npc ai problem

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
az_rieil
New User
Posts: 11
Joined: Tue Jan 24, 2017 1:46 am

npc ai problem

Post by az_rieil »

how i can move npcs but still react to events?
is there some way to handle several scripts to npc or use parallel streams for different actions like moving/fighting
az_rieil
New User
Posts: 11
Joined: Tue Jan 24, 2017 1:46 am

Re: npc ai problem

Post by az_rieil »

no ideas? :c
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: npc ai problem

Post by RusseL »

AI script is event catcher.
You can start as many parallel script as you want, and send those events to AI.
Where is the problem?
az_rieil
New User
Posts: 11
Joined: Tue Jan 24, 2017 1:46 am

Re: npc ai problem

Post by az_rieil »

ok, lets imagine
speech event cheks 2 command:
"move forward 100 steps"
"stop moving"

i said first command and AI script start the cycle
for i=0;i<100;i++ moveforward blablabla

while 50-th step is on, i say "stop moving" and expect that moving is stops ( by changing props or something another way to check ). but my script still execute step's cycle and command will be ignored
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: npc ai problem

Post by RusseL »

so, catch for events inside of your moving loop :)

for i=0;i<100;i++
stepforward
checkforevents (wait sleep makeapizza drinkabeer)
endfor

ps. you can also perform moving inside of main loop.
while waitforevent(1)
if (needs_to_be_moved)
stepforward
needs_to_be_moved:=false
endif
chackforevents
endwhile
az_rieil
New User
Posts: 11
Joined: Tue Jan 24, 2017 1:46 am

Re: npc ai problem

Post by az_rieil »

I'll try, but same method provide a big load for sever. if i want to hide delay between steps, i need to repeat main cycle near 10 times at second. and this is ony one npc. i not sure that it a good decision
az_rieil
New User
Posts: 11
Joined: Tue Jan 24, 2017 1:46 am

Re: npc ai problem

Post by az_rieil »

testing shows that near 150 npcs with 2 two enabled events and similar functionality and delat beetwen cycle as 50ms increasing sysload from 3-5 to 25-35.
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: npc ai problem

Post by RusseL »

when entering e.g. a Fight Mode you can start parallel running scripts with start_script
NightOwl
New User
Posts: 12
Joined: Mon Oct 01, 2012 11:21 am
Location: Russia
Contact:

Re: npc ai problem

Post by NightOwl »

az_rieil wrote: Sat Feb 18, 2017 5:23 am how i can move npcs but still react to events?
is there some way to handle several scripts to npc or use parallel streams for different actions like moving/fighting


Look at this script.
pol 099 x64 SystemAi ver 1.3 beta.rar
(75.59 KiB) Downloaded 227 times
Message translated with help of Google translator.
NightOwl
New User
Posts: 12
Joined: Mon Oct 01, 2012 11:21 am
Location: Russia
Contact:

Re: npc ai problem

Post by NightOwl »

Found an error.
This is a new feature.

Code: Select all

function AiStop(byref npc,byref prop,byref index,byref poltime)
var commands	:= prop.instruction[index].commands;
var flag	:= Cint(prop.instruction[index].flag);
var id		:= 0;

prop.instruction.erase(index);
	foreach command in commands
		id		:= AiGetIndexByCommand(prop,command);
		if(id)
			Print("Stop command: " + command + " out_event: " + prop.instruction[id].out_event + " out_quest: " + prop.instruction[id].out_quest + "mobiles: " + prop.mobiles.size() + " flag: " + flag);
			Case(command)
			"attack":		SetWarMode(0);
			endcase



	if((flag or prop.mobiles.size()) and prop.instruction[id].out_event)
		MSendProcEvent(struct{type := SYSEVENT_UPDATE,source := struct{key := "check_event",who := npc,sid := poltime,template := MGetNpcTemplateByPatch(npc.npctemplate),id := MGetNpcId(npc),realm := Lower(MGetNpcrealm(npc)),region := Lower(MGetNpcRegion(npc)),event_name := prop.instruction[id].out_event,quest_name := prop.instruction[id].out_quest}},MGetNpcProcGroup(npc),MGetNpcProcName(npc),Lower(MGetNpcrealm(npc) + ":" + MGetNpcRegion(npc)),SystemFindObjectBySerial(MGetNpcSpawner(npc)));
				

	endif
		prop.instruction.erase(id);
		endif
endforeach
		
		prop.idletime		:= prop.maxidletime + 1;

return 0;
endfunction
Translated by google translator.
NightOwl
New User
Posts: 12
Joined: Mon Oct 01, 2012 11:21 am
Location: Russia
Contact:

Re: npc ai problem

Post by NightOwl »

In components to a subject. Whether it is possible to add in the future to a kernel a system event which would occur when NPS would meet on the way of other NPS or the player?
Because SYSEVENT_ENTEREDAREA occurs, current when someone enters the NPS area and if NPS itself Meets Someone on the way that doesn't occur and on it it is necessary to scan periodically terrain to find somebody, and it is load of the server.


Message translated by an electronic translator.
Post Reply