• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

What is here wrong ? And how to change max hp with function movements.

darex11

Own Big Server
Joined
Aug 21, 2007
Messages
219
Reaction score
0
Location
Poland
Hello in this function is bug. I don't know where...

...just kills you.
I very need this functions to change max hp and mana at weapon equip.

luascript.cpp
Code:
	//doCreatureChangeMaxHealth(cid, newHealth)
	lua_register(m_luaState, "doCreatureChangeMaxHealth", LuaScriptInterface::luaDoCreatureChangeMaxHealth);

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;
}

luascript.h
Code:
        static int32_t luaDoCreatureChangeMaxHealth(lua_State* L);

creature.cpp
Code:
void Creature::changeMaxHealth(int32_t healthChange)
{
   
    healthMax = (int32_t)healthChange;

	g_game.addCreatureHealth(this);
}

creature.h
Code:
        virtual void changeMaxHealth(int32_t healthChange);


When using this script, as I said, it kills you and when you relog, you login with 0 HP so you die again and when you login the second time you don't die.

And in movements I make function:
Code:
function onEquip(cid, item)
    doCreatureChangeMaxHealth(cid, (getMaxHealth+50))
	return TRUE
end
and

Code:
function onDeEquip(cid, item)
    doCreatureChangeMaxHealth(cid, (getMaxHealth-50))
	return TRUE
end
And don't works. Any help ?
 
Back
Top