Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 72 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 4
Category: CoD4 SP Mapping
CoD 4 mapping and level design for single player.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername, novemberdobby
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked
Page
Next Page
subscribe
Author Topic: allies dying
BlindSniper
General Member
Since: Aug 22, 2008
Posts: 45
Last: May 29, 2013
[view latest posts]
Level 2
Category: CoD4 SP Mapping
Posted: Wednesday, Feb. 17, 2010 05:21 pm
I've just started making sp maps and need a little help with the objectives.
I was wondering how to make it so if all of your allies die then you fail.
Also I want it to sort of count those that have been killed, e.g.
0/4 Allies died (on screen)
Share |
BlindSniper
General Member
Since: Aug 22, 2008
Posts: 45
Last: May 29, 2013
[view latest posts]
Level 2
Category: CoD4 SP Mapping
Posted: Wednesday, Feb. 24, 2010 07:23 pm
can anyone help me?
Share |
playername
Preferred Member
Since: Aug 24, 2006
Posts: 821
Last: Apr 15, 2011
[view latest posts]
Level 7
Forum Moderator
Im a fan of MODSonair
Category: CoD4 SP Mapping
Posted: Thursday, Feb. 25, 2010 03:52 am
For the first part, you are going to have to to have a checker that checks for the amount of allies alive. Here is a quick example.

Code:
main()
{
	// What I am going to do here is:
	// 1. Setup our objective
	// 2. watch for dead AI and end the mission if they die!

	wait 5; // Wait a few seconds until everything is setup.

	thread setMyObjective();
	thread watchFailmission();
}

setMyObjective()
{
	// What I am going to do here is:
	// 1. Setup my objective and alliesCount
	// 2. Start checking for dead allies

	level.alliesCount = getAiArray("allies").size; // Get the count of Allies currently alive.

	Objective_Add(0, "active", "Protect the Allies! ["+level.alliesCount+" alive]"); // Make the new objective and add text. "Protect the Allies! [5 alive]"
}

watchAi()
{
	// What I am going to do here is:
	// 1. Loop every half second to check for alive AI
	// 2. If AI are all dead, notify allies_killed.

	level endon("allies_killed");

	while(1)
	{
		count = getAiArray("allies").size;

		// If count less than or equal to 0, they are all dead!
		if(count <= 0)
		{
			level notify("allies_killed");
			break;
		}

		// Now, if we have a different count than before, we want to update the objective text and the alliesCount
		if(count != level.alliesCount)
		{
			level.alliesCount = count;
			objective_string(0, "Protect the Allies! ["+level.alliesCount+" alive]"); // As this gets called, the number will either increase (if more spawn) or decrease (if they die).
		}

		wait 0.5; // Wait a half second between each loop.
	}
}

watchFailmission()
{
	// What I am going to do here is:
	// 1. Wait until allies_killed is triggered.
	// 2. Fail the mission if all allies died.

	level waittill("allies_killed");
	MissionFailed();
}
nullFew tips for coding.
1. Keep the script as short as possible.
2. Don't comment every line. Only comment portions where they may be needed to point something out.
3. Don't over complicate the script, keep it organized and easy to read.

These help you find simple errors and makes it easy to make changes.
Share |
BlindSniper
General Member
Since: Aug 22, 2008
Posts: 45
Last: May 29, 2013
[view latest posts]
Level 2
Category: CoD4 SP Mapping
Posted: Thursday, Feb. 25, 2010 08:59 pm
Thanks a lot m8 this really helps
Share |
voidsource
General Member
Since: May 5, 2007
Posts: 1513
Last: Sep 1, 2013
[view latest posts]
Level 8
Category: CoD4 SP Mapping
Posted: Thursday, Feb. 25, 2010 11:07 pm
i must say that is a good way of doing it but heres another way too. instead of checking every half second to see if he's dead just have a simple thread on your allie or allies like in the last part that playername has. it would seem much better and ur not checking so often. it would look something like this

Code:

