maskatchi Posted July 1, 2011 Share Posted July 1, 2011 Ok i get this error stack overflow when i try to use my speed script: function setElementSpeed(element, unit, speed) -- only work if element is moving! if (unit == nil) then unit = 0 end if (speed == nil) then speed = 0 end speed = tonumber(speed) local acSpeed = setElementSpeed(element, unit) if (acSpeed~=false) then -- if true - element is valid, no need to check again local diff = speed/acSpeed local x,y,z = setElementVelocity(element) setElementVelocity(element,x*diff,y*diff,z*diff) return true end return false end addCommandHandler("sspeed", function (player, cmd, arg1) local veh = getPedOccupiedVehicle(player) if (veh) then setElementSpeed(veh, "kph", tonumber(arg1)) else outputChatBox("You have to sit in vehicle", player) end end ) any suggestions? Link to comment
Klesh Posted July 2, 2011 Share Posted July 2, 2011 You must use [ code=text ] here your script code [ /code ] to post your codes and we can see in what you need help or where is the error. Use [ code=lua ] here your script code[ /code ] to post the format text, you must read the announcements for scripters! Use it with Edit Post, select code. Link to comment
Jockie Posted July 2, 2011 Share Posted July 2, 2011 @ Line 5: You call the same function in the function, so it gets over-flowed ofcourse. Tip: You're missing some ''end''s. function setElementSpeed(element, unit, speed) if (unit == nil) then unit = 0 end if (speed == nil) then speed = 0 end speed = tonumber(speed) local acSpeed = setElementSpeed(element, unit) -- Change this if (acSpeed~=false) then local diff = speed/acSpeed local x,y,z = setElementVelocity(element) setElementVelocity(element,x*diff,y*diff,z*diff) return true end end return false end -- Missed ''end'' over here end -- And one here addCommandHandler("sspeed", function (player, cmd, arg1) local veh = getPedOccupiedVehicle(player) if (veh) then setElementSpeed(veh, "kph", tonumber(arg1)) else outputChatBox("You have to sit in vehicle", player) end end ) Link to comment
Klesh Posted July 3, 2011 Share Posted July 3, 2011 Try the edited code: function setElementSpeed(element, unit, speed) if (unit == nil) then unit = 0 or if (speed == nil) then speed = 0 then speed = tonumber(speed) local acSpeed = setElementSpeed(element, unit) if (acSpeed~=false) then local diff = speed/acSpeed local x,y,z = setElementVelocity(element) setElementVelocity(element,x*diff,y*diff,z*diff) end end end end addCommandHandler("sspeed",getRootElement,(ThisResource()), Link to comment
karlis Posted July 3, 2011 Share Posted July 3, 2011 Try the edited code: function setElementSpeed(element, unit, speed) if (unit == nil) then unit = 0 or if (speed == nil) then speed = 0 then speed = tonumber(speed) local acSpeed = setElementSpeed(element, unit) if (acSpeed~=false) then local diff = speed/acSpeed local x,y,z = setElementVelocity(element) setElementVelocity(element,x*diff,y*diff,z*diff) end end end end addCommandHandler("sspeed",getRootElement,(ThisResource()), wtf is even this? i guess your another post count whore -- @jockie-he didn't miss them, watch more careful. -- try: function setElementSpeed(element, unit, speed) local unit=(unit == "kph") and 161 or 100 if (speed == nil) then speed = 0 else speed = tonumber(speed) end local x,y,z = getElementVelocity(element) local diff = speed/((x^2+y^2+z^2)^0.5*unit) setElementVelocity(element,x*diff,y*diff,z*diff) end addCommandHandler("sspeed", function (player,_, arg1) local veh = getPedOccupiedVehicle(player) if (veh) then setElementSpeed(veh, "kph",arg1) else outputChatBox("You have to sit in vehicle", player,255,0,0) end end ) Link to comment
Klesh Posted July 3, 2011 Share Posted July 3, 2011 I try to help no to up my count posts. Link to comment
karlis Posted July 3, 2011 Share Posted July 3, 2011 you basically wrote the same as above, only except destroying only part that was working. 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