_RuiGy Posted November 2, 2012 Share Posted November 2, 2012 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
Castillo Posted November 2, 2012 Share Posted November 2, 2012 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
_RuiGy Posted November 2, 2012 Author Share Posted November 2, 2012 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
Castillo Posted November 2, 2012 Share Posted November 2, 2012 Yes, it is, you can make: nItemFound [ source ] = { } Then do: nItemFound [ source ] [ 1 ] = 0 Link to comment
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