Jump to content

"integers" for every player?


kevin433

Recommended Posts

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.

Link to comment

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

Link to comment
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

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...