lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Ben Sunshine-Hill wrote:
I would like to ask a question.... for a MMO RPG wrote by C++ and
using LUA as a script tools..... when a player access the script like

the following..

if (gold >= 5000)
  Dec(gold, 5000)

How do the server know which player will be decreased $5000 since
in LUA doesn't know the player UIN......


Lua will know the player UIN if you tell it the player UIN. But I think your code would probably look more like the following:

if(myPlayer.gold >= 5000) then
    myPlayer.gold -= 5000
end


In this situation you might need to protect players from each other.
So maybe the setup is like this:

/* in C++ or C code */

setup_lua_environment_for_user(UIN);

/* now lua references to gold mean UIN.gold */
call_lua_script(SCRIPT);

setup_lua_environment_for_user(OTHER_UIN);

/* now lua references to gold mean OTHER_UIN.gold */
call_lua_script(SCRIPT);


	Eero