Will this work?

Post your scripting questions / solutions here

Moderator: Moderators

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

Will this work?

Post by Alcoholic »

im trying to make my script work so that other ai will runto the leader if he gets too far away. i looked in g_allclasses and i made a guess at how i should do it. will this script work?

Code: Select all

main:

	exec global/ai.scr
	exec global/friendly.scr
	exec global/loadout.scr maps/test_alliedraid.scr // i have no idea why this is here. i just put it here cuz i see it in other scripts.

level waittill prespawn

	level.captain = level.friendly1
	level.medic = level.friendly5
	
	level.medic exec globa/disable_ai.scr // BTW- my medic STILL DOESNT HEAL!! ARGHHH
	
	level.script = maps/test_alliedraid.scr

level waittill spawn
	
	$player item weapons/bar.tik
	$player item weapons/colt45.tik
	$player ammo mg 200
	$player ammo pistol 70
	$player useweaponclass mg
	$player item weapons/m2frag_grenade.tik
	$player ammo grenade 4

//Threads
thread friendlysetup
thread followtheleader
level.friendly2 thread friendly2followleader
level.friendly3 thread friendly3followleader
level.friendly4 thread friendly4followleader
end

friendly2followleader:

	while (isalive level.friendly2)
	{
		if (isalive level.captain)
		{
			if (vector_within level.friendly2 level.captain 128 == 0)
			{
				wait 2
				self runto level.captain
			}
		}
	}
	end

friendly3followleader:

	while (isalive level.friendly3)
	{
		if (isalive level.captain)
		{
			if (vector_within level.friendly3 level.captain 128 == 0)
			{
				wait 2
				self runto level.captain
			}
		}
	}
	end
	
friendly4followleader:

	while (isalive level.friendly4)
	{
		if (isalive level.captain)
		{
			if (vector_within level.friendly4 level.captain 128 == 0)
			{
				wait 2
				self runto level.captain
			}
		}
	}
	end
	


friendlysetup:

	level.captain thread global/friendly.scr::friendlythink
	level.friendly2 thread global/friendly.scr::friendlythink
	level.friendly3 thread global/friendly.scr::friendlythink
	level.friendly4 thread global/friendly.scr::friendlythink
	level.medic thread global/friendly.scr::friendlythink

	level.captain.friendtype = 4
	level.friendly2.friendtype = 0
	level.friendly3.friendtype = 0
	level.friendly4.friendtype = 0
	level.medic.friendtype = 5
	
	level.captain.avoidplayer = 0
	level.friendly2.avoidplayer = 0
	level.friendly3.avoidplayer = 0
	level.friendly4.avoidplayer = 0
	level.medic.avoidplayer = 0

	level.captain.health = 1000
	level.friendly2.health = 1000
	level.friendly3.health = 1000
	level.friendly4.health = 1000
	level.medic.health = 1000
	
	level.friendly2.mins = 128
	level.friendly2.maxs = 512
	
	level.friendly3.mins = 128
	level.friendly3.maxs = 512
	
	level.friendly4.mins = 128
	level.friendly4.maxs = 512
	
	level.medic.mins = 128
	level.medic.maxs = 512

/*  level.friendly2.destination = level.captain
	level.friendly3.destination = level.captain
	level.friendly4.destination = level.captain
	level.medic.destination = level.captain */
	
	level.captain thread deathleader
	level.friendly2 thread deathfriend2
	level.friendly3 thread deathfriend3
	level.friendly4 thread deathfriend4
	level.medic thread deathmedic
	end

deathleader:
	
	self waittill death
	iprintlnbold "Captain Smith has been killed in action. You are the new leader."
	thread newleader
	end

deathfriend2:

	self waittill death
	iprintlnbold "Private Duncan has been killed in action."
	end

deathfriend3:

	self waittill death
	iprintlnbold "Private Jordan has been killed in action."
	end

deathfriend4:

	self waittill death
	iprintlnbold "Sharpshooter Jones has been killed in action."
	end

deathmedic:

	self waittill death
	iprintlnbold "Medic Henry has been killed in action."
	end

newleader:

	iprintlnbold "The Captain has died. You are the new leader."
	thread newleadersetup
	end

newleadersetup:
	
	level.friendly2.mins = -128
	level.friendly2.maxs = -512
	
	level.friendly3.mins = -128
	level.friendly3.maxs = -512
	
	level.friendly4.mins = -128
	level.friendly4.maxs = -512
	end
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

I see a number of problems with your script, although it's nice to see such a sophisticated attempt :).

First I wonder why you are using both friendly.scr with friendtype 0 (follow the player) and then use the friendlyxfollwoleader threads to make them run to the captain. I expect to rapidly run between you and the captain. So, why not miss out the friendly.scr completely (except for the medic maybe). :?

Here's the list of errors in your script :wink: :

exec global/ai.scr
exec global/friendly.scr
exec global/loadout.scr maps/test_alliedraid.scr // i have no idea why this is here. i just put it here cuz i see it in other scripts.

None of these are allowed above level waittill prespawn, so move them below. exec global/ai.scr and exec global/loadout.scr won't do a thing in your map, best omit these lines (never add lines if you don't know what they do ;)).

level.medic exec globa/disable_ai.scr

should be

level.medic exec global/disable_ai.scr

or

level.medic.enableEnemy = 0

Code: Select all

   while (isalive level.friendly2)
   {
      if (isalive level.captain)
      {
         if (vector_within level.friendly2 level.captain 128 == 0)
         {
            wait 2
            self runto level.captain
         }
      }
   }
end 
This code will make your script crash back to the main menu, since this is an 'infinite loop', which mohaa doesn't like. Always add a wait or waitframe within the while. To improve performance it's a good idea to terminate the while loop if the captain is dead, since he will never be alive again. Also be aware that 'runto' actually means 'keep running to', so the guy will still run to the captain even is he is within the 128 unit radius. Type 'runto NULL' to stop him. Finally the line statement

vector_within level.friendly2 level.captain 128

is wrong, since you need to specify two vectors:

vector_within level.friendly2.origin level.captain.origin 128

This is what the follow code could look like:

Code: Select all

while (isalive level.friendly2)
{
  if (isalive level.captain)
  {
     if (vector_within level.friendly2.origin level.captain.origin 128 == 0)
     {
        self runto level.captain
        wait 1
     }
     else
     	self runto NULL
  }
  else
  {
  	self runto NULL
  	break
  }
  waitframe
}
or, in which case you would only need one thread:

Code: Select all

while(isAlive self && isAlive level.captain)
{
	if !(vector_within self.origin level.captain.origin 128)
		self runto level.captain
	else
		self runto NULL
	
	wait 0.1
}
if(isAlive self)
	self runto NULL
The rest of your code looks quite ok, except the thread followtheleader is missing.
Image
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

cool thankx it makes alot more sense now
Post Reply