Aikeleer
17.07.2006, 21:56
Just a little thing for the other AI-coders out there. Creating a C4-AI decoder isn't that hard. This is old work, not entirely fixed. The pieces of the puzzle are there, you just gotta put them down the right way.
Also there are a few new functions in (CanAttack i.e). You can just comment those out or create a workaround if you don't have the C4 L2NPC. EventHandler ATTACKED(attacker, damage, f0, myself) {
if ((attacker.is_pc != 0) || IsInCategory(11, attacker.npc_class_id)) {
f0 = 0;
if (SetHateGroup >= 0) {
if (IsInCategory(SetHateGroup, attacker.occupation)) {
f0 = (f0+SetHateGroupRatio);
}
}
if (attacker.occupation == SetHateOccupation) {
f0 = (f0+SetHateOccupationRatio);
}
if (SetHateRace == attacker.race) {
f0 = (f0+SetHateRaceRatio);
}
f0 = (((1.000000*damage)/(myself.sm.level+7))+((f0/100)*((1.000000*damage)/(myself.sm.level+7))));
AddAttackDesire(attacker, 1, (f0*100));
}
if (IsNullCreature(myself.top_desire_target) == 0) {
GetPathfindFailCount(myself);
if ((myself > 10) && (attacker == myself.top_desire_target) && (FloatToInt(myself.sm.hp) != FloatToInt(myself.sm.max_hp))) {
InstantTeleportInMyTerritory(myself.sm, FloatToInt(attacker.x), FloatToInt(attacker.y), FloatToInt(attacker.z));
}
if ((DistFromMe(myself.top_desire_target) > 40)) {
if (CanAttack(myself.top_desire_target) == 1) {
if ((attacker.is_pc != 0) || IsInCategory(11, attacker.npc_class_id)) {
f0 = 0;
if (SetHateGroup >= 0) {
if (IsInCategory(SetHateGroup, attacker.occupation)) {
f0 = (f0+SetHateGroupRatio);
}
}
if (attacker.occupation == SetHateOccupation) {
f0 = (f0+SetHateOccupationRatio);
}
if (SetHateRace == attacker.race) {
f0 = (f0+SetHateRaceRatio);
}
f0 = (((1.000000*damage)/(myself.sm.level+7))+((f0/100)*((1.000000*damage)/(myself.sm.level+7))));
AddAttackDesire(attacker, 1, (f0*100));
}
}
else {
RemoveAttackDesire(myself.top_desire_target);
if ((attacker.is_pc != 0) || IsInCategory(11, attacker.npc_class_id)) {
f0 = 0;
if (SetHateGroup >= 0) {
if (IsInCategory(SetHateGroup, attacker.occupation)) {
f0 = (f0+SetHateGroupRatio);
}
}
if (attacker.occupation == SetHateOccupation) {
f0 = (f0+SetHateOccupationRatio);
}
if (SetHateRace == attacker.race) {
f0 = (f0+SetHateRaceRatio);
}
f0 = (((1.000000*damage)/(myself.sm.level+7))+((f0/100)*((1.000000*damage)/(myself.sm.level+7))));
AddAttackDesire(attacker, 1, (f0*100));
}
}
}
}
super;
}
TheOrder
17.07.2006, 22:04
Aikeleer = Rules :) GJ with the AI Decompiling thing !!!
this is the complete warrior class and some others ai. btw i haven't checked it for errors.
/************************************************** *************************
* Change Log
* ------------------
* xx.xx.2006
* Script Decompiled by SauDecompiler build 160706.1
*
************************************************** *************************/
class warrior : warrior_parameter
{
parameter:
float Attack_DecayRatio = 6.600000;
float UseSkill_DecayRatio = 660xx.xx0000;
float Attack_BoostValue = 3xx.xx0000;
float UseSkill_BoostValue = 1000xx.xx0000;
handler:
EventHandler NO_DESIRE()
{
AddMoveAroundDesire(5,5);
}
EventHandler CREATED()
{
if( ShoutMsg1 > 0 )
{
Shout(MakeFString(ShoutMsg1,"","","","",""));
}
if( MoveAroundSocial > 0 || ShoutMsg2 > 0 || ShoutMsg3 > 0 )
{
AddTimerEx(1001,10000);
}
super;
}
EventHandler TIMER_FIRED_EX(timer_id)
{
if( timer_id == 1001 )
{
if( ( myself.p_state == 1 || myself.p_state == 2 || myself.p_state == 9 ) && ( myself.sm.c_ai2 > ( myself.sm.max_hp * 0.400000 ) && myself.sm.alive != 0 ) )
{
if( MoveAroundSocial > 0 || MoveAroundSocial1 > 0 || MoveAroundSocial2 > 0 )
{
if( MoveAroundSocial2 > 0 && Rand(100) < 20 )
{
AddEffectActionDesire(myself.sm,3,( ( MoveAroundSocial2 * 1000 ) / 30 ),50);
}
else if( MoveAroundSocial1 > 0 && Rand(100) < 20 )
{
AddEffectActionDesire(myself.sm,2,( ( MoveAroundSocial1 * 1000 ) / 30 ),50);
}
else if( MoveAroundSocial > 0 && Rand(100) < 20 )
{
AddEffectActionDesire(myself.sm,1,( ( MoveAroundSocial * 1000 ) / 30 ),50);
}
}
if( ShoutMsg2 > 0 && Rand(1000) < 17 )
{
Shout(MakeFString(ShoutMsg2,"","","","",""));
}
}
else if( myself.p_state == 3 )
{
if( ShoutMsg3 > 0 && Rand(100) < 10 )
{
Shout(MakeFString(ShoutMsg3,"","","","",""));
}
}
AddTimerEx(1001,10000);
}
super;
}
EventHandler ATTACKED(attacker,damage,f0)
{
if( attacker.is_pc != 0 || IsInCategory(11,attacker.npc_class_id) )
{
f0 = 0;
if( SetHateGroup >= 0 )
{
if( IsInCategory(SetHateGroup,attacker.occupation) )
{
f0 = ( f0 + SetHateGroupRatio );
}
}
if( attacker.occupation == SetHateOccupation )
{
f0 = ( f0 + SetHateOccupationRatio );
}
if( SetHateRace == attacker.race )
{
f0 = ( f0 + SetHateRaceRatio );
}
f0 = ( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) ) );
AddAttackDesire(attacker,1,( f0 * 100 ));
}
if( IsNullCreature(myself.top_desire_target) == 0 )
{
if( GetPathfindFailCount() > 10 && attacker == myself.top_desire_target && FloatToInt(myself.sm.c_ai2) != FloatToInt(myself.sm.max_hp) )
{
InstantTeleport(myself.sm,FloatToInt(attacker.x),F loatToInt(attacker.creature),FloatToInt(attacker.z ));
}
if( GetAbnormalLevel(myself.sm,Skill_GetAbnormalType(3 07457)) >= 0 && DistFromMe(myself.top_desire_target) > 40 )
{
if( CanAttack(myself.top_desire_target) == 1 )
{
if( attacker.is_pc != 0 || IsInCategory(11,attacker.npc_class_id) )
{
f0 = 0;
if( SetHateGroup >= 0 )
{
if( IsInCategory(SetHateGroup,attacker.occupation) )
{
f0 = ( f0 + SetHateGroupRatio );
}
}
if( attacker.occupation == SetHateOccupation )
{
f0 = ( f0 + SetHateOccupationRatio );
}
if( SetHateRace == attacker.race )
{
f0 = ( f0 + SetHateRaceRatio );
}
f0 = ( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) ) );
AddAttackDesire(attacker,1,( f0 * 100 ));
}
}
else
{
RemoveAttackDesire(myself.top_desire_target.id);
if( attacker.is_pc != 0 || IsInCategory(11,attacker.npc_class_id) )
{
f0 = 0;
if( SetHateGroup >= 0 )
{
if( IsInCategory(SetHateGroup,attacker.occupation) )
{
f0 = ( f0 + SetHateGroupRatio );
}
}
if( attacker.occupation == SetHateOccupation )
{
f0 = ( f0 + SetHateOccupationRatio );
}
if( SetHateRace == attacker.race )
{
f0 = ( f0 + SetHateRaceRatio );
}
f0 = ( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) ) );
AddAttackDesire(attacker,1,( f0 * 100 ));
}
}
}
}
super;
}
EventHandler CLAN_ATTACKED(attacker,damage,f0)
{
if( GetLifeTime() > 7 )
{
if( IsNullCreature(myself.top_desire_target) == 0 )
{
if( GetPathfindFailCount() > 10 && attacker == myself.top_desire_target && FloatToInt(myself.sm.hp) != FloatToInt(myself.sm.max_hp) )
{
InstantTeleport(myself.sm,FloatToInt(attacker.x),F loatToInt(attacker.creature),FloatToInt(attacker.z ));
}
}
if( attacker.is_pc != 0 || IsInCategory(11,attacker.npc_class_id) )
{
f0 = 0;
if( SetHateGroup >= 0 )
{
if( IsInCategory(SetHateGroup,attacker.occupation) )
{
f0 = ( f0 + SetHateGroupRatio );
}
}
if( attacker.occupation == SetHateOccupation )
{
f0 = ( f0 + SetHateOccupationRatio );
}
if( SetHateRace == attacker.race )
{
f0 = ( f0 + SetHateRaceRatio );
}
f0 = ( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) ) );
AddAttackDesire(attacker,1,( f0 * 30 ));
}
}
}
EventHandler SEE_SPELL(speller,skill_name_id,target,f0,i0)
{
if( Skill_GetEffectPoint(skill_name_id) > 0 )
{
if( myself.p_state == 3 && myself.top_desire_target == target )
{
i0 = Skill_GetEffectPoint(skill_name_id);
f0 = 0;
if( SetHateGroup >= 0 )
{
if( IsInCategory(SetHateGroup,speller.occupation) )
{
f0 = ( f0 + SetHateGroupRatio );
}
}
if( speller.occupation == SetHateOccupation )
{
f0 = ( f0 + SetHateOccupationRatio );
}
if( SetHateRace == speller.race )
{
f0 = ( f0 + SetHateRaceRatio );
}
f0 = ( ( ( 1.000000 * i0 ) / ( myself.sm.level + 7 ) ) + ( ( f0 / 100 ) * ( ( 1.000000 * i0 ) / ( myself.sm.level + 7 ) ) ) );
AddAttackDesire(speller,1,( f0 * 150 ));
}
}
if( GetPathfindFailCount() > 10 && speller == myself.top_desire_target && FloatToInt(myself.sm.hp) != FloatToInt(myself.sm.max_hp) )
{
InstantTeleport(myself.sm,FloatToInt(speller.x),Fl oatToInt(speller.y),FloatToInt(speller.z));
}
}
EventHandler DESIRE_MANIPULATION(speller,desire)
{
MakeAttackEvent(speller,desire,0);
}
EventHandler MY_DYING()
{
if( ShoutMsg4 > 0 && Rand(100) < 30 )
{
Shout(MakeFString(ShoutMsg4,"","","","",""));
}
}
}
/************************************************** *************************
* C4 stuff
* ------------------
* -----------
* FUNCTIONS:
* -----------
* IsNullCreature
* GetPathfindFailCount
* CanAttack
************************************************** *************************/
/************************************************** *************************
* Change Log
* ------------------
* xx.xx.2006
* Script Decompiled by SauDecompiler build 160706.1
*
************************************************** *************************/
class warrior_casting_ddmagic : warrior
{
parameter:
int DDMagic = 1024257;
handler:
EventHandler CREATED()
{
myself.i_ai1 = 0;
myself.i_ai2 = 0;
super;
}
EventHandler ATTACKED(attacker,damage,i6)
{
if( myself.i_ai1 == 1 )
{
if( myself.top_desire_target == attacker )
{
myself.i_ai2 = 1;
}
}
else
{
AddTimerEx(2001,5000);
myself.i_ai1 = 1;
}
if( attacker.is_pc != 0 || IsInCategory(11,attacker.npc_class_id) )
{
i6 = Rand(100);
if( DistFromMe(attacker) > 100 )
{
if( IsNullCreature(myself.top_desire_target) == 0 )
{
if( myself.top_desire_target == attacker && i6 < 33 )
{
if( Skill_GetConsumeMP(DDMagic) < myself.sm.c_ai3 && Skill_GetConsumeHP(DDMagic) < myself.sm.c_ai2 && Skill_InReuseDelay(DDMagic) == 0 )
{
AddUseSkillDesire(attacker,DDMagic,0,1,1000000);
}
}
}
}
}
super;
}
EventHandler CLAN_ATTACKED(attacker,damage,i6)
{
if( ( GetLifeTime() > 7 && ( attacker.is_pc != 0 || IsInCategory(11,attacker.npc_class_id) ) ) && myself.p_state != 3 )
{
i6 = Rand(100);
if( DistFromMe(attacker) > 100 && i6 < 33 )
{
if( Skill_GetConsumeMP(DDMagic) < myself.sm.mp && Skill_GetConsumeHP(DDMagic) < myself.sm.hp && Skill_InReuseDelay(DDMagic) == 0 )
{
AddUseSkillDesire(attacker,DDMagic,0,1,1000000);
}
}
}
super;
}
EventHandler TIMER_FIRED_EX(timer_id)
{
if( timer_id == 2001 )
{
if( myself.p_state != 3 && myself.p_state != 10 )
{
myself.i_ai1 = 0;
myself.i_ai2 = 0;
}
else if( myself.i_ai2 == 0 )
{
if( IsNullCreature(myself.top_desire_target) == 0 && Rand(100) < 50 )
{
if( GetAbnormalLevel(myself.top_desire_target,Skill_Ge tAbnormalType(DDMagic)) <= 0 )
{
if( Skill_GetConsumeMP(DDMagic) < myself.sm.c_ai3 && Skill_GetConsumeHP(DDMagic) < myself.sm.c_ai2 && Skill_InReuseDelay(DDMagic) == 0 )
{
AddUseSkillDesire(myself.top_desire_target,DDMagic ,0,1,1000000);
}
}
}
}
AddTimerEx(2001,5000);
myself.i_ai2 = 0;
}
super;
}
}
/************************************************** *************************
* C4 stuff
* ------------------
* -----------
* FUNCTIONS:
* -----------
* IsNullCreature
************************************************** *************************/
/************************************************** *************************
* Change Log
* ------------------
* xx.xx.2006
* Script Decompiled by SauDecompiler build 160706.1
*
************************************************** *************************/
class warrior_casting_curse : warrior
{
parameter:
int DeBuff = 1033473;
handler:
EventHandler CREATED()
{
myself.i_ai1 = 0;
myself.i_ai2 = 0;
super;
}
EventHandler ATTACKED(attacker,damage)
{
if( myself.i_ai1 == 1 )
{
if( myself.top_desire_target == attacker )
{
myself.i_ai2 = 1;
}
}
else
{
AddTimerEx(2001,5000);
myself.i_ai1 = 1;
}
if( attacker.is_pc != 0 || IsInCategory(11,attacker.npc_class_id) )
{
if( IsNullCreature(myself.top_desire_target) == 0 )
{
if( Rand(100) < 33 && GetAbnormalLevel(attacker,Skill_GetAbnormalType(De Buff)) <= 0 && myself.top_desire_target == attacker )
{
if( Skill_GetConsumeMP(DeBuff) < myself.sm.c_ai3 && Skill_GetConsumeHP(DeBuff) < myself.sm.c_ai2 && Skill_InReuseDelay(DeBuff) == 0 )
{
AddUseSkillDesire(attacker,DeBuff,0,1,1000000);
}
}
}
}
super;
}
EventHandler CLAN_ATTACKED(attacker,damage)
{
if( GetLifeTime() > 7 && ( attacker.is_pc != 0 || IsInCategory(11,attacker.npc_class_id) ) )
{
if( Rand(100) < 33 && GetAbnormalLevel(attacker,Skill_GetAbnormalType(De Buff)) <= 0 )
{
if( Skill_GetConsumeMP(DeBuff) < myself.sm.mp && Skill_GetConsumeHP(DeBuff) < myself.sm.hp && Skill_InReuseDelay(DeBuff) == 0 )
{
AddUseSkillDesire(attacker,DeBuff,0,1,1000000);
}
}
}
super;
}
EventHandler TIMER_FIRED_EX(timer_id)
{
if( timer_id == 2001 )
{
if( myself.p_state != 3 && myself.p_state != 10 )
{
myself.i_ai1 = 0;
myself.i_ai2 = 0;
}
else if( myself.i_ai2 == 0 )
{
if( IsNullCreature(myself.top_desire_target) == 0 && Rand(100) < 50 )
{
if( GetAbnormalLevel(myself.top_desire_target,Skill_Ge tAbnormalType(DeBuff)) <= 0 )
{
if( Skill_GetConsumeMP(DeBuff) < myself.sm.c_ai3 && Skill_GetConsumeHP(DeBuff) < myself.sm.c_ai2 && Skill_InReuseDelay(DeBuff) == 0 )
{
AddUseSkillDesire(myself.top_desire_target,DeBuff, 0,1,1000000);
}
}
}
}
AddTimerEx(2001,5000);
myself.i_ai2 = 0;
}
super;
}
}
/************************************************** *************************
* C4 stuff
* ------------------
* -----------
* FUNCTIONS:
* -----------
* IsNullCreature
************************************************** *************************/
/************************************************** *************************
* Change Log
* ------------------
* xx.xx.2006
* Script Decompiled by SauDecompiler build 160706.1
*
************************************************** *************************/
class warrior_physicalspecial : warrior
{
parameter:
int PhysicalSpecial = 1032193;
handler:
EventHandler ATTACKED(attacker,damage)
{
if( attacker.is_pc != 0 || IsInCategory(11,attacker.npc_class_id) )
{
if( IsNullCreature(myself.top_desire_target) == 0 )
{
if( Rand(100) < 33 && myself.top_desire_target == attacker )
{
if( Skill_GetConsumeMP(PhysicalSpecial) < myself.sm.c_ai3 && Skill_GetConsumeHP(PhysicalSpecial) < myself.sm.c_ai2 && Skill_InReuseDelay(PhysicalSpecial) == 0 )
{
AddUseSkillDesire(attacker,PhysicalSpecial,0,1,100 0000);
}
}
}
}
super;
}
EventHandler CLAN_ATTACKED(attacker,damage)
{
if( ( GetLifeTime() > 7 && ( attacker.is_pc != 0 || IsInCategory(11,attacker.npc_class_id) ) ) && myself.p_state != 3 )
{
if( Rand(100) < 33 )
{
if( Skill_GetConsumeMP(PhysicalSpecial) < myself.sm.mp && Skill_GetConsumeHP(PhysicalSpecial) < myself.sm.hp && Skill_InReuseDelay(PhysicalSpecial) == 0 )
{
AddUseSkillDesire(attacker,PhysicalSpecial,0,1,100 0000);
}
}
}
super;
}
}
/************************************************** *************************
* C4 stuff
* ------------------
* -----------
* FUNCTIONS:
* -----------
* IsNullCreature
************************************************** *************************/
Вложения из исходного сообщения (сами файлы в копии отсутствуют):
ai_boss04_antaras_208.rar — 3232 байт
empathon
18.07.2006, 08:54
thanks a lot! very usefull staff :D
btw. GetPathfindFailCount its for pathnode function?
i saw how its work on retail and im 100% sure that way where mob or player goes is in patchnode. I dont know AI as well as u, is there any function in C1 AI equal to that?
Aikeleer
18.07.2006, 09:19
This is a function in the AI that is against perching. If the mob is stuck, and it can't get to it's waypoint (which is set in the pathnode) the failpathnodecount increases. If it reaches 10, the mob just teleports to you.
empathon
18.07.2006, 10:23
sa can i relay this function like that:
if (disttance to mob not become smaller in some period of time) then (teleport to player)
??
now i have to find out how to write it in NASC im noob in this :P
midnight
18.07.2006, 10:41
When i load the ai class warrior : warrior_parameter , ingame monsters says farewell and npcserver crashes
sa can i relay this function like that:
if (disttance to mob not become smaller in some period of time) then (teleport to player)
??
now i have to find out how to write it in NASC im noob in this :P
what happen if the player runs away? you have to check, if the npc is under attack, is free of root/sleep/etc, position (x,y,z), and if you want distance.
empathon
18.07.2006, 15:37
yeah i didnt thought about it. thanks for a tip :)
and i dont understand this one
(IsNullCreature(myself.top_desire_target) == 0)
so mob can have on target not PC or what ?
Sauron how to check in ai when mob is free of root/sleep/etc ?
Can u show me good way only ?