It is currently March 29th, 2024, 1:28 am

Can someone Help me merge those scripts in one script?

Discuss the use of Lua in Script measures.
skullleeep
Posts: 1
Joined: June 25th, 2019, 6:54 pm

Can someone Help me merge those scripts in one script?

Post by skullleeep »

Can someone Help me merge those scripts in one script?
First Script:

Code: Select all

iconid=0
iconuseimg=0
iconuseid={}
playerdistance={}
boatpicked={}
boatnum={}
obstaclesize={}
debugdisplay=0

currentboat=0
minterrainheight=450
obstaclecount=0

boatcount=0

function boat_init(e)
boatused={}
e_rel={}
boatused[e]=0
e_rel[e]=0
speed=0
-- boat acceleration and brake
power=0.025
brake=0.05
-- boat max and min speed
maxspeed=4
minspeed=-2
-- water drag - increase for greater drag
drag=0.0005

-- useicon height, controls where use icon is positioned on y axis
iconheight=80
-- adjust front and side range if you find your boat clipping on the terrain
frontrange=150
siderange=70
-- adjust offset to reposition player when driving the boat
offset=60
boatrideheight=40

-- adjust boat_rot_tweak to suit your boats orientation (if you find your boat going sidewards for instance)
boat_rot_tweak=90
-- adjust accordingly for your boats dimensions
leaveboatrange=250
enterboatrange=180

-- adjust this to suit your boats size
otherboatsize=200

-- adjust waterheight to get your custom boat to sit in the water correctly. 
--waterheight=470 -- Store boat default from first video example (OldPman's boat)
waterheight=500

waterlevel=500

boatx=g_Entity[e]['x']
boaty=g_Entity[e]['y']
boatz=g_Entity[e]['z']

turn=0

playerposx=0
playerposy=0
end

function boat_main(e)
if iconuseid[e]==nil then
 iconuseid[e]=0
end
if e_rel[e]==nil then
 e_rel[e]=0
end
if boatused[e]==nil then
 boatused[e]=0
end
if boatcount==nil then
 boatcount=0
end
if boatpicked[e]==nill then
 boatcount=boatcount+1
 boatpicked[e]=boatcount
 boatnum[boatcount]=e
end

 boatangle=g_Entity[e]['angley']

 PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
 PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
 PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDZ*PlayerDZ));
 playerdistance[e]=PlayerDist

 if iconuseimg>0 then
  iconuseid[e]=iconuseimg
 end
 if playerdistance[e] > enterboatrange and currentboat == e then
  Hide(iconuseid[e])
 end

 if playerdistance[e] < enterboatrange and g_PlayerHealth > 0 and g_PlayerThirdPerson==0 and boatused[e]==0 then

   Show(iconuseid[e])
   currentboat=e
   
   CollisionOff(iconuseid[e])
   SetPosition(iconuseid[e],g_Entity[e]['x'],g_Entity[e]['y']+iconheight,g_Entity[e]['z'])
   SetRotation(iconuseid[e],0,g_PlayerAngY,0)
   CollisionOn(iconuseid[e])

  if g_KeyPressE==1 and e_rel[e]==0 and boatused[e]==0 then
   boatused[e]=1
   CollisionOff(e)
   Hide(iconuseid[e])
   e_rel[e]=1
  end
  if g_KeyPressE==0 and e_rel[e]==1 then
   e_rel[e]=0
  end
 end

 if boatused[e]==0 then
  if g_Entity[e]['y']>waterheight or g_Entity[e]['y']<(waterheight-1) then
   --Text(10,10,6,g_Entity[e]['y'])
   CollisionOff(e)
   SetPosition(e,g_Entity[e]['x'],waterheight,g_Entity[e]['z'])
   CollisionOn(e)
  end
 end
 if boatused[e]==1 then
  Hide(iconuseid[e])
  boatx=g_Entity[e]['x']
  boaty=g_Entity[e]['y']
  boatz=g_Entity[e]['z']

  SetFreezePosition(freezex,g_Entity[e]['y']+40,freezez)

-- boat speed control
  if g_KeyPressW == 1 then
   if speed<maxspeed then
    speed=speed+power
   end
  end
  if g_KeyPressS == 1 then
   if speed>minspeed then
    speed=speed-brake
   end
  end
-- boat steering
  if g_KeyPressA == 1 then
   boatangle=boatangle-.2 --(0.01*speed)-0.4
   turn=1
  end

  if g_KeyPressD == 1 then
   boatangle=boatangle+.2 --(0.01*speed)+0.4
   turn=1
  end

  if turn==1 then
   turn=0
   if g_PlayerAngX>0 and g_PlayerAngX<100 then
    SetFreezeAngle(g_PlayerAngX,boatangle+boat_rot_tweak,g_PlayerAngZ)
    TransportToFreezePosition()
   end
  end
--leave boat
  if g_KeyPressE==1 and e_rel[e]==0 and playerposy>minterrainheight then
   boatused[e]=0
   freezex=playerposx
   freezez=playerposz
   freezey=playerposy
   SetPosition(iconid,0,0,0)
   Hide(iconid)
   SetFreezePosition(freezex,freezey+5,freezez)
   TransportToFreezePositionOnly()
   e_rel[e]=1
   CollisionOn(e)
  end
  if g_KeyPressE==0 and e_rel[e]==1 then
   e_rel[e]=0
  end

