Newbie Posted May 3, 2014 Share Posted May 3, 2014 function someoneReachedHunter(number, sort, model) for index, account in ipairs ( getAccounts ( ) ) do if getAccountPlayer ( account ) then local alreadyGotHunter = getElementData(source, "gotHunter") if sort == "vehiclechange" and model == 425 and not alreadyGotHunter then outputChatBox ( "#000000* #ffffff " ..getPlayerName(source).." Got hunter! $#11dd111000", getRootElement(), 255, 255, 255, true ) setAccountData( account,"Hunters",tostring( getAccountData( account,"Hunters" ) or 0 )+1 ) setAccountData( account,"Cash",tostring( getAccountData( account,"Cash" ) or 0 )+1000 ) setAccountData( account,"EXP",tostring( getAccountData( account,"EXP" ) or 0 )+5 ) setElementData(source, "gotHunter", true) end end end end addEvent("onPlayerPickUpRacePickup",true) addEventHandler("onPlayerPickUpRacePickup", root, someoneReachedHunter) addEvent("onMapStarting", true) function resetHunterStatus() for k, player in ipairs(getElementsByType("player")) do setElementData(player, "gotHunter", false) end end addEventHandler("onMapStarting", root, resetHunterStatus) Its script that when player takes hunter it sets his Hunters data +1, and if he takes hunter again in same map, data wont be +1. But when server plays 2 or more players, it bugs.. When other player gots hunter the data wont change. Link to comment
Castillo Posted May 3, 2014 Share Posted May 3, 2014 I don't understand the problem. Also, you should use a table to store if the player took the hunter or not, using element data is just a waste. Link to comment
cheez3d Posted May 3, 2014 Share Posted May 3, 2014 local hunters = {}; addEvent("onPlayerPickUpRacePickup",true); addEventHandler("onPlayerPickUpRacePickup",root,function(id,_type,model) if _type == "vehiclechange" and model == 425 then if hunters[source] then return; end; local account = getPlayerAccount(source); local data = { ["Hunters"] = { current = getAccountData(account,"Hunters"), add = 1; }, ["Cash"] = { current = getAccountData(account,"Cash"), add = 1000; }, ["EXP"] = { current = getAccountData(account,"EXP"), add = 5; }; }; for k,v in pairs(data) do setAccountData(account,k,(v.current and v.current or 0)+v.add); end; hunters[source] = true; end; end); addEvent("onMapStarting",true); addEventHandler("onMapStarting",root,function() for k in pairs(hunters) do k = nil; end; end); Optimised your code. 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