Page 1 of 1

Friendly AI Problem

Posted: Mon May 12, 2003 8:13 pm
by Otto
Dear All

I've written a basic SP script with three objectives. It all works perfectly until the player meets up with a friendly 'prisoner' Miller. The friendly moves to the player and follows the player - no problem. But as soon as we encounter enemy AI and the firing starts the whole thing freezes and I get this error message

Script Error: Cannot cast 'NIL' to float
wait self.waittime (global/friendly.scr,1172)

Script Error: Cannot cast 'NIL' to float
while (iSalive self) (global/freindly.scr,228)

ERROR: Command overflow Possible infinite loop in thread

The full script is pasted below. Anyone got any ideas as to what I'm doing wrong?? Thanks in anticipation.

Regards

Otto


//test_sam


exec global/ai.scr
exec global/loadout.scr maps/test_sam.scr

level waittill prespawn
exec global/ambient.scr test_sam
level waittill spawn

main:

waitthread InitPlayer
waitthread InitFriends
waitthread InitObjectives
end

InitPlayer:

$player item weapons/m1_garand.tik
$player ammo rifle 24
$player useweaponclass rifle
fadein 2 0 0 0 1
wait 2

level.script = "maps/test_sam.scr"

end

InitFriends:

thread FriendWait
end

FriendWait:

$friend_trigger waittill trigger
$friendly.destination = $player
$friendly.friendtype = 1
$friendly.distance = 150
$friendly thread global/friendly.scr::friendlythink
end

InitObjectives:

waitthread global/objectives.scr::add_objectives 1 1 "Get the documents" $documents.origin
waitthread global/objectives.scr::add_objectives 2 1 "Rescue Miller" $miller.origin
waitthread global/objectives.scr::add_objectives 3 1 "Exit by back gate" $gate.origin

waitthread global/objectives.scr::add_objectives 1 2
waitthread global/objectives.scr::current_objectives 1

end

objective1:
$documents remove
goto objective

end

objective:
waitthread global/objectives.scr::add_objectives 1 3 "Get the documents" $documents.origin
waitthread global/objectives.scr::add_objectives 2 2
waitthread global/objectives.scr::current_objectives 2
end

objective2:
goto objectivenext

end

objectivenext:
waitthread global/objectives.scr::add_objectives 2 3 "Rescue Miller" $miller.origin
waitthread global/objectives.scr::add_objectives 3 2
waitthread global/objectives.scr::current_objectives 3

end


objective3:
goto levelend

end

levelend:
waitthread global/objectives.scr::add_objectives 3 3 "Exit by back gate" $gate.origin
waitthread global/objectives.scr::current_objectives 0

iprintln_noloc "Mission Complete!"
wait 1
exec global/missioncomplete.scr test_sam 1
end

Posted: Tue May 13, 2003 6:11 am
by jv_map

Code: Select all

FriendWait:

$friend_trigger waittill trigger
$friendly.destination = $player
$friendly.friendtype = 1
$friendly.distance = 150
$friendly thread global/friendly.scr::friendlythink
end 
should be

Code: Select all

FriendWait:

$friend_trigger waittill trigger
$friendly.waittime = 0.05 // one frame
$friendly.friendtype = 1
$friendly.distance = 150
$friendly thread global/friendly.scr::friendlythink
end 
It's kinda weird the friendly.scr has no protection for this though. If you notice the scripting overhead really slows down the game, it could be a good idea to increase the waittime.

Posted: Tue May 13, 2003 8:12 am
by mohaa_rox
This is even better:

$friendly thread global/friendly.scr::friendlythink
$friendly.friendtype = x
$friendly.distance = xxx
$friendly.destination = $player
//blah blah blah!
end

and use 1 2, 2 2, 3 2 for add objectives.

Posted: Tue May 13, 2003 8:23 am
by jv_map
mohaa_rox wrote:This is even better:

$friendly thread global/friendly.scr::friendlythink
$friendly.friendtype = x
$friendly.distance = xxx
$friendly.destination = $player
//blah blah blah!
end
Why would that be better? ;)

You forgot to set a waittime and that's what caused Otto's error. The .destination variable is overwritten by friendly.scr, so it really doesn't matter what you set there.

Posted: Tue May 13, 2003 9:23 am
by mohaa_rox
I mean, (don't flame me!!!!!), it's the same after all, that's the way i write it. :D :wink:

The waittime was for him to add. :P :wink:

Posted: Tue May 13, 2003 10:44 am
by jv_map
I'm only heating you a few degrees :twisted:

Posted: Sun May 18, 2003 8:10 am
by Otto
:D Thanks for your help. Much appreciated. It works a treat.

Cheers

Otto