Daniels69 Posted August 24, 2016 Share Posted August 24, 2016 i'm trying to make an script: when player scrolls down the mouse, the spoilers change. and it doesn't work , i don't really know where is the problem , and what did i do wrong. client: function checkifkeyup() if getKeyState( "lctrl" ) == true then triggerServerEvent("changespoiler",localPlayer,localPlayer) end end bindKey( "mouse_wheel_up", "down", checkifkeyup ) server: local spoilers = { 1000, 1001, 1002, 1003, 1014, 1015, 1016, } addEvent("changespoiler",true) function spoilerdown(thePlayer) local theVehicle = getPedOccupiedVehicle ( source ) if theVehicle == true then local theVehicle = getPedOccupiedVehicle ( source ) addVehicleUpgrade ( theVehicle, spoilers+1 ) else addVehicleUpgrade ( theVehicle, math.random(#spoilers)) end end addEventHandler("changespoiler",getRootElement(),spoilerdown) Thank you Link to comment
Captain Cody Posted August 24, 2016 Share Posted August 24, 2016 Not tested and not sure if it'll work at all spoilers = { 1000, 1001, 1002, 1003, 1014, 1015, 1016, } Current = 1 addEvent("changespoiler",true) function spoilerdown(thePlayer) local theVehicle = getPedOccupiedVehicle ( source ) if Current < #spoilers then Current = Current+1 else Current = 1 end if theVehicle true then addVehicleUpgrade ( theVehicle, spoilers(Current) ) end end addEventHandler("changespoiler",getRootElement(),spoilerdown) Link to comment
Daniels69 Posted August 24, 2016 Author Share Posted August 24, 2016 Not tested and not sure if it'll work at all spoilers = { 1000, 1001, 1002, 1003, 1014, 1015, 1016, } Current = 1 addEvent("changespoiler",true) function spoilerdown(thePlayer) local theVehicle = getPedOccupiedVehicle ( source ) if Current < #spoilers then Current = Current+1 else Current = 1 end if theVehicle true then addVehicleUpgrade ( theVehicle, spoilers(Current) ) end end addEventHandler("changespoiler",getRootElement(),spoilerdown) doesn't work. and there's no errors o.0 Link to comment
StefanAlmighty Posted August 24, 2016 Share Posted August 24, 2016 The issue with your original code is here: addVehicleUpgrade ( theVehicle, spoilers+1 ) spoilers is defined as a table in your code and in this line you're trying to +1 to the table which isn't possible. To choose a random spoiler from the list: spoilers[math.random(1, #spoilers)] To cycle through each one, start by defining the current spoiler it's on as seen in the script provided above. Each time you trigger changespoiler you want to add 1 to the current spoiler variable but if it hits #spoilers+1 then reset it to 1. That way each time you trigger changespoiler it will cycle through the list of parts in your spoilers table. 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