diff options
-rw-r--r-- | src/game-server/character.cpp | 12 | ||||
-rw-r--r-- | src/game-server/character.hpp | 5 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 29 |
3 files changed, 46 insertions, 0 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index b2a21c5a..0775c75f 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -519,6 +519,18 @@ void Character::incrementKillCount(int monsterType) }; } +int Character::getKillCount(int monsterType) +{ + std::map<int, int>::iterator i = mKillCount.find(monsterType); + if (i == mKillCount.end()) + { + return 0; + } else { + return i->second; + }; +} + + void Character::recalculateLevel() { std::list<float> levels; diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp index fbba4eee..05c36c24 100644 --- a/src/game-server/character.hpp +++ b/src/game-server/character.hpp @@ -323,6 +323,11 @@ class Character : public Being void incrementKillCount(int monsterType); /** + * Gets the number of monsters the character killed of a given type + */ + int getKillCount(int monsterType); + + /** * Shortcut to get being's health */ int getHealth() const diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 1c79ede9..3b33a3d1 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1292,6 +1292,34 @@ static int chr_get_hair_color(lua_State *s) } /** + * Get the number of monsters the player killed of a type + * mana.chr_get_kill_count (character, monsterType) + */ +static int chr_get_kill_count(lua_State *s) +{ + Character *c = getCharacter(s, 1); + if (!c) + { + raiseScriptError(s, "chr_get_kill_count called for nonexistent character."); + return 0; + } + + if (!lua_isnumber(s, 2)) + { + raiseScriptError(s, "chr_get_kill_count called with incorect parameters"); + return 0; + } + + int id = lua_tointeger(s, 2); + + int kills = c->getKillCount(id); + + lua_pushinteger(s, kills); + return 1; +} + + +/** * Returns the rights level of a character. * mana.chr_get_rights (being) */ @@ -1463,6 +1491,7 @@ LuaScript::LuaScript(): { "chr_get_hair_style", &chr_get_hair_style }, { "chr_set_hair_color", &chr_set_hair_color }, { "chr_get_hair_color", &chr_get_hair_color }, + { "chr_get_kill_count", &chr_get_kill_count }, { "exp_for_level", &exp_for_level }, { "monster_create", &monster_create }, { "monster_load_script", &monster_load_script }, |