Jump to content

global variable?


Recommended Posts

if anyone here knows pawno there is a command that i can do for example

  
  
new bool:first[MAX_PLAYERS]; 
  
  

so my question how do i make global variable for all players (a boolean, only true and false )

so then on player spawn i can do...

first[playerid] = true; 
  
--or 
  
if(first[thePlayer]==true) --etc... and so on.. 
  

i guess i mean by max_players is for each client

or something like that if anybody have understood me ? :P

Link to comment

in lua you don't need to define variables, you just make them

  
players = { } 
players[1] = true 
players[2] = false 
--or 
players = { true, false } 
  

but mta doesn't have build in player id system.

so for all players table you need to use

  
players = getElementsByType("player") 
  
for key,value in pairs(players) do 
  --do what you want 
end 
  

Link to comment

ok so how can i do something like this in lua?

  
  
firstspawn = {} 
  
function player_Spawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension ) 
    if(firstspawn[source]) 
                --do stuff... 
                  firstspawn[source] = false;   
        end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), player_Spawn ) 
  
  

Link to comment

why u ask ? i know it doesnt work ! pls help me dont post useless -.-

  
  
if(firstspawn[source]) then 
        firstspawn[source] = false; 
        givePlayerMoney ( source, 10000 ) 
        outputChatBox("called?") 
        createBlipAttachedTo (source, 56) 
    end 
  
  

Link to comment

if(firstspawn[source]) then -- won't pass, ever.

if (not firstspawn[source]) then -- use this instead

firstspawn[source] = true -- do this after their first spawn so it won't run on their 2nd spawn.

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...