• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[C++] doCreatureCombatHealth

perdigs

New Member
Joined
Aug 22, 2010
Messages
114
Reaction score
1
Code:
int32_t LuaScriptInterface::luaDoCombatAreaHealth(lua_State* L)
{
	//doCombatAreaHealth(cid, type, pos, area, min, max, effect)
	MagicEffect_t effect = (MagicEffect_t)popNumber(L);
	int32_t maxChange = (int32_t)popNumber(L), minChange = (int32_t)popNumber(L);
	uint32_t areaId = popNumber(L);

	PositionEx pos;
	popPosition(L, pos);

	CombatType_t combatType = (CombatType_t)popNumber(L);
	uint32_t cid = popNumber(L);

	ScriptEnviroment* env = getEnv();
	Creature* creature = NULL;
	if(cid)
	{
		if(!(creature = env->getCreatureByUID(cid)))
		{
			errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
			lua_pushboolean(L, false);
			return 1;
		}
	}

	const CombatArea* area = env->getCombatArea(areaId);
	if(area || !areaId)
	{
		CombatParams params;
		params.combatType = combatType;
		params.effects.impact = effect;

		Combat::doCombatHealth(creature, pos, area, minChange, maxChange, params);
		lua_pushboolean(L, true);
	}
	else
	{
		errorEx(getError(LUA_ERROR_AREA_NOT_FOUND));
		lua_pushboolean(L, false);
	}

	return 1;
}

Please i need to add to this function a hitcolor
//doCombatAreaHealth(cid, type, pos, area, min, max, effect[, hitcolor])

please help.:D
 
Why you dont use it as lua ? well, in c++ proapapbly is better but this is idea good idea for you how to make it...

if its a creature script then
LUA:
function onStatsChange(cid, attacker, combatee, value)
if combatee ~= COMBAT_PHYSICALDAMAGE then
if isCreature(attacker) then -- or player what ever.
doCreatureAddHealth(attacker, -value)
doSendAnimatedText(getThingPos(attacker), -value, 191) -- nice idea huh :) it can nicely change whatever collor you wanna
end
end
return true
end -- sorry writed in browser

If if you wanna for actions then propapbly

LUA:
local damage = 50
function onUse or what ever OnstepIn (cid)
doCreatureAddHealth(cid, -damage)
doSendAnimatedText(getThingPos(cid), -damage, 191)
return true
end-- sorry writed in browser i just writed idea how to do it !
 
is better but i have 185 spells and i make it in callback and this callback only hits the target
i have one spells with physical damage hit is blue and other with the physical damage is red
how to i set this in lua ???
is much better in c++ or iam wrong ?
 
is better but i have 185 spells and i make it in callback and this callback only hits the target
i have one spells with physical damage hit is blue and other with the physical damage is red
how to i set this in lua ???
is much better in c++ or iam wrong ?

i already said you how to set it !
 
Try replacing the function with this:
[cpp]int32_t LuaInterface::luaDoCombatAreaHealth(lua_State* L)
{
//doCombatAreaHealth(cid, type, pos, area, min, max, effect, [color])
Color_t hitColor = COLOR_UNKNOWN;
if(lua_gettop(L) > 7)
hitColor = (Color_t)popNumber(L);

MagicEffect_t effect = (MagicEffect_t)popNumber(L);
int32_t maxChange = (int32_t)popNumber(L), minChange = (int32_t)popNumber(L);
uint32_t areaId = popNumber(L);

PositionEx pos;
popPosition(L, pos);

CombatType_t combatType = (CombatType_t)popNumber(L);
uint32_t cid = popNumber(L);

ScriptEnviroment* env = getEnv();
Creature* creature = NULL;
if(cid)
{
if(!(creature = env->getCreatureByUID(cid)))
{
errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}
}

const CombatArea* area = env->getCombatArea(areaId);
if(area || !areaId)
{
CombatParams params;
params.combatType = combatType;
params.effects.impact = effect;
if(hitColor != COLOR_UNKNOWN)
params.effects.color = hitColor;

Combat::doCombatHealth(creature, pos, area, minChange, maxChange, params);
lua_pushboolean(L, true);
}
else
{
errorEx(getError(LUA_ERROR_AREA_NOT_FOUND));
lua_pushboolean(L, false);
}

return 1;
}[/cpp]
 
Try replacing the function with this:
[cpp]int32_t LuaInterface::luaDoCombatAreaHealth(lua_State* L)
{
//doCombatAreaHealth(cid, type, pos, area, min, max, effect, [color])
Color_t hitColor = COLOR_UNKNOWN;
if(lua_gettop(L) > 7)
hitColor = (Color_t)popNumber(L);

MagicEffect_t effect = (MagicEffect_t)popNumber(L);
int32_t maxChange = (int32_t)popNumber(L), minChange = (int32_t)popNumber(L);
uint32_t areaId = popNumber(L);

PositionEx pos;
popPosition(L, pos);

CombatType_t combatType = (CombatType_t)popNumber(L);
uint32_t cid = popNumber(L);

ScriptEnviroment* env = getEnv();
Creature* creature = NULL;
if(cid)
{
if(!(creature = env->getCreatureByUID(cid)))
{
errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}
}

const CombatArea* area = env->getCombatArea(areaId);
if(area || !areaId)
{
CombatParams params;
params.combatType = combatType;
params.effects.impact = effect;
if(hitColor != COLOR_UNKNOWN)
params.effects.color = hitColor;

Combat::doCombatHealth(creature, pos, area, minChange, maxChange, params);
lua_pushboolean(L, true);
}
else
{
errorEx(getError(LUA_ERROR_AREA_NOT_FOUND));
lua_pushboolean(L, false);
}

return 1;
}[/cpp]

I try to recompile with this code but the compiler returns this errors
Code:
In static member function `static int32_t LuaScriptInterface::luaDoCombatAreaHealth(lua_State*)':
5873 C:\Users\Casa\Desktop\OTS\Sources\Source (New 12)\luascript.cpp `Color_t' was not declared in this scope 
5873 C:\Users\Casa\Desktop\OTS\Sources\Source (New 12)\luascript.cpp expected `;' before "hitColor" 
5875 C:\Users\Casa\Desktop\OTS\Sources\Source (New 12)\luascript.cpp `hitColor' was not declared in this scope 
5875 C:\Users\Casa\Desktop\OTS\Sources\Source (New 12)\luascript.cpp expected `;' before "popNumber" 
5905 C:\Users\Casa\Desktop\OTS\Sources\Source (New 12)\luascript.cpp `hitColor' was not declared in this scope 
5905 C:\Users\Casa\Desktop\OTS\Sources\Source (New 12)\luascript.cpp `COLOR_UNKNOWN' was not declared in this scope 
 C:\Users\Casa\Desktop\OTS\Sources\Source (New 12)\dev-cpp\Makefile.win [Build Error]  [obj//luascript.o] Error 1
im using TFS 0.3.6 Distro.
Tks for attention.
 
Back
Top