Jump to content

Boat sinking script problem


Miika

Recommended Posts

Posted

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 

Real motorbike backflip / frontflip script: https://forum.mtasa.com/viewtopic.php?f=108&t=98191

Posted

Is it a client side script? if so, then the first parameter of addCommandHandler is the command name, use 'localPlayer'.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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 

Real motorbike backflip / frontflip script: https://forum.mtasa.com/viewtopic.php?f=108&t=98191

Posted

Doing that, you are just defining a global variable, meaning this script will only work with a single player.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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...