summaryrefslogtreecommitdiff
path: root/src/scripting
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2012-03-17 20:20:10 +0100
committerErik Schilling <ablu.erikschilling@googlemail.com>2012-03-17 23:40:30 +0100
commit61ac3cbf1e507f103e5fc240958971f512cd8c73 (patch)
tree28fc78e2047a91f9b6131d2f3e62d83c4db23711 /src/scripting
parenta6c3eed2b9a91e9768ec6ce137879cac13703dea (diff)
downloadmanaserv-61ac3cbf1e507f103e5fc240958971f512cd8c73.tar.gz
manaserv-61ac3cbf1e507f103e5fc240958971f512cd8c73.tar.bz2
manaserv-61ac3cbf1e507f103e5fc240958971f512cd8c73.tar.xz
manaserv-61ac3cbf1e507f103e5fc240958971f512cd8c73.zip
Made skill related function capable of taking the skill name as parameter
Reviewed-by: bjorn.
Diffstat (limited to 'src/scripting')
-rw-r--r--src/scripting/lua.cpp19
-rw-r--r--src/scripting/luautil.cpp12
-rw-r--r--src/scripting/luautil.h1
3 files changed, 27 insertions, 5 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 136350da..2d98c713 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1019,7 +1019,10 @@ static int being_damage(lua_State *s)
return 0;
}
}
- dmg.skill = luaL_optint(s, 8, 0);
+ if (lua_gettop(s) >= 8)
+ {
+ dmg.skill = checkSkill(s, 8);
+ }
being->damage(source, dmg);
return 0;
@@ -1682,12 +1685,15 @@ static int chr_shake_screen(lua_State *s)
/**
* chr_get_exp(Character*, int skill): int
- * Gets the exp total in a skill of a specific character
+ * chr_get_exp(Character*, string skillname): int
+ * Gets the exp total in a skill of a specific character.
+ * If called with skillname this name has to be in this format:
+ * "<setname>_<skillname>"
*/
static int chr_get_exp(lua_State *s)
{
Character *c = checkCharacter(s, 1);
- const int skill = luaL_checkint(s, 2);
+ int skill = checkSkill(s, 2);
const int exp = c->getExperience(skill);
lua_pushinteger(s, exp);
@@ -1696,14 +1702,17 @@ static int chr_get_exp(lua_State *s)
/**
* chr_give_exp(Character*, int skill, int amount[, int optimal_level]): void
+ * chr_give_exp(Character*, string skillname, int amount
+ * [, int optimal_level]): void
* Gives the character a certain amount of experience points
* in a skill. Can also be used to reduce the exp amount when
- * desired.
+ * desired. If called with skillname this name has to be in this format:
+ * "<setname>_<skillname>"
*/
static int chr_give_exp(lua_State *s)
{
Character *c = checkCharacter(s, 1);
- const int skill = luaL_checkint(s, 2);
+ int skill = checkSkill(s, 2);
const int exp = luaL_checkint(s, 3);
const int optimalLevel = luaL_optint(s, 4, 0);
diff --git a/src/scripting/luautil.cpp b/src/scripting/luautil.cpp
index 8bc72d3f..67dd7395 100644
--- a/src/scripting/luautil.cpp
+++ b/src/scripting/luautil.cpp
@@ -26,6 +26,7 @@
#include "game-server/monster.h"
#include "game-server/monstermanager.h"
#include "game-server/npc.h"
+#include "game-server/skillmanager.h"
#include "utils/logger.h"
@@ -252,6 +253,17 @@ NPC *checkNPC(lua_State *s, int p)
return npc;
}
+int checkSkill(lua_State *s, int p)
+{
+ if (lua_isstring(s, p))
+ {
+ int id = skillManager->getId(luaL_checkstring(s, p));
+ luaL_argcheck(s, id != 0, p, "invalid skill name");
+ return id;
+ }
+ return luaL_checkint(s, 2);
+}
+
MapComposite *checkCurrentMap(lua_State *s, Script *script /* = 0 */)
{
diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h
index 89ea4800..a0eac120 100644
--- a/src/scripting/luautil.h
+++ b/src/scripting/luautil.h
@@ -168,6 +168,7 @@ ItemClass * checkItemClass(lua_State *s, int p);
Monster * checkMonster(lua_State *s, int p);
MonsterClass * checkMonsterClass(lua_State *s, int p);
NPC * checkNPC(lua_State *s, int p);
+int checkSkill(lua_State *s, int p);
MapComposite * checkCurrentMap(lua_State *s, Script *script = 0);
Script::Thread* checkCurrentThread(lua_State *s, Script *script = 0);