Which LUA Functions?
doCreatureChangeMaxHealth(cid, newHealth)
doCreatureChangeMaxMana(cid, newMana)
getPlayerSummonCount(cid)
getCreatureSummonCountByName(cid, name)
Start of the code:
luascrpt.cpp
Add...
...under
Add...
...under
luascrpt.h
Add...
...under
creature.cpp
Add...
...above
creature.h
Add...
...above
End of the code:
Rebuild all and your are done.
Explanation
doCreatureChangeMaxHealth(cid, 500) - Means, the max hp of that creature will be 500. If he/she has 1000 hp, he/she will get 500 as MAX hp. If he/she has 200 then he/she will get 500 as MAX hp. So it doesn't matter how much you have, just write how much hp you want it to be as MAX. Note that you may need creaturescripts for this, incase he/she dies/reloggs.
doCreatureChangeMaxMana(cid, 500) - Same as above, but on mana
getPlayerSummonCount(cid) - Returns the ammount of total summons the player has.
getCreatureSummonCountByName(cid, rat) - Returns the ammount of total summons the player has with the name "rat".
Please leave a comment
And if there is a better way to do this, please tell me then. Still learning
Yours,
Kadj
doCreatureChangeMaxHealth(cid, newHealth)
doCreatureChangeMaxMana(cid, newMana)
getPlayerSummonCount(cid)
getCreatureSummonCountByName(cid, name)
Start of the code:
luascrpt.cpp
Add...
Code:
//doCreatureChangeMaxHealth(cid, newHealth)
lua_register(m_luaState, "doCreatureChangeMaxHealth", LuaScriptInterface::luaDoCreatureChangeMaxHealth);
//doCreatureChangeMaxMana(cid, newMana)
lua_register(m_luaState, "doCreatureChangeMaxMana", LuaScriptInterface::luaDoCreatureChangeMaxMana);
//getPlayerSummonCount(cid)
lua_register(m_luaState, "getPlayerSummonCount", LuaScriptInterface::luaGetPlayerSummonCount);
//getCreatureSummonCountByName(cid, name)
lua_register(m_luaState, "getCreatureSummonCountByName", LuaScriptInterface::luaGetCreatureSummonCountByName);
...under
Code:
//escapeString(str)
lua_register(m_luaState, "escapeString", LuaScriptInterface::luaEscapeString);
Add...
Code:
int32_t LuaScriptInterface::luaDoCreatureChangeMaxHealth(lua_State* L)
{
//doCreatureChangeMaxHealth(uid,newHealth)
int32_t healthChange = (int32_t)popNumber(L);
uint32_t cid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Creature* creature = env->getCreatureByUID(cid);
if(creature)
{
creature->changeMaxHealth(healthChange);
lua_pushnumber(L, LUA_NO_ERROR);
}
else
{
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushnumber(L, LUA_ERROR);
}
return 1;
}
int32_t LuaScriptInterface::luaDoCreatureChangeMaxMana(lua_State* L)
{
//doCreatureChangeMaxMana(uid,newMana)
int32_t manaChange = (int32_t)popNumber(L);
uint32_t cid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Creature* creature = env->getCreatureByUID(cid);
if(creature)
{
creature->changeMaxMana(manaChange);
lua_pushnumber(L, LUA_NO_ERROR);
}
else
{
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushnumber(L, LUA_ERROR);
}
return 1;
}
int32_t LuaScriptInterface::luaGetPlayerSummonCount(lua_State* L)
{
//getPlayerSummonCount(cid)
uint32_t cid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Creature* creature = env->getCreatureByUID(cid);
if(creature)
{
int32_t summons = creature->getSummonCount();
lua_pushnumber(L, summons);
}
else
{
reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
lua_pushnumber(L, LUA_ERROR);
}
return 1;
}
int LuaScriptInterface::luaGetCreatureSummonCountByName(lua_State *L)
{
std::string name = popString(L);
uint32_t uid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Creature* creature = env->getCreatureByUID(uid);
if(creature){
int count = 0;
std::list<Creature*>::iterator cit;
for(cit = creature->summons.begin(); cit != creature->summons.end(); ++cit){
if((*cit)->getName() == name){
count = count + 1;
}
}
if(count > 0){
lua_pushnumber(L, count);
}
}
else{
reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
lua_pushnumber(L, LUA_ERROR);
}
return 1;
}
...under
Code:
int32_t LuaScriptInterface::luaEscapeString(lua_State* L)
{
//escapeString(str)
std::string str = popString(L);
lua_pushstring(L, Database::escapeString(str).c_str());
return 1;
}
luascrpt.h
Add...
Code:
static int32_t luaDoCreatureChangeMaxHealth(lua_State* L);
static int32_t luaDoCreatureChangeMaxMana(lua_State* L);
static int32_t luaDoCreatureChangeHealth(lua_State* L);
static int32_t luaDoCreatureChangeMana(lua_State* L);
static int32_t luaGetPlayerSummonCount(lua_State* L);
static int luaGetCreatureSummonCountByName(lua_State *L);
...under
Code:
static int32_t luaEscapeString(lua_State* L);
creature.cpp
Add...
Code:
void Creature::changeMaxHealth(int32_t healthChange)
{
healthMax = (int32_t)healthChange;
g_game.addCreatureHealth(this);
}
void Creature::changeMaxMana(int32_t manaChange)
{
manaMax = (int32_t)manaChange;
}
...above
Code:
void Creature::changeHealth(int32_t healthChange)
{
if(healthChange > 0)
health += std::min(healthChange, getMaxHealth() - health);
else
health = std::max((int32_t)0, health + healthChange);
g_game.addCreatureHealth(this);
}
creature.h
Add...
Code:
virtual void changeMaxHealth(int32_t healthChange);
virtual void changeMaxMana(int32_t manaChange);
...above
Code:
virtual void changeHealth(int32_t healthChange);
Rebuild all and your are done.
Explanation
doCreatureChangeMaxHealth(cid, 500) - Means, the max hp of that creature will be 500. If he/she has 1000 hp, he/she will get 500 as MAX hp. If he/she has 200 then he/she will get 500 as MAX hp. So it doesn't matter how much you have, just write how much hp you want it to be as MAX. Note that you may need creaturescripts for this, incase he/she dies/reloggs.
doCreatureChangeMaxMana(cid, 500) - Same as above, but on mana
getPlayerSummonCount(cid) - Returns the ammount of total summons the player has.
getCreatureSummonCountByName(cid, rat) - Returns the ammount of total summons the player has with the name "rat".
Please leave a comment
And if there is a better way to do this, please tell me then. Still learning
Yours,
Kadj
Last edited: