How do I get a Allied AI to follow player?

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
grb
Warrant Officer
Posts: 136
Joined: Fri Jun 06, 2003 12:22 am
Location: USA Philadelphia

How do I get a Allied AI to follow player?

Post by grb »

Here is what I have in my main script file which concerns friendly/AI:

exec global/friendly.scr

main:
level waittill prespawn
fadein 2 0 0 0 1
wait 2
level.script = maps/test_grb1.scr
level.friendly1 thread global/friendly.scr::friendlythink
level.friendly1.friendtype = 1


I read the front end comments in the global/friendly.scr file, and the two
above lines are what it said to put into the main script file. Notice at this
point I have not added any min/max dist parameters etc.. I just want to
see if the AI character would even attempt to follow me.

OK. In the map, I surrounded the AI character ( ai_allied_1st-ranger_sergeant ) with info_pathnodes about 64 grids apart and extending for a couple hundred grid width.
The information I put in for the AI is:
target name friendly
testanim follow
#set 1 and of course the other stuff that gets assigned to the AI character such as angles blah, blah. I did not click any of the little boxes in the Entity Screen such as NO_STATION, detail etc.. So the Spawn Flag is still set to zero (0).
DO NOTICE THE KEY: #set VALUE 1. Now I also tried the stuff WITH NO SUCCESS when I entered KEY: set VALUE 1. So that is not an issue here.

Based on what I read in the global/friendly.scr this is basically all one should have to do, or so it seems to me.

But when I fire the map up, the sergeant will not follow me around.
The following is what I see in the console just after the map loads up:


level.friendly0 thread global/friendly.scr::friendlythink (maps/test_grb1.scr, 20)
level.friendly0 ^

^~^~^ Script Error: command 'thread' applied to NIL

level.friendly0.friendtype = 1 (maps/test_grb1.scr, 21)
level.friendly0^

^~^~^ Script Error: Cannot cast 'NIL' to listener


Now.................as I look in the global/friendly.scr file I do notice that there are reference to "NIL" in some IF STATEMENTS. For whatever that
is worth.

Any clues as to what I am doing wrong or not doing? OR IS IT AS USUAL,
A PROBLEM WITH RUNNING IN TEST MODE, AND THEREFORE NOT HAVING SCRIPT CODE PLACED INTO THE global/friendly.scr file etc., that references my particular map (test_grb1).
Let me qualify this question a bit. In the friendly.scr file there is a lot of code which is enclosed in IF statements that test for the STANDARD MOHAA MISSIONS, e.g. m4l1, m5l1 etc..

Now readers, the AI character is fully AI active, that is he will tell me to shoot at enemies, and he will move along the info_pathnodes I placed in the map IF I NUDGE HIM ALONG. So it is not an issue with not having info_pathnodes set close enought to him.

And finally, has anyone gotten AI characters to follow the player in Single Player MOHAA maps they built?

thanks for any help.... :?
grb
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

for your friendly Key:#fnum Value:1 . The pathnodes should be a max of 360 units apart . The leash value is how far they will wander away from a pathnode when not attacking . If an enemy is within the min distance ai will run away . If an enemy is outside the max distance the ai will run towards him . If you use test in front of your map name do not put your map in the dm directory . The directory is part of the map name so test_mymap.bsp will be dm/test_mymap.bsp which does not start with test but dm . I know you said it was a single player map but it should be said . Every thing goes after main: not before .
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

you dont need testanim follow. theres something you need to learn about scripting. the game execs this level script. by default, when you exec a script, the first "thread" it goes to is "main". you placed the exec before main, so it was never executed. to help you better understand, you executed the thread "friendlythink" later on... the "::friendlythink" means, "go to this script, but skip all the way to the thread friendlythink."
if you took off the ::friendlythink, the script would be fired from main. your exec friendly.scr isnt in main, so it was never called.


ALSO you did not give him any .mins or .maxs. you said you didnt because you want to see if he follows you. if he has no mins or maxs, how is he gonna follow you? he doenst know how close or how far to follow you.
grb
Warrant Officer
Posts: 136
Joined: Fri Jun 06, 2003 12:22 am
Location: USA Philadelphia

Got AI to follow but....

Post by grb »

Alcoholic and bdbodger,
Thanks for you help thus far. I changed the AI entity Key from #set to
#fnum.............as it is shown in the friendly.scr file, the only reason I had used #set was that it was not working originally and thought it might have
been a typo in the comment section of that file. At any rate.

The AI now follows me withing the constraints I put on leash, mindist,maxdist etc.. Works great! And he takes out enemies just fine.

The only problem remaining is for me to understand a bit more about correct scripting sequences. Shown immediately below is my script file
in it's entirety, followed by a chunck of the logfile showing some errors.
Can either of you guys tell me what I am not doing correctly in the script file at this point? I tried to put a "level waittill prespawn" in between each
exec global/blah..blah just to see if that would help but no apples, I still get the same error message as seen below in the logfile.

Thank you in advance for any further help you folks might give.


My Script File:
----------------------------------------

// test_grb1.scr
// By grb for map: test_grb1

main:
level waittill prespawn
fadein 2 0 0 0 1
wait 2
exec global/loadout.scr maps/test_grb1.scr

level.script = maps/test_grb1.scr
$player item weapons/silencedpistol.tik
$player item weapons/colt45.tik
$player item weapons/springfield.tik
$player item weapons/m1_garand.tik
$player item weapons/m2frag_grenade.tik
$player item weapons/thompsonsmg.tik
$player item weapons/bazooka.tik
$player item items/binoculars.tik
$player ammo rifle 200
$player ammo grenades 6
$player ammo pistol 200
$player ammo smg 200

