Jump to content

Problem with burnout script


Recommended Posts

So this script doesnt work. It is Client-side and it has worked on my previous roleplay servers but now it does nothing

local burnoutTimer = {}
local player = localPlayer
function popTheTires(player)
setVehicleWheelStates(getPedOccupiedVehicle(player),-1, 1,-1, 1)
end
 
function burnoutTheTires(player,key)
if (key == "accelerate" and getPedControlState (player,"brake_reverse") == true) or (key == "brake_reverse" and getPedControlState (player,"accelerate") == true) then
     burnoutTimer[player] = setTimer(popTheTires,2000,1,player)
end
end
 
function unpressedTheKeys(player)
if (isTimer(burnoutTimer[player])) then
killTimer(burnoutTimer[player])
end
end
for i,v in ipairs(getElementsByType("player")) do
--bindKey("accelerate","down",burnoutTheTires)
--bindKey("brake_reverse","down",burnoutTheTires)
 
bindKey("accelerate","up",unpressedTheKeys)
bindKey("brake_reverse","up",unpressedTheKeys)
end
 
function joinBinds()
bindKey("accelerate","down",burnoutTheTires)
bindKey("brake_reverse","down",burnoutTheTires)
 
bindKey("accelerate","up",unpressedTheKeys)
bindKey("brake_reverse","up",unpressedTheKeys)
end
addEventHandler("onClientResourceStart",getRootElement(getThisResource()),joinBinds)

i have tried everything in my knowledge but nothing seems to work. Can somebody help?

Link to comment

The callback function for bindKey callback function does not receive a player element. The client-side bindKey's player can only ever be the localPlayer, so you need to change this function signature:

function burnoutTheTires(player,key)

-- into this
function burnoutTheTires(key)

and likewise for unpressedTheKeys,

function unpressedTheKeys(player)

-- into this
function unpressedTheKeys()

You could have discovered this yourself with a very simply debug methodology: debug outputs. See outputDebugString and iprint, (and less frequently used for this purpose but still usable: outputChatBox, outputConsole).

And get rid of the burnoutTimer table, it is unnecessary, since it only ever stores one value, always under the key equivalent to the localPlayer element. Simply declare a local value (tip: local values, aka upvalues are faster in write and read speed over globals which are actually entries in the _G table and table lookups aren't as fast as upvalues)

local burnoutTimer

--- ... elsewhere in the code
burnoutTimer = setTimer(...)

-- ... in another place
if isTimer(burnoutTimer) then
	killTimer(burnoutTimer)
end

-- etc.

You may choose to search-and-replace all occurrences of "player" with "localPlayer" since that's pre-defined, but it's fine to leave as since it's just a local value pointing to the localPlayer element.

The following part seems to be remnant of a time when this script was supposed to be serverside?

for i,v in ipairs(getElementsByType("player")) do
--bindKey("accelerate","down",burnoutTheTires)
--bindKey("brake_reverse","down",burnoutTheTires)
 
bindKey("accelerate","up",unpressedTheKeys)
bindKey("brake_reverse","up",unpressedTheKeys)
end

Anyway, completely unnecessary -- onClientResourceStart is triggered for a running client (at the time of resource start on the server) as well as a joining client (aka resource start on the client at time of join), so this results in duplicated bind calls.

Edited by Addlibs
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...