summaryrefslogtreecommitdiff
path: root/src/scripting/lua.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-12-02 19:09:18 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2012-01-10 01:12:51 +0100
commit4c9db4a20aad649f80c9db8379f372de7361096b (patch)
tree317b817b830140a07970549995ed683b90856d22 /src/scripting/lua.cpp
parent1c40074d28676ec996ec91f1719cff43077f15f6 (diff)
downloadmanaserv-4c9db4a20aad649f80c9db8379f372de7361096b.tar.gz
manaserv-4c9db4a20aad649f80c9db8379f372de7361096b.tar.bz2
manaserv-4c9db4a20aad649f80c9db8379f372de7361096b.tar.xz
manaserv-4c9db4a20aad649f80c9db8379f372de7361096b.zip
Added equip lua script functions.
One per inventory slot, one per item id or name. + Fixes from 2 Ablu's reviews. Reviewed-by: Ablu. 1st part of Mana-Mantis #339, 350.
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r--src/scripting/lua.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 9f905bcd..58492319 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -481,6 +481,75 @@ static int chr_inv_count(lua_State *s)
}
/**
+ * mana.chr_equip_slot(Character*, int inventorySlot): bool success
+ * Makes the character equip the item in the given inventory slot.
+ */
+static int chr_equip_slot(lua_State *s)
+{
+ int inventorySlot = luaL_checkint(s, 2);
+
+ Character *ch = getCharacter(s, 1);
+ if (!ch)
+ {
+ raiseScriptError(s, "chr_equip_slot "
+ "called for nonexistent character.");
+ return 0;
+ }
+ Inventory inv(ch);
+
+ lua_pushboolean(s, inv.equip(inventorySlot));
+ return 1;
+}
+
+/**
+ * mana.chr_equip_item(Character*, int itemId || string itemName): bool success
+ * Makes the character equip the item id when it's existing
+ * in the player's inventory.
+ */
+static int chr_equip_item(lua_State *s)
+{
+ // Get the itemId
+ ItemClass *it;
+ if (lua_isnumber(s, 2))
+ it = itemManager->getItem(lua_tointeger(s, 2));
+ else
+ it = itemManager->getItemByName(lua_tostring(s, 2));
+
+ if (!it)
+ {
+ raiseScriptError(s, "chr_equip_item called with invalid "
+ "item id or name.");
+ return 0;
+ }
+ unsigned int id = it->getDatabaseID();
+ if (!id)
+ {
+ LOG_WARN("chr_equip_item called with id 0! "
+ "Currency is now handled through attributes!");
+ lua_pushboolean(s, false);
+ return 1;
+ }
+
+ Character *ch = getCharacter(s, 1);
+ if (!ch)
+ {
+ raiseScriptError(s, "chr_equip_item "
+ "called for nonexistent character.");
+ return 0;
+ }
+ Inventory inv(ch);
+
+ int inventorySlot = inv.getFirstSlot(id);
+ bool success = false;
+
+ if (inventorySlot > -1)
+ success = inv.equip(inventorySlot);
+
+ lua_pushboolean(s, success);
+ return 1;
+}
+
+/**
* mana.chr_get_level(Character*): int level
* Tells the character current level.
*/
@@ -2324,6 +2393,8 @@ LuaScript::LuaScript():
{ "chr_warp", &chr_warp },
{ "chr_inv_change", &chr_inv_change },
{ "chr_inv_count", &chr_inv_count },
+ { "chr_equip_slot", &chr_equip_slot },
+ { "chr_equip_item", &chr_equip_item },
{ "chr_get_level", &chr_get_level },
{ "chr_get_quest", &chr_get_quest },
{ "chr_set_quest", &chr_set_quest },