exec global/ai.scr
exec global/ambient.scr
exec global/ambience.scr
exec global/friendly.scr

level.friendly1 thread global/friendly.scr::friendlythink
level.friendly1.friendtype = 1


//exec global/crouch.scr
//exec global/bomber.scr
//exec global/weather.scr
//exec global/exploder.scr
//exec global/ambient.scr m5l1b music
end

-----------------------------------------------------------
And the logfile:


cache models/weapons/bazooka.tik
^~^~^ Add the following line to the *_precache.scr map script:
cache models/items/binoculars.tik
level waittill prespawn (global/ai.scr, 154)
level ^

^~^~^ Script Error: invalid waittill prespawn for 'Level'

There are 0 friendlyspawners
Adding autosave names
level waittill spawn (global/ambient.scr, 5)
level ^

^~^~^ Script Error: invalid waittill spawn for 'Level'

Loading Ambient.scr
Spawned friendly 1
level waittill spawn (global/friendly.scr, 2332)
level ^

^~^~^ Script Error: invalid waittill spawn for 'Level'

There are 0 enemies
level waittill spawn (global/friendly.scr, 2111)
level ^

^~^~^ Script Error: invalid waittill spawn for 'Level'

-----------------------------------------

THESE ARE THE ONLY ERRORS I SEE REFERENCING THINGS FROM MY SCRIPT FILE, THE PLAYER RECEIVES ALL THE WEAPONS I ASK FOR PRIOR TO ANY ERRORS SHOWING UP.
grb
User avatar
mohaa_rox
Field Marshal
Posts: 2760
Joined: Mon Nov 11, 2002 7:05 am
Contact:

Post by mohaa_rox »

Here i come!!!!!

My Script File:
----------------------------------------

// test_grb1.scr
// By grb for map: test_grb1

main:
level waittill prespawn
fadein 2 0 0 0 1
wait 2
exec global/loadout.scr maps/test_grb1.scr

level.script = maps/test_grb1.scr

level waittill spawn

thread init_player
thread init_execs

init_player:
$player item weapons/silencedpistol.tik
$player item weapons/colt45.tik
$player item weapons/springfield.tik
$player item weapons/m1_garand.tik
$player item weapons/m2frag_grenade.tik
$player item weapons/thompsonsmg.tik
$player item weapons/bazooka.tik
$player item items/binoculars.tik
$player ammo rifle 200
$player ammo grenades 6
$player ammo pistol 200
$player ammo smg 200
end

init_execs:
exec global/ai.scr
exec global/ambient.scr test_grb1
exec global/friendly.scr
end

thread init_friendly

init_friendly:
if(isAlive level.friendly1) //check if he's dead
{
level.friendly1 thread global/friendly.scr::friendlythink
level.friendly1.friendtype = 1
level.friendly1.destination = $player
level.friendly1.distance = 128 //say 128?
}
end

//ur objectives and stuff here
Live to map, not map to live.
-mohaa_rox, .map
moderator
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

level waittill prespawn (global/ai.scr, 154)
level ^

^~^~^ Script Error: invalid waittill prespawn for 'Level'

this error was in the global/ai.scr ignore it same for the others like it has nothing to do with your script harmless

one other thing you have fadein 2 0 0 0 1
the default for the map is faded in you need to fadeout first before you fadein one use of this is , you fadeout then show writhing on the screen like " Dday charley sector december 1942 " . the writing is done by creating a .urc file and useing the command in your script
pushmenu mymenu
or whatever you called your menu in the .urc wait for a while then hidemenu mymenu then fadein
grb
Warrant Officer
Posts: 136
Joined: Fri Jun 06, 2003 12:22 am
Location: USA Philadelphia

bdbodger and mohaa_rox...

Post by grb »

bd,
Thanks for the information regarding use of "fadein/fadeout" and reason to ignore the seen Error messages concerning Level.

mohaa_rox,
Thanks for modifying my script file. It sure looks better organized. I shall modify the script file per your example. Your added code shows me some
new things I have not seen in the code thus far examined in this forum.
In short, I have barely scratched the surface concerning script coding for
mohaa.
Thanks guys.
grb
grb
Warrant Officer
Posts: 136
Joined: Fri Jun 06, 2003 12:22 am
Location: USA Philadelphia

thanks mohaa_rox....

Post by grb »

The script modifications you provided me work just fine. However, I needed to make one minor change. You placed the "thread init_friendly"
statement outside the main program. That is it was after the main's end
statement, so obviously it never ran. All I did to make it work was to move it into main just under the other thread ...blah statements.

Thanks again for the help.
grb
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

remember not only is there level waittill prespawn (wait for level to spawn). there is also level waittill spawn (wait for PLAYER to spawn). dont give player the weapons before you put level waittill spawn.
grb
Warrant Officer
Posts: 136
Joined: Fri Jun 06, 2003 12:22 am
Location: USA Philadelphia

roger Alcoholic....

Post by grb »

Understand. I just noticed that there also was no "end statement" to end the main script, in the modified version rox shared. I put one in, so now
all the threads which include the giving the player weapons wait until after the player is spawned into the game.

Thanks for that note. As an afternote, seems like jv_map pretty well spelled out how we should understand AI thinkstates. So much for being able to somehow change their state via. a script thread. Guess letting a script change a think state for a given AI could really play havoc with the engine when one thinks about it. No need to reply to this statement.
If you want to converse about these type of things I am open to email
dialogs. To much stuff can really clog up this forum in no time.
grb
Post Reply