diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 96 |
2 files changed, 79 insertions, 22 deletions
@@ -1,3 +1,8 @@ +2008-10-23 David Athay <ko2fan@gmail.com> + + * src/scripting/lua.cpp: Added functions for getting being name and + attributes in scripts. + 2008-10-22 Chuck Miller <shadowmil@gmail.com> * src/game-server/mapreader.cpp, src/utils/sting.cpp diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 846a43a1..f5365623 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -218,6 +218,7 @@ static int LuaNpc_Create(lua_State *s) /** * Enable a NPC if it has previously disabled + * tmw.npc_enable(npc) */ static int LuaNPC_Enable(lua_State *s) { @@ -234,6 +235,7 @@ static int LuaNPC_Enable(lua_State *s) /** * Disable a NPC + * tmw.npc_disable(npc) */ static int LuaNPC_Disable(lua_State *s) { @@ -500,6 +502,54 @@ static int LuaBeing_Damage(lua_State *s) } /** + * Gets the attribute for a being + * tmw.being_get_attribute(being, attribute) + */ +static int LuaBeing_GetAttribute(lua_State *s) +{ + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + + Being *being = getBeing(s, 1); + + if (being) + { + int attr = lua_tointeger(s, 2); + if (attr == 0) + { + raiseScriptError(s, + "being_get_attribute called with incorrect parameters."); + return 0; + } + else + { + lua_pushinteger(s, being->getModifiedAttribute(attr)); + } + } + + return 1; +} + +/** + * Gets the being's name + * tmw.being_get_name(being) + */ +static int LuaBeing_GetName(lua_State *s) +{ + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + + Being *being = getBeing(s, 1); + + if (being) + { + lua_pushstring(s, being->getName().c_str()); + } + + return 1; +} + +/** * Function for getting the x-coordinate of the position of a being */ static int LuaPosX(lua_State *s) @@ -807,28 +857,30 @@ LuaScript::LuaScript(): // Put some callback functions in the scripting environment. static luaL_reg const callbacks[] = { - { "npc_create", &LuaNpc_Create }, - { "npc_message", &LuaNpc_Message }, - { "npc_choice", &LuaNpc_Choice }, - { "npc_trade", &LuaNpc_Trade }, - { "npc_enable", &LuaNPC_Enable }, - { "npc_disable", &LuaNPC_Disable }, - { "chr_warp", &LuaChr_Warp }, - { "chr_inv_change", &LuaChr_InvChange }, - { "chr_inv_count", &LuaChr_InvCount }, - { "chr_get_quest", &LuaChr_GetQuest }, - { "chr_set_quest", &LuaChr_SetQuest }, - { "monster_create", &LuaMonster_Create }, - { "being_walk", &LuaBeing_Walk }, - { "being_say", &LuaBeing_Say }, - { "being_damage", &LuaBeing_Damage }, - { "posX", &LuaPosX }, - { "posY", &LuaPosY }, - { "trigger_create", &LuaTrigger_Create }, - { "chatmessage", &LuaChatmessage }, - { "get_beings_in_circle", &LuaGetBeingsInCircle}, - { "get_post", &LuaGetPost }, - { "note_on_death", &LuaNoteOnDeath }, + { "npc_create", &LuaNpc_Create }, + { "npc_message", &LuaNpc_Message }, + { "npc_choice", &LuaNpc_Choice }, + { "npc_trade", &LuaNpc_Trade }, + { "npc_enable", &LuaNPC_Enable }, + { "npc_disable", &LuaNPC_Disable }, + { "chr_warp", &LuaChr_Warp }, + { "chr_inv_change", &LuaChr_InvChange }, + { "chr_inv_count", &LuaChr_InvCount }, + { "chr_get_quest", &LuaChr_GetQuest }, + { "chr_set_quest", &LuaChr_SetQuest }, + { "monster_create", &LuaMonster_Create }, + { "being_walk", &LuaBeing_Walk }, + { "being_say", &LuaBeing_Say }, + { "being_damage", &LuaBeing_Damage }, + { "being_get_attribute", &LuaBeing_GetAttribute}, + { "being_get_name", &LuaBeing_GetName }, + { "posX", &LuaPosX }, + { "posY", &LuaPosY }, + { "trigger_create", &LuaTrigger_Create }, + { "chatmessage", &LuaChatmessage }, + { "get_beings_in_circle", &LuaGetBeingsInCircle }, + { "get_post", &LuaGetPost }, + { "note_on_death", &LuaNoteOnDeath }, { NULL, NULL } }; luaL_register(mState, "tmw", callbacks); |