Jump to content

Boat sinking script problem


Miika

Recommended Posts

I start coding the boat sinking script.

First i want add rotation. But I have problem.

WANRNING: restart/restart.lua:9: Bad argument @ 'getPedOccupiedVehicle' [Expected ped at argument, 1 got nil] 

Code:

function commandX(thePlayer) 
  vehicle = getPedOccupiedVehicle ( thePlayer ) 
  if (getVehicleType(vehicle) == "Boat") then 
    setTimer (timerA, 1000, 1) 
  else 
    outputChatBox("You don't have a boat!", thePlayer, 255, 255, 0, true) 
end 
end 
addCommandHandler("sink", commandX) 
  
function timerA() 
    theVehicle = getPedOccupiedVehicle ( source ) 
    if theVehicle then 
    local rotX, rotY, rotZ = getElementRotation( theVehicle ) 
    local posX, posY, posZ = getElementPosition( theVehicle ) 
    setElementRotation(theVehicle, 0, 0, rotZ+0.01) 
    setTimer (timerB, 1, 1) 
    else 
    return end 
end 
  
function timerB( thePlayer ) 
    theBoat = getPedOccupiedVehicle ( source ) 
    if theVehicle then 
    local rotX, rotY, rotZ = getElementRotation( theBoat ) 
    local posX, posY, posZ = getElementPosition( theBoat ) 
    setElementRotation(theBoat, 0, 0, rotZ+0.01) 
    setTimer (timerA, 1, 1) 
    else 
    return end 
end 

Link to comment
Ah wait, I thought it was the first getPedOccupiedVehicle, but it was the one inside function "timerA".

The problem is that 'source' is nothing, you need to pass the player/vehicle element in the timer arguments.

The timer works, but the boat begins to vibrate, but does not turn

function commandX(thePlayer) 
  vehicle = getPedOccupiedVehicle ( thePlayer ) 
  rotX, rotY, rotZ = getElementRotation(vehicle) 
  if (getVehicleType(vehicle) == "Boat") then 
    setTimer (timerA, 1000, 1) 
  else 
    outputChatBox("You don't have a boat!", thePlayer, 255, 255, 0, true) 
end 
end 
addCommandHandler("sink", commandX) 
  
function timerA( thePlayer ) 
    setElementRotation(vehicle, 0, 0, rotZ+0.1) 
    setTimer (timerB, 50, 1) 
end 
  
function timerB( thePlayer ) 
    setElementRotation(vehicle, 0, 0, rotZ+0.1) 
    setTimer (timerA, 50, 1) 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...