Lordkrypton Posted August 17, 2015 Share Posted August 17, 2015 Hi, I wanted to create a delays between 2 repair in freeroam mode. Like you press one time repair, and you have to wait 30 sec before repair a other time ? Can you help me to create the script, i don't have idea Thank you Link to comment
AfuSensi Posted August 17, 2015 Share Posted August 17, 2015 You can do it with getTickCount() Example: local repairDelay = 30000 -- 30 seconds delay (in ms) local delayTick = false function repairFunction() -- Check when the last repair was if getTickCount() - delayTick < repairDelay then return end -- If it's less then repairDelay ms ago then abort -- repair code --set tick when repair happened delayTick = getTickCount() end Not tested, but you get the point. 2 Link to comment
Lordkrypton Posted August 18, 2015 Author Share Posted August 18, 2015 Kariiim, it's for this function, in freeroam gameplay : --------------------------- -- Repair vehicle --------------------------- function repairVehicle() local vehicle = getPedOccupiedVehicle(g_Me) if vehicle then server.fixVehicle(vehicle) end end addCommandHandler('repair', repairVehicle) addCommandHandler('rp', repairVehicle) AfuSensi, thank you, i still try to add it, but i have bug. Link to comment
AfuSensi Posted August 19, 2015 Share Posted August 19, 2015 Kariiim, it's for this function, in freeroam gameplay :--------------------------- -- Repair vehicle --------------------------- function repairVehicle() local vehicle = getPedOccupiedVehicle(g_Me) if vehicle then server.fixVehicle(vehicle) end end addCommandHandler('repair', repairVehicle) addCommandHandler('rp', repairVehicle) AfuSensi, thank you, i still try to add it, but i have bug. (not tested) I used timers this time, but same can be applied with getTickCount() --------------------------- -- Repair vehicle --------------------------- local repairDelayTime = 30000 -- delay time in ms local repairTimer = false function repairVehicle() if isTimer(repairTimer) then local timeleft = math.ceil( getTimerDetails(repairTimer)/1000 ) -- Get seconds left from timer if timeleft then local secondString = " second" if timeleft > 1 then secondString = " seconds" end outputChatBox("Repair failed! Repair is possible again in "..tostring(timeleft)..secondString) return false end end local vehicle = getPedOccupiedVehicle(g_Me) if vehicle then server.fixVehicle(vehicle) repairDelayTime = setTimer(function() repairTimer = false end,repairDelayTime,1) end end addCommandHandler('repair', repairVehicle) addCommandHandler('rp', repairVehicle) 1 Link to comment
Lordkrypton Posted August 19, 2015 Author Share Posted August 19, 2015 bad argument @ Set timer, expect number get bolean, i try something from https://wiki.multitheftauto.com/wiki/SetTimer but still bugged x) Thank you a lot for your help Link to comment
Moderators IIYAMA Posted August 19, 2015 Moderators Share Posted August 19, 2015 repairTimer = setTimer(function() repairTimer = false end,repairDelayTime,1) Although tickcount would be more suitable for this code. Link to comment
Lordkrypton Posted August 19, 2015 Author Share Posted August 19, 2015 Thank you guys !!! 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