Jump to content

Player Variables


_RuiGy

Recommended Posts

Hello again,

I would like to know if there is a way to create player variables, example:

--SERVER-SIDE 
local nItemFound = 0 
--------------------- 
function onPlayerPickupItem( thePickup ) 
    outputChatBox ( "* You found a item. Total itens found: " .. nItemFound, source ) 
    nItemFound = nItemFound + 1 
end 
addEventHandler ( "onPlayerPickupHit", getRootElement(), onPlayerPickupItem) 

But, this way when another player find a item nItemFound will be increased too.

Thank you!

Link to comment

You can use tables:

--SERVER-SIDE 
local nItemFound = { } 
--------------------- 
function onPlayerPickupItem ( thePickup ) 
    if ( not nItemFound [ source ] ) then 
        nItemFound [ source ] = 0 
    end 
    outputChatBox ( "* You found a item. Total itens found: ".. nItemFound [ source ], source ) 
    nItemFound [ source ] = ( nItemFound [ source ] + 1 ) 
end 
addEventHandler ( "onPlayerPickupHit", getRootElement(), onPlayerPickupItem ) 

What I did is store the player in the table.

Link to comment
You can use tables:
--SERVER-SIDE 
local nItemFound = { } 
--------------------- 
function onPlayerPickupItem ( thePickup ) 
    if ( not nItemFound [ source ] ) then 
        nItemFound [ source ] = 0 
    end 
    outputChatBox ( "* You found a item. Total itens found: ".. nItemFound [ source ], source ) 
    nItemFound [ source ] = ( nItemFound [ source ] + 1 ) 
end 
addEventHandler ( "onPlayerPickupHit", getRootElement(), onPlayerPickupItem ) 

What I did is store the player in the table.

Oh, thank you!

It's my first-week in lua, i'm still learning the syntax.

----------------------------------------------------------------

Btw, and is there a way to make a multidimensional table?

Like:

nItemFound[source][itemid] 

Thanks again!

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