SphereCommunity
attacker question - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: attacker question (/Thread-attacker-question)



attacker question - Rizz - 05-21-2015 10:18 AM

Is correct something like that?

FOR X 0 <eval <attacker>-1>
IF (<attacker.<dLOCAL.X>.isnpc>)
attacker.<dLOCAL.X>.remove
ENDIF

ENDFOR

Or is better to achieve the uid and remove it from the attackers list OUTSIDE the for cycle to prevent some problems with the amount of attackers?


RE: attacker question - XuN - 05-21-2015 06:03 PM

Depends on the situation, if you are going to prevent npcs to joining this list or if you want to remove an specific uid in certain cases...

When you are looping on something you are going to decrease it's better to do a reversed loop because if you remove 2 attackers in the loop when you reach 2 last cycles it will throw error:

Code:
for x <eval <attacker>-1> 0
IF (<attacker.<dLOCAL.X>.isnpc>)
  attacker.<dLOCAL.X>.remove
endif
endfor

You can alternatively remove an uid with some previous check: attacker.delete <uid>

Code:
ON=@HitTry
if (<src.npc>)
attacker.delete <src>
return 1
endif

Or you can alternatively just block it's inserction on the list:

Code:
ON=@CombatAdd // this will force npc (if you are using the trigger on an npc to try to add it again in the next tick)
if (<src.npc>)
return 1
endif

Altought I don't know what do you want ... if you just want NPCs to not be attacked the very best method is to ignore them so Sphere won't try to add them each time it should, hence less code will be run:

Code:
ON=@CombatAdd
if (<src.npc>)
argn2=1
endif



RE: attacker question - Rizz - 05-21-2015 07:53 PM

I am experiencing that the target system works great within players but it's not working well with NPC (most of time the target switch between more NPCs).
So the idea is to keep only one NPC in the attackers list and remove this one if i decide to attack a different one.

I am not sure if this is a problem related to sphere or to the scrips, I just would like to check and see what happen.


RE: attacker question - XuN - 05-21-2015 08:26 PM

NPCs have the same way to check who is going to be their next target:
local.threat = 0
local.dist = 65535

attacker is dead = skip
attacker is ignored = skip
if (action =ranged skill (archery/throwing..)
if ( distance < serv.archerymindist || distance > serv.archerymaxdist )
skip
endif
if ( attacker = current_target) // not sure why this one exists, may I remove it
skip
endif
endif
attacker dist > 14 = skip //max dist view (screen size)
!CanSeeLos attacker = skip

if (npcai & npc_ai_threat && attacker.threat > local.threat)
target = attacker
elseif ( dist < local.dist )
local.dist = <dist>
target = attacker
endif

Not using SphereScript 100% but enough to show you how does it work right now.

So if you are encountering problems, which may be related to this, just post here a better explanation of whats happening and under which circumstances.


RE: attacker question - Rizz - 05-22-2015 06:18 PM

The problem is related when a player attacks more than a one monster. Seems the players cannot stick on a single target but he attack based on range etc.
I use an attackers ignore script to avoid this environment and it works great in a combat between players but not with players and monsters mixed together or only monsters.
As I told you, I am not sure if this is a sphere fault or there are some lacks on my script...

That's why I would like to keep only one monster at time in the attackers list to check.