Page 1 of 1

Casters and Statics or LOS

Posted: Fri Sep 26, 2008 8:53 am
by Breg
Having trouble with npc casters casting through Mountains and fences, If someone could give me the specific directories to edit or code to tweak it'd be appreciated I've looked and it stumped me.

Re: Casters and Statics or LOS

Posted: Fri Sep 26, 2008 12:53 pm
by *Edwards
First I would suggest you to look in your npcdesc.cfg found in distro/config for your npc description. Then you'll find a script attached to your NPC that you may probably find in distro/scripts/ai. The just open the file and add a check when it calls the function for casting.

Something like:

Code: Select all

If( CheckLineOfSight( npc, victim ))
      CallYourFunctionHere();
endif

Re: Casters and Statics or LOS

Posted: Fri Sep 26, 2008 6:16 pm
by Breg
Okay so none of my Ai Scripts call for this code and I would definately like to try it out, where would I insert in a script such as this?

Ai For Undead Spellcasters

Code: Select all

use os;
use uo;
use npc;
use util;
use cfgfile;

include "../pkg/npcs/main_ai/setup/setup";
include "include/attributes";
include "../pkg/npcs/main_ai/main/mainloop_killpcs_normal";
include "../pkg/npcs/main_ai/main/sleepmode_normal";
include "../pkg/npcs/main_ai/combat/fightmode_normal";
include "../pkg/npcs/main_ai/combat/closedistance_spellcaster";
include "../pkg/npcs/main_ai/combat/changeopponent_default";
include "../pkg/npcs/hostiles/undead/undead";
include "../pkg/npcs/npc_util";

const HALT_THRESHOLD := 13; // how close before he attacks?
drop_anchor();

program KillPlayers()
	if (!me.backpack)
		DoOnCreationSetup();
	endif
	DoStartupSetup();

	if (GetObjProperty(me, "frozen"))
		me.frozen := 1;
	endif

	post_combat();
	main_AI_loop();
endprogram

function process_combat_event(byref ev)

	SpellAttack(ev.source);

	case (ev.type)
		EVID_DAMAGED:
			if ( GetHp(me) < (GetStrength(me)/2))
				sleep(1);
				CastSpell(me, me,":misc_spells:gheal");
				if( me.poisoned )
					CastSpell(me, me, ":poison_spells:cure");
					CastSpell(me, ev.source, ":poison_spells:poison");
				endif
			endif
	endcase
endfunction

function SpellAttack(byref opponent)

	if (!GetObjProperty(me,"#lastspell"))
		SetObjProperty(me,"#lastspell",ReadGameClock() + 2);
	endif

	if (GetObjProperty(me,"#lastspell") > ReadGameClock() )
		return;
	endif

	if (RandomInt(3))
		sleep(1);
		cast_offensive_spell(me,opponent);
		SetObjProperty(me,"#lastspell",ReadGameClock() + 4);
	endif

endfunction

function in_combat_event_loop(byref opponent)

	if (!CheckLosAt(me, opponent.x, opponent.y, opponent.z))
	   look_around();

else
	SpellAttack(opponent);
	endif
endfunction

function prepare_for_fight(byref opponent)
	if (!GetObjProperty(me, "mr"))
		CastSpell(me,me,":misc_spells:reflect");
	endif

	DisableMainEvents();
	EnableCombatEvents();
endfunction

function post_combat()
	if ( GetHp(me) < (GetStrength(me)/2))
		CastSpell(me,me,":misc_spells:gheal");
	endif

	DisableCombatEvents();
	EnableMainEvents();

	SetWarMode( 0 );
	sleep(1);
	look_around();
endfunction

Re: Casters and Statics or LOS

Posted: Sat Sep 27, 2008 4:25 pm
by CWO
you need to check more than just the src. You need to check the include files too. Since a LOS check would logically be in the main loop and/or a fighting loop, you might want to check the include files that seem to be named appropriately...

include "../pkg/npcs/main_ai/main/mainloop_killpcs_normal";
include "../pkg/npcs/main_ai/combat/fightmode_normal";

Re: Casters and Statics or LOS

Posted: Tue Feb 03, 2009 1:15 am
by cucciola3000
The problem was that LOS return True....