diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2008-11-01 01:41:12 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2008-11-01 01:41:12 +0000 |
commit | ad5efe104cd7639009622393f16bfd93075fcb34 (patch) | |
tree | f9618bffd5e38c9f50722d36d4d77e8bfea06168 /src/scripting/lua.cpp | |
parent | 3ec0d0f152be4381dc843bc1ca99f8731c8fb366 (diff) | |
download | manaserv-ad5efe104cd7639009622393f16bfd93075fcb34.tar.gz manaserv-ad5efe104cd7639009622393f16bfd93075fcb34.tar.bz2 manaserv-ad5efe104cd7639009622393f16bfd93075fcb34.tar.xz manaserv-ad5efe104cd7639009622393f16bfd93075fcb34.zip |
Added script bindings for manipulating the characters experience.
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r-- | src/scripting/lua.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index c0c7a95c..34e66427 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -902,6 +902,77 @@ static int LuaEffect_Create(lua_State *s) return 0; } +/** + * Gets the exp total in a skill of a specific character + * tmw.chr_get_exp (being, skill) + */ +static int LuaChr_GetExp(lua_State *s) +{ + Character *c = getCharacter(s, 1); + if (!c) + { + raiseScriptError(s, "luaChr_GetExp called for nonexistent character."); + return 0; + } + + int skill = lua_tointeger(s, 2); + if (skill < CHAR_SKILL_BEGIN || skill >= CHAR_SKILL_END) + { + raiseScriptError(s, "luaChr_GetExp called for nonexistent skill number %d.", skill); + return 0; + } + + int exp = c->getExperience(skill - CHAR_SKILL_BEGIN); + + lua_pushinteger(s, exp); + return 1; +} + + +/** + * Gives the character a certain amount of experience points + * in a skill. Can also be used to reduce the exp amount when + * desired. + * tmw.chr_give_exp (being, skill, amount) + */ +static int LuaChr_GiveExp(lua_State *s) +{ + Character *c = getCharacter(s, 1); + if (!c) + { + raiseScriptError(s, "luaChr_GiveExp called for nonexistent character."); + return 0; + } + + int skill = lua_tointeger(s, 2); + if (skill < CHAR_SKILL_BEGIN || skill >= CHAR_SKILL_END) + { + raiseScriptError(s, "luaChr_GiveExp called for nonexistent skill number %d.", skill); + return 0; + } + + int exp = lua_tointeger(s, 3); + + c->receiveExperience(skill, exp); + + return 0; +} + + +/** + * Returns the exp total necessary to reach a specific skill level. + * tmw.exp_for_level (level) + */ +static int LuaExpForLevel(lua_State *s) +{ + int level = lua_tointeger(s, 1); + + int exp = Character::expForLevel(level); + + lua_pushinteger(s, exp); + return 1; +} + LuaScript::LuaScript(): nbArgs(-1) @@ -923,6 +994,9 @@ LuaScript::LuaScript(): { "chr_get_quest", &LuaChr_GetQuest }, { "chr_set_quest", &LuaChr_SetQuest }, { "chr_get_post", &LuaChr_GetPost }, + { "chr_get_exp", &LuaChr_GetExp }, + { "chr_give_exp", &LuaChr_GiveExp }, + { "exp_for_level", &LuaExpForLevel }, { "monster_create", &LuaMonster_Create }, { "being_walk", &LuaBeing_Walk }, { "being_say", &LuaBeing_Say }, |