summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-10-23 10:33:09 +0000
committerDavid Athay <ko2fan@gmail.com>2008-10-23 10:33:09 +0000
commitd1cd50665be45056446c6dc2a12cf0f47d2a2439 (patch)
tree2dc4459efe8595c8a2ad3727a0ab99c76c860d36 /src
parent2fdca71554dee26bae4b1ee0dc63469599144c59 (diff)
downloadmanaserv-d1cd50665be45056446c6dc2a12cf0f47d2a2439.tar.gz
manaserv-d1cd50665be45056446c6dc2a12cf0f47d2a2439.tar.bz2
manaserv-d1cd50665be45056446c6dc2a12cf0f47d2a2439.tar.xz
manaserv-d1cd50665be45056446c6dc2a12cf0f47d2a2439.zip
Added functions for getting a being's name and attributes in scripts
Diffstat (limited to 'src')
-rw-r--r--src/scripting/lua.cpp96
1 files changed, 74 insertions, 22 deletions
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 *)&registryKey);
+ 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 *)&registryKey);
+ 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);