If Distance/If Target Script

Post your scripting questions / solutions here

Moderator: Moderators

Broadus
Captain
Posts: 235
Joined: Mon Jan 30, 2006 5:35 am

If Distance/If Target Script

Post by Broadus »

I'm a very, very bad scripter, so I was wandering if maybe someone could give me the basis of a script like...
I've got some tanks that are on the same team as the player. When they get a certain distance away from the player, I want them to stop (self.driving = 0) so the player can catch up, or so the player can back up so that the friendlies can catch up with him.
I also want them to stop when they have a target (like real tanks had to stop when they wanted to shoot at something), but keep moving when they don't have a target.
Would these conflict with eachother?

Thanks for any help!
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

That should be possible... note that tanks by themselves don't have any target finding, so that'd have to be fully scripted.
Image
Broadus
Captain
Posts: 235
Joined: Mon Jan 30, 2006 5:35 am

Post by Broadus »

Well, I've already got a tank-targeting script that I just pulled out of t2l4.
So, any idea what the script would look like that makes the tank stop when it gets a certain distance from the player?
Image
Green Beret
Major General
Posts: 746
Joined: Mon Apr 19, 2004 12:21 pm
Contact:

Post by Green Beret »

local.tank.origin = $AI.origin + ( xxx )
Just a guess, Im no awsome scripter niether.
Kinda like how the avatar floats above your head on Freeze Tag?
Image
Broadus
Captain
Posts: 235
Joined: Mon Jan 30, 2006 5:35 am

Post by Broadus »

... Yeah, I have a feeling that making the origin of the tank the same as the origin of something else won't solve much of anything in this case.
Image
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

i believe a sighttrace would be the best. basically it's like drawing a straight line from point to point, and it returns false if it's out of range or somehting's in the way.

i dont have the g_dumpallclasses file anymore, but it should be in there.
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Sighttrace traces using a bounding box, m8. ;)
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Broadus
Captain
Posts: 235
Joined: Mon Jan 30, 2006 5:35 am

Post by Broadus »

So how do I make a sighttrace?
Image
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

there's a bunch of traces... i think theres a "trace" too... i dunno.
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
Broadus
Captain
Posts: 235
Joined: Mon Jan 30, 2006 5:35 am

Post by Broadus »

Then how do I just make it so that it stops at a certain distance?
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Depends. What is your current drive code?
Image
Broadus
Captain
Posts: 235
Joined: Mon Jan 30, 2006 5:35 am

Post by Broadus »

Well, it's... Not very complicated at the moment.
Basically:
$FFtank1 thread FFt1drive
. . .
FFt1drive:
self.driving = 1 (just in case?)
self drive $FFtank1path 5 10 100 256 //speed, accel/decel, closeness to nodes, looking ahead
self waittill drive
self stop
end
Image
Green Beret
Major General
Posts: 746
Joined: Mon Apr 19, 2004 12:21 pm
Contact:

Post by Green Beret »

Broadus wrote:... Yeah, I have a feeling that making the origin of the tank the same as the origin of something else won't solve much of anything in this case.
I didnt say make it the same origin, The + adds onto the origin
+ ( xxx xxx xxx )

But the sighttrace is the way to go, Have fun scripting that :P
Image
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

Code: Select all

local.tank.origin = $AI.origin + ( xyz ) 
sets the entity that local.tank refers to to the origin of $AI incremented by the amount in hte parens, so yes you'd be setting the tank right next to whatever AI is named that.

i asked about traces before and got a copy/paste code of it from bdb.

Code: Select all

local.player = $player
local.range = 1024
local.fwd_vec = angles_toforward local.player.viewangles 
local.start = local.player gettagposition "Bip01 Head" 
local.target.origin = trace (local.start + local.fwd_vec * 64) (local.start + local.fwd_vec * local.range ) 0  
in this case it draws a line straight from the player to either 1024 units ahead or until it hits a brush, in which case it returns coords to where the trace terminated.

but the tank would sort of be wallhacking, because it would need to look at the player it's entire existance to know when it can actually see the player.

makes you wish they just made tank AI built-in doesnt it?
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
Green Beret
Major General
Posts: 746
Joined: Mon Apr 19, 2004 12:21 pm
Contact:

Post by Green Beret »

Makes you wonder why they didnt, Itd be nice to have a tank go on a search and destroy mission, Then come in after the tank and clean up what is left :lol:
Image
Post Reply