Page 1 of 1

target low level by number idea

Posted: Tue Apr 17, 2007 5:18 pm
by fps
would it be possible to set a pawns target to equal the entynames of several pawns at once.
like this.

SetTarget(foe_(1-12))

i may need to use a right or left copy command in there some were i think, but if im right i can keep the pawn in low level.

i may even need to cycle the order constantly throughout the script but it would still save me a lot of wasted effort. can anyone confirm or deny my theory?


Thanks,
fps

Posted: Tue Apr 17, 2007 5:27 pm
by Juutis
Excellent idea!
Yes, you could get the enemies' names that way and then check if any of them is visible and then target that one.

Though I don't recommend doing the 'check' very often. If there are, say, 10 pawns each checking if there are enemies nearby like 10 times per second, things may get slow. Also, the pawn number in one level will be limited, but I don't think that's a major issue.

Anyway, Great thinking! :)

Posted: Tue Apr 17, 2007 5:48 pm
by fps
i am planning on having (for my test) friendly_1-10 and foe_1-10.
they need to attack each other accordingly. which way would you suggest i use. the check method. or the right copy in setup method?

Posted: Tue Apr 17, 2007 5:58 pm
by Juutis
I personally would do it like this:

Code: Select all

for enemynumber = 0 to 10
{
     if(IsEntityVsible("foe_" # enemynumber))
     {
          SetTarget("foe_" # enemynumber);
     }
}

Posted: Wed Apr 18, 2007 3:42 am
by revolutiongames2004
oo indifference

also visible is spelled wrong

Code: Select all

 if(IsEntityVsible("foe_" # enemynumber)) 

Posted: Wed Apr 18, 2007 9:51 am
by Juutis
revolutiongames2004 wrote: also visible is spelled wrong

Code: Select all

 if(IsEntityVsible("foe_" # enemynumber)) 
That's how it is in the manual. I just pasted it here. :wink:

Posted: Wed Apr 18, 2007 10:48 am
by QuestOfDreams
hm... seems to be spelled wrong in the source code too, so IsEntityVsible is the version that actually works...

Posted: Wed Apr 18, 2007 5:14 pm
by fps
thats nice to know. if they fix that in the next release it would mess up older scripts.

so the order should look somthing like this in the script.

{
Spawn[ ()
{
Console(true);
Ect(true);
LowLevel("Setup");
} ]

Setup[ ()
{
BlaBla = "bla";
self.think = "Idle";
} ]

Idle[ ()
{
idleactions
self.think = "AquireTargets"
}]

AquireTargets[ ()
{
self.ThinkTime = "0.2"; //what should this be set at?
for enemynumber = 0 to 10
{
if(IsEntityVsible("foe_" # enemynumber))
{
SetTarget("foe_" # enemynumber);
}
}]

rest of script
}


Will this check the visible pawns throughout the entire duration of the script or will i need to but it else were in the code also?
what do you think would happen if more than one pawn becomes visible while this is setting its target?
(i think i may have asked that elsewere :roll: )
would it work if the players entity name to friendly_1?

i think i will need to have it check for distance too but it may already do that in my full script.


i feel like im getting somewere with this finally,
thanks for the help,
fps

Posted: Wed Apr 18, 2007 7:08 pm
by Juutis
No, it wouldn't work the way you wrote it. You see, in the 'Idle' order you command the script to go to 'AquireTargets', but it doesn't come back to 'Idle'. So the script will only run the order 'AquireTargets' and do nothing else. I would recommend making this 'AquireTargets' a custom command (or something like that). I mean like this:

Code: Select all

 AquireTargets[ ()
{
for enemynumber = 0 to 10
{
if(IsEntityVsible("foe_" # enemynumber))
{
SetTarget("foe_" # enemynumber);
}
}] 
Then you could call this function from anywhere in the script. So whenever you would need to get a target, you would add line 'AquireTargets();' in the script. For example, if you wanted the pawn to check for new targets every 1 seconds while in 'Idle', you would add this to the 'Idle' order:

Code: Select all

if(FindTargetTimer < self.time)
{
AquireTargets();
FindTargetTimer = self.time + 1;
}
Where 'FindTargetTimer' is a variable which you need to define in the top of the script.


If there are multiple enemies visible at the same time, I believe the last one (the one with the biggest number) will be targeted.
Also, I would check for targets like every 1-2 seconds. In the end, it's up to you, though. Try different numbers and try to optimize it, so that it doesn't take too long for the pawns to find targets but it doesn't drop the framerate either.