summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <mana@crushnet.org>2010-01-08 22:53:26 +0100
committerPhilipp Sehmisch <mana@crushnet.org>2010-01-08 22:53:26 +0100
commit5c5abafd2b0dcbcdeefad625b03732949c56056f (patch)
tree37b0b903ff23f37a8103e8c365110332a872bec7 /src
parentde7d79c7f42636065ca5281fa3bec151e34a7c48 (diff)
downloadmanaserv-5c5abafd2b0dcbcdeefad625b03732949c56056f.tar.gz
manaserv-5c5abafd2b0dcbcdeefad625b03732949c56056f.tar.bz2
manaserv-5c5abafd2b0dcbcdeefad625b03732949c56056f.tar.xz
manaserv-5c5abafd2b0dcbcdeefad625b03732949c56056f.zip
Added script binding for checking the kill count for each monster so that uninventive server admins can implement their boring kill-ten-rats quests.
Diffstat (limited to 'src')
-rw-r--r--src/game-server/character.cpp12
-rw-r--r--src/game-server/character.hpp5
-rw-r--r--src/scripting/lua.cpp29
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 },