Friendly AI Problem

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Otto
Lance Corporal
Posts: 16
Joined: Sat Apr 19, 2003 8:15 pm

Friendly AI Problem

Post 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
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post 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.
Image
User avatar
mohaa_rox
Field Marshal
Posts: 2760
Joined: Mon Nov 11, 2002 7:05 am
Contact:

Post 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.
Live to map, not map to live.
-mohaa_rox, .map
moderator
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post 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.
Image
User avatar
mohaa_rox
Field Marshal
Posts: 2760
Joined: Mon Nov 11, 2002 7:05 am
Contact:

Post 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:
Live to map, not map to live.
-mohaa_rox, .map
moderator
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

I'm only heating you a few degrees :twisted:
Image
Otto
Lance Corporal
Posts: 16
Joined: Sat Apr 19, 2003 8:15 pm

Post by Otto »

:D Thanks for your help. Much appreciated. It works a treat.

Cheers

Otto
Post Reply