-- Front Collision
  height = GetTerrainHeight(boatcollx,boatcollz)
  if height>waterlevel then
   speed=-1
  end

-- Rear Collision
  height = GetTerrainHeight(boatrearcollx,boatrearcollz)
  if height>waterlevel then
   speed=1
  end

-- Left Collision
  height = GetTerrainHeight(boatleftcollx,boatleftcollz)
  if height>waterlevel then
   boatx=boatx+(math.sin(boatangleleftdeg)*-2)
   boatz=boatz+(math.cos(boatangleleftdeg)*-2)
  end

-- Right Collision
  height = GetTerrainHeight(boatrightcollx,boatrightcollz)
  if height>waterlevel then
   boatx=boatx+(math.sin(boatangleleftdeg)*2)
   boatz=boatz+(math.cos(boatangleleftdeg)*2)
  end

-- Rad Conversion
  boatangledeg=math.rad(boatangle+boat_rot_tweak)
  boatangleleftdeg=math.rad(boatangle)
  boatanglerightdeg=math.rad(boatangle)


-- Setup boat collsion points
  boatx=boatx+(math.sin(boatangledeg)*speed)
  boaty=g_Entity[e]['y']
  boatz=boatz+(math.cos(boatangledeg)*speed)

  boatcollx=boatx+(math.sin(boatangledeg)*frontrange+speed)
  boatcollz=boatz+(math.cos(boatangledeg)*frontrange+speed)

  boatrearcollx=boatx+(math.sin(boatangledeg)*(frontrange+speed)*-1)
  boatrearcollz=boatz+(math.cos(boatangledeg)*(frontrange+speed)*-1)


  boatleftcollx=boatx+(math.sin(boatangleleftdeg)*siderange)
  boatleftcollz=boatz+(math.cos(boatangleleftdeg)*siderange)

  boatrightcollx=boatx+(math.sin(boatanglerightdeg)*(siderange)*-1)
  boatrightcollz=boatz+(math.cos(boatanglerightdeg)*(siderange)*-1)

-- boat collision with other boats

for n=1,boatcount do

 if boatnum[n]~=e then

  otherboatx = g_Entity[boatnum[n]]['x'] - boatx;
  otherboatz = g_Entity[boatnum[n]]['z'] - boatz;

  otherboatdist = math.sqrt(math.abs(otherboatx*otherboatx)+math.abs(otherboatz*otherboatz));

  if otherboatdist<otherboatsize then
     speed=speed*-2
  end
 end
end

-- obstacle collision with boat

if obstaclecount>0 then
 for s=1,obstaclecount do
 if obstaclenum[s]~=e then

  obstaclex = g_Entity[obstaclenum[s]]['x'] - boatx;
  obstaclez = g_Entity[obstaclenum[s]]['z'] - boatz;

  obstacledist = math.sqrt(math.abs(obstaclex*obstaclex)+math.abs(obstaclez*obstaclez));
  if obstacledist<obstaclesize[s] then
     speed=speed*-2
  end

 end
 end
end

-- update freeze location
  if boatused[e]==1 then
  freezex=g_Entity[e]['x']+(math.sin(boatangledeg)*(offset-speed)*-1)
  freezez=g_Entity[e]['z']+(math.cos(boatangledeg)*(offset-speed)*-1)
  SetFreezePosition(freezex,g_Entity[e]['y']+boatrideheight,freezez)
  end

  SetPosition(e,boatx,boaty,boatz)
  SetRotation(e,g_Entity[e]['anglex'],boatangle,g_Entity[e]['anglez'])

-- update player position to leave boat
  playerposx=g_PlayerPosX+(math.sin(math.rad(g_PlayerAngY))*leaveboatrange)
  playerposz=g_PlayerPosZ+(math.cos(math.rad(g_PlayerAngY))*leaveboatrange)
  playerposy=GetTerrainHeight(playerposx,playerposz)
  if boatused[e]==1 then
   if playerposy>minterrainheight then
   Show(iconid)
   CollisionOff(iconid)
   SetPosition(iconid,playerposx,playerposy+boatrideheight,playerposz)
   SetRotation(iconid,0,g_PlayerAngY,0)
   CollisionOn(iconid)
   else
   Hide(iconid)
   end
  end

  TransportToFreezePositionOnly()
  if speed>0 and g_KeyPressW == 0 then
   speed=speed-drag
  end
  if speed<0 and g_KeyPressS == 0 then
   --speed=0
   speed=speed/1.1
  end
 end
end
2nd script:

Code: Select all

function pickup_init(e)
 Include ("carry.lua")
end

function pickup_main(e)

 PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
 PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
 PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
 PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));

 if g_KeyPressE == 0 then
  itemreleased=1
 end

 if PlayerDist < 75 then
  Prompt("Press E to pick this up.")
  if g_KeyPressE == 1 then
   if itemreleased==1 then
    PlaySound(e,0);
    itemreleased=0
    SwitchScript ( e,"carry" )
   end
  end
 end
end
Please help me!
Last edited by balala on June 25th, 2019, 7:02 pm, edited 1 time in total.
Reason: Please use [code] tags whenever are you posting code snippets. It's the </> button.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Can someone Help me merge those scripts in one script?

Post by jsmorley »

This does not look like it has anything to do with Rainmeter, and in any case the Include function is not allowed in Lua with Rainmeter.

This looks like a question better suited to a more general Lua-related forum.