-.Paradox.- Posted June 3, 2014 Share Posted June 3, 2014 Hello guys, Is there anyway to check the player who's driving a vehicle idle time and set his ElementData +10 every 5 minute. Like example i'm driving a vehicle, and it will set my "Driving" Element Data +100 every 5 minutes. Thanks Link to comment
Den. Posted June 3, 2014 Share Posted June 3, 2014 It is untested, not sure if this is what you wanted but: If a player keeps driving a vehicle for a while, it will increment his "driving" element data. If he exits, the element data is set back to nil. local time = 5 * 60000 --The time between each check. local increment = 100 --How much the element data "driving" should be increased function countDrivingTime() local thePlayers = getElementsByType("player") --Get all players for key, thePlayer in ipairs(thePlayers) do if isPedInVehicle(thePlayer) then -- If thePlayer is in a vehicle local driving = getElementData(thePlayer, "driving") driving = driving and driving + increment or 0 --If driving is a value, then increment it. setElementData(thePlayer, "driving", driving) --Set the data. end end end setTimer(countDrivingTime, time, 0) --Timer to check the players. --Reset driving counter when player exits, remove it if you don't want it. addEventHandler("onPlayerVehicleExit", root, function() if getElementData(source, "driving") then setElementData(source, "driving", nil) end end) However, if you want to measure the IDLE TIME ( that is when the player is in a vehicle, but doesn't move with it at all ); You're going to have to save the old position, and then see if it equals the current position in this check. Link to comment
-.Paradox.- Posted June 3, 2014 Author Share Posted June 3, 2014 But i think this will add 100 even if i wasn't driving, *camping* with my vehicle. Link to comment
.:HyPeX:. Posted June 3, 2014 Share Posted June 3, 2014 Just use the idle MTA function. https://wiki.multitheftauto.com/wiki/GetPlayerIdleTime Link to comment
-.Paradox.- Posted June 3, 2014 Author Share Posted June 3, 2014 Dude....this is to check if the player is not moving... Link to comment
.:HyPeX:. Posted June 3, 2014 Share Posted June 3, 2014 Dude....this is to check if the player is not moving... Yes, if he's still then he's just camping. If you want to make it more exact, just store down the value to a variable for the player and check it after the time you want, and if the distance is okay (getDistanceBetweenPoints2D) then go foward. (But i dont really recommend this) Link to comment
Den. Posted June 3, 2014 Share Posted June 3, 2014 Okay, I changed it to check distance from old position to current position. local time = 5 * 60000 --The time between each check. local increment = 100 --How much the element data "driving" should be increased function countDrivingTime() local thePlayers = getElementsByType("player") --Get all players for key, thePlayer in ipairs(thePlayers) do if isPedInVehicle(thePlayer) then -- If thePlayer is in a vehicle local pos = getElementData(thePlayer, "oldpos") or {0, 0, 0} local oldx, oldy, oldz = unpack(pos) local x, y, z = getElementPosition(thePlayer) if getDistanceBetweenPoints3D(x, y, z, oldx, oldy, oldz) > 5 then --If he moved a distance of 5 away from old position local driving = getElementData(thePlayer, "driving") driving = driving and driving + increment or 0 setElementData(thePlayer, "driving", driving) end setElementData(thePlayer, "oldpos", {x, y, z}) end end end setTimer(countDrivingTime, time, 0) --Timer to check the players. --Reset driving counter when player exits, remove it if you don't want it. addEventHandler("onPlayerVehicleExit", root, function() setElementData(source, "driving", nil) setElementData(source, "oldpos", nil) end) However, if the timer is as long as 5 minutes, then if a player went from point x to point y, then returned to point x in 5 mins; His driving data isn't going to be incremented because the distance from the old position (point x) to the current position ( point x as well) is 0. Link to comment
.:HyPeX:. Posted June 3, 2014 Share Posted June 3, 2014 Make it easier, just save a % of that to the data every that % of time (Eg: 20% every min) Link to comment
-.Paradox.- Posted June 4, 2014 Author Share Posted June 4, 2014 Okay, I changed it to check distance from old position to current position. local time = 5 * 60000 --The time between each check. local increment = 100 --How much the element data "driving" should be increased function countDrivingTime() local thePlayers = getElementsByType("player") --Get all players for key, thePlayer in ipairs(thePlayers) do if isPedInVehicle(thePlayer) then -- If thePlayer is in a vehicle local pos = getElementData(thePlayer, "oldpos") or {0, 0, 0} local oldx, oldy, oldz = unpack(pos) local x, y, z = getElementPosition(thePlayer) if getDistanceBetweenPoints3D(x, y, z, oldx, oldy, oldz) > 5 then --If he moved a distance of 5 away from old position local driving = getElementData(thePlayer, "driving") driving = driving and driving + increment or 0 setElementData(thePlayer, "driving", driving) end setElementData(thePlayer, "oldpos", {x, y, z}) end end end setTimer(countDrivingTime, time, 0) --Timer to check the players. --Reset driving counter when player exits, remove it if you don't want it. addEventHandler("onPlayerVehicleExit", root, function() setElementData(source, "driving", nil) setElementData(source, "oldpos", nil) end) However, if the timer is as long as 5 minutes, then if a player went from point x to point y, then returned to point x in 5 mins; His driving data isn't going to be incremented because the distance from the old position (point x) to the current position ( point x as well) is 0. I guess it will add 100 in Driving ElementData only once not every 5 minutes, I didn't tested but it seems that there is something wrong with the timer... And thanks for your work i really appreciate it. Link to comment
Den. Posted June 4, 2014 Share Posted June 4, 2014 No, it should add 100 to driving every 5 minutes, can't see what's wrong with the timer. Looks fine. setTimer -And anytime . Link to comment
-.Paradox.- Posted June 4, 2014 Author Share Posted June 4, 2014 I will try it in server side thanks anyway Link to comment
denny199 Posted June 4, 2014 Share Posted June 4, 2014 You should make the checks client side for the local player only, so that you don't need to loop trough every player on the server-side... Because element data is synced with everything on the server... You can also check if the player is driving with getControlState ( https://wiki.multitheftauto.com/wiki/GetControlState ) So you should recode the code a little bit optimized for client side, just recommed ;p Link to comment
-.Paradox.- Posted June 5, 2014 Author Share Posted June 5, 2014 Nice idea! Thank you 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