Bean666 Posted June 12, 2016 Posted June 12, 2016 hi, im asking a question what if i make a function with setElementData in a resource. then if i make another resource will getElementData work with the data i set in the other resource? will it get the data from the other resource?
Castillo Posted June 12, 2016 Posted June 12, 2016 Yes. Element data is shared between all resources.
Bean666 Posted June 12, 2016 Author Posted June 12, 2016 uhm just a question will this set the player's ElementData to "tough" when he clicks the button "button"? function toughperk( ) if (source == localPlayer) then setElementData(localPlayer,"tough", true) end end addEventHandler ( "onClientGUIClick", button, toughperk )
Castillo Posted June 12, 2016 Posted June 12, 2016 Yes. By the way, 'source' of onClientGUIClick is the button, not the localPlayer, remove that 'if' check.
Bean666 Posted June 12, 2016 Author Posted June 12, 2016 (edited) like this? function toughperk( ) setElementData(localPlayer,"tough", true) end addEventHandler ( "onClientGUIClick", button, toughperk ) Edited June 12, 2016 by Guest
Bean666 Posted June 12, 2016 Author Posted June 12, 2016 ok thanks i just had to remove 1 end and it's already working , thanks. anyways will this work if i get the player's data? if (getElementType(player) == "player") and getElementData(player, "toughperk") == true then
Castillo Posted June 12, 2016 Posted June 12, 2016 You have a missing parentheses after 'true' and before 'then'.
Bean666 Posted June 12, 2016 Author Posted June 12, 2016 ok i got it working but , how can i save a player's Element Data when he quits the game? and when he joins game it sets the saved Element Data?
Bean666 Posted June 12, 2016 Author Posted June 12, 2016 nvm it works fine when i used: function quitPlayer () local account = getPlayerAccount (source) local data = getElementData(source, "toughperk") if data == true then setAccountData (account, "toughperk", true ) end end addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) addEventHandler ( 'onPlayerLogin', getRootElement ( ), function ( _, theCurrentAccount) local ifaccountperk = getAccountData(theCurrentAccount, "toughperk") if ifaccountperk == true then setElementData(source,"toughperk", true) setAccountData (account, "toughperk", false ) else setElementData(source,"toughperk", false) end end )
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