my_partner();
{
    getent( "guy", 'targetname" ) thread mission_fail_upon_death();// this is your entity running on a thread 
}

mission_fail_upon_death()
{

    self waittill("death" );
    setdvar("ui_deadquote",&"Mapname_localizedstring");
    maps\_utility::missionFailedWrapper();
}



now if its more than one guy i would suggest that you give all your partners the same key value. the script would slightly change. Also if you want those threads to end after a certain time or event in your script ( because mostlikely you dont want it to be running during your entire mission) you can put an endon function. Im not sure if you are familiar with it, but its a string( kinda like a message ) that you would tell a thread to terminate its own function if this string is ever called.
Example you want a pie and you call a thread to "eat_pie" but you put a endon function of "pie_is_too_hot" then whenever you call "pie_is_too_hot" then we terminate the thread of "eat_pie". it wouldnt affect the rest of the script just that thread. anywho the new function would look like this:

Code:

my_partner();
{
   guys =  getentarray( "guy", 'targetname" );
   for( i = 0; i < guys.size; i++ )
              guys[i] thread mission_fail_upon_death();
}

mission_fail_upon_death()
{
    level endon( "mission_complete" );//whenever you call "mission_complete" on any part of your script this thread will be terminated and will no longer be usefull. 
    self waittill("death" );
    setdvar("ui_deadquote",&"Mapname_localizedstring");
    maps\_utility::missionFailedWrapper();
}



remember that "mapname_localizedstring" is a localized string.
i hope this works out for you. Also im not saying playersname script is wrong. Im just providing an alternative that is all.



Share |
BlindSniper
General Member
Since: Aug 22, 2008
Posts: 45
Last: May 29, 2013
[view latest posts]
Level 2
Category: CoD4 SP Mapping
Posted: Friday, Feb. 26, 2010 06:39 pm
I tried what you said and got a syntax error my tests.gsc is:

Code:
main()
{
 maps\_load::main();
 
 level.weaponClipModels = [];
 level.weaponClipModels[0] = "weapon_m16_clip";
 level.weaponClipModels[1] = "weapon_ak47_clip";
 level.weaponClipModels[3] = "weapon_mp5_clip";

 level.player takeallweapons();
 level.player giveWeapon ("m16_basic");
 level.player giveWeapon ("fraggrenade");
 level.player giveWeapon ("flash_grenade");
 
 wait 5;
 
 thread obj1();
 
 thread my_partner();
 
 thread mission_fail_upon_death();

}

my_partner();
{
   guys =  getentarray( "guy", 'targetname" );
   for( i = 0; i < guys.size; i++ )
              guys[i] thread mission_fail_upon_death();
}

mission_fail_upon_death()
{
    level endon( "mission_complete" );//whenever you call "mission_complete" on any part of your script this thread will be terminated and will no longer be usefull. 
    self waittill("death" );
    setdvar("ui_deadquote",&"tests_localizedstring");
    maps\_utility::missionFailedWrapper();
}

obj1()
{

obj1 = getent("obj1", "targetname");

objective_add(1, "active", &"tests_OBJ1",getent("obj1","targetname").origin);

objective_current(1);

obj1 waittill("trigger");

objective_state(1, "done");

obj1 delete();

wait(1);

iprintlnbold (&"tests_OBJ_COMPLETED"); //tells player obj finished

missionSuccess ("fun",false); //the mission ends
}


The error is:

Error:
******* script compile error *******
Error: bad syntax: (file 'maps/tests.gsc', line 25)
my_partner();
*
************************************
Loaded zone 'tests'
dvar set cl_paused 0
dvar set loc_language 0
dvar set loc_forceEnglish 0
dvar set com_errorTitle Error
dvar set com_errorMessage script compile error
bad syntax
my_partner();
(see console for details)

********************
ERROR: script compile error
bad syntax
my_partner();
(see console for details)

********************

Can anyone help?

edited on Feb. 26, 2010 02:45 pm by BlindSniper
Share |
tomv8
General Member
Since: Oct 5, 2008
Posts: 469
Last: Jul 14, 2010
[view latest posts]
Level 5
Category: CoD4 SP Mapping
Posted: Friday, Feb. 26, 2010 06:54 pm
make sure ur allies have a targetname of guy
Share |
Marty22
General Member
Since: Jan 2, 2008
Posts: 42
Last: Sep 17, 2011
[view latest posts]
Level 2
Category: CoD4 SP Mapping
Posted: Friday, Feb. 26, 2010 07:42 pm
You need to remove the semicolon after my_partner() here:
Code:
my_partner(); <-------------
{
   guys =  getentarray( "guy", 'targetname" );
   for( i = 0; i < guys.size; i++ )
              guys[i] thread mission_fail_upon_death();
}
Share |
BlindSniper
General Member
Since: Aug 22, 2008
Posts: 45
Last: May 29, 2013
[view latest posts]
Level 2
Category: CoD4 SP Mapping
Posted: Friday, Feb. 26, 2010 07:47 pm
Thats fixed it Marty22
Share |
tomv8
General Member
Since: Oct 5, 2008
Posts: 469
Last: Jul 14, 2010
[view latest posts]
Level 5
Category: CoD4 SP Mapping
Posted: Friday, Feb. 26, 2010 07:49 pm
Marty22 writes...
Quote:
You need to remove the semicolon after my_partner() here:
Code:
my_partner(); <-------------
{
   guys =  getentarray( "guy", 'targetname" );
   for( i = 0; i < guys.size; i++ )
              guys[i] thread mission_fail_upon_death();
}

nice eyes u got there i didnt even notice tht :P
Share |
Restricted Access Topic is Locked
Page
Next Page
subscribe
MODSonline.com Forums : Call of Duty 4 : CoD4 SP Mapping

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»