xtc_velns Posted March 2, 2023 Share Posted March 2, 2023 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
Vampire Posted March 2, 2023 Share Posted March 2, 2023 Hello @xtc_velns and welcome! I've moved your topic to the Scripting section so you can get better assistance. Link to comment
Addlibs Posted March 2, 2023 Share Posted March 2, 2023 (edited) 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 March 2, 2023 by Addlibs Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now