kevin433 Posted February 16, 2010 Posted February 16, 2010 Hi, I recently began to script in LUA, and I have experience with PAWN. The problem is now that i want an "integer" which every player has his own off. I just know how to do this in SA:MP, but not in MTA. I mean something like this (I hope some guys understand what i want to do), I just can show how i would write it in SA:MP: new lightson[MAX_PLAYERS]; if(lightson[playerid] == 1) { ...... etc } How should i write this in LUA? I've checked the wiki, but I couldn't find it there.
eAi Posted February 16, 2010 Posted February 16, 2010 If you want to associate information with players, the official way to do that is setElementData and getElementData.
kevin433 Posted February 16, 2010 Author Posted February 16, 2010 What is meaned with "string key"? I just saw the example on the Wiki page and there the key was "tempdata.originalnick". I just need to save an integer
Dark Dragon Posted February 16, 2010 Posted February 16, 2010 the key is simply something to find the information later. for example you use setElementData(somePlayer,"phoneNumber",666999333) and later you use getElementData(somePlayer,"phoneNumber") to get the information you have previously set, in this case 666999333 if this way seems uncomfortable to you you can also use a table local playerPhoneNumberTable = {} playerPhoneNumberTable[somePlayerElement] = 666999333 playerPhoneNumberTable[someOtherPlayerElement] = 123123123
kevin433 Posted February 16, 2010 Author Posted February 16, 2010 Should this work? setElementData(source,"lightson", 1) Don't I have to make a local or global "lightson"? Or should it just be like that? And can I do things like this? if(getElementData(source, "lightson") == 1) then outputChatBox("Your lights are on!", source) end
Aibo Posted February 17, 2010 Posted February 17, 2010 yep, that should work, you dont need a global, you're just adding a key and a value to it.
Dark Dragon Posted February 17, 2010 Posted February 17, 2010 Should this work? setElementData(source,"lightson", 1) Don't I have to make a local or global "lightson"? Or should it just be like that? And can I do things like this? if(getElementData(source, "lightson") == 1) then outputChatBox("Your lights are on!", source) end yes that would work. and in this case you could even save some memory by using true and false instead of an integer setElementData(source,"lightson", true) if(getElementData(source, "lightson") == true) then outputChatBox("Your lights are on!", source) end
eAi Posted February 17, 2010 Posted February 17, 2010 That wouldn't save any memory, but it's a good idea anyway.
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