Multiple targets, same name

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Multiple targets, same name

Post by Alcoholic »

[self.mood=curious]ok i was really curious as to do this...[/mood]

lets say you want someone to shoot something, but there are three somethings all with the same name and in the same area. if someone wants to shoot a something, he is gonna see all 3 at once no matter what way he enters the area. my question is, how do you make him choose one and attack? i never worked with mp maps before, but i believed that if you had a tank fire at $player, it would go nuts, cuz there are like 30 players! any help would be appreciated.
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

create a random integer and then target it

shoot_clay_pot:
level.pot_number = randomint (3) //will return either 0, 1 or 2
switch (level.pot_number)
{
case 0:
$player shoot at $pot_0
etc...
}

or create them in an array
$player shoot at $pot[level.pot_number]

there's possibly an easier way cos, u'd also need stuff like
level.pot2 = 1 //when it's destroyed and therefore need to find a new target
hope this helps, prob not cos it's all foreign 2 me :-/
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

$player shoot at $pot[level.pot_number]

should be

$player shoot at $pot[(level.pot_number + 1)]

:P
Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

If you are going to use a randomint and one targetname for 3 targets you could do this

$player shootat $pot[(randomint($pot.size)+1)]
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

not if they're labelled pot 0, 1 and 2 :D

and is it's using case 0, adding 1 will skip that case...
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

targetname arrays start at 1 not 0 where for example randomint(4) will give you 0 1 2 3 which is 4 numbers the +1 is nessesary with random numbers and targetname arrays .
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

lol, i've never noticed that before, i only create arrays when they have about 8 objects in there, so i guess the 0th one will never work

but you could do a much more complicated thing than JV suggested by -1 from the array :D

i know, i know, it's a stupid idea, i just don't like being wrong :P
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

hmmm.. let me put it another way..

lets say you have a tank in multiplayer that shoots at any player it see's. how do you script the tank so it doesnt go nuts?
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

tanks have already been done, parts and JV sorted that one

a search will get you the details :D
hope this helps, prob not cos it's all foreign 2 me :-/
Desert Eagle
Captain
Posts: 237
Joined: Mon Jan 13, 2003 1:05 am
Location: Mapping Bunker
Contact:

Post by Desert Eagle »

I used this to target allied players, with a tiger tank. Did not work in TOW map though, worked okay in roundbased and objective. It would target axis players, but not shoot. Maybe it will help:

I created a tiger tank and give it a targetname of tiger1 and ran this thread $tiger1 thread target

//*** find an allied player near by to shoot at!
Target:

println ("looking for target")

//look for first player in range and shoot at them!

for (self.i = 1; self.i <= 32; self.i++)
{
if ($player[self.i])
{
if ($player[self.i].dmteam == allies)
{
if (vector_length (self.origin - $player[self.i].origin) > 200)
{
if (vector_length (self.origin - $player[self.i].origin) < 3000)
{
if (self cansee $player[self.i])
{
println ("targeting player #" + self.i)
self.gun setAimTarget $player[self.i]
self.gun waittill ontarget
self.gun anim fire
goto breakloop
}
else
{
println "can't see him!"
}
}
}
}
}
}
println "no target found"

breakloop:

wait 2
goto Target

end
Desert-Eagle
....The Eagle Has Landed...
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

thanks thats just what i needed to find out.
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

does goto target mean to loop the thread or something?
User avatar
mohaa_rox
Field Marshal
Posts: 2760
Joined: Mon Nov 11, 2002 7:05 am
Contact:

Post by mohaa_rox »

it's like a loop to go back to the same thread.
Live to map, not map to live.
-mohaa_rox, .map
moderator
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

lmao, i can see why rox has so many posts too :P

about the goto command, it's pretty much the same is thread, except it won't continue to run the thread after the goto, it's goes somewhere else

so you could use it to determine which thread will be selected

if (this_happens)
{goto it_did}
else
{it didn't}

but bear in mind that you'll get an over flow if you don't have pauses in there as Desert Eagle used wait 2 before it reloops the thread
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
mohaa_rox
Field Marshal
Posts: 2760
Joined: Mon Nov 11, 2002 7:05 am
Contact:

Post by mohaa_rox »

nuggets wrote:lmao, i can see why rox has so many posts too :P
cause i spam and repeat what ppl say :wink:
Live to map, not map to live.
-mohaa_rox, .map
moderator
Post Reply