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

Members Online

»
0 Active | 93 Guests
Online:

LATEST FORUM THREADS

»
run artillery on maps
CoD+UO Map + Mod Releases
Call of DutyŽ: WWII
CoD WW2 General

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 2
Category: CoD2 Scripting
Scripting and coding with Call of Duty 2.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: How to end a Level if a German Soldier dies?
s6robi
General Member
Since: Jun 11, 2006
Posts: 83
Last: Feb 4, 2016
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Monday, Dec. 28, 2015 08:44 am
Hi everyone,

So I am 95% done with my single player map. In order for me to complete it, I am trying to add a function where if I kill a German Soldier before his time.

I.E - Im on OBJ 2 and I need to kill a German Sentre during OBJ 4 but if I kill him while im on OBJ 2 it threads a mission failure and the level restarts to last checkpoint.

I am able to get a "Mission Failure" working when I kill the German Soldier. So I am 50% complete...however, when I get to the OBJ where I need to kill the soldier, I'll kill him and it still threads the mission failure [banghead]. I'm decent at scripting (Not a pro by any means). I have to turn towards you all for your help and guidance.

Here is my code:

#include maps\_utility;
#include maps\_anim;
#using_animtree("generic_human");

main()
{

maps\_load::main();
//precachemodel ("xmodel/vehicle_stuka_flying");




thread german();
thread german2();
thread obj1();
}

obj1()
{
obj1 = getent("obj1", "targetname");
objective_add(1, "active", &"OASIS_OBJECTIVE_FOLLOW",getent("obj1marker", "targetname").origin);
objective_current(1);

obj1 waittill("trigger");

objective_state(1, "done");
obj1 delete();

thread obj2();
}


obj2()
{
thread germansuccess();
thread german2success();

obj2 = getent("obj2", "targetname");
objective_add(2, "active", &"OASIS_OBJECTIVE_KILL_SNIPER",getent("obj2", "targetname").origin);
objective_current(2);

obj2 waittill("death");
objective_state(2, "done");
}


german()
{
german = getent ("german", "script_noteworthy");;

if(isAlive(german))
{
german.maxsightdistsqrd = (5*5);
german.health = 10;
german waittill("death");
thread mission_failure();
}
wait(.05);
}



german2()
{
german2 = getent ("german2", "script_noteworthy");;

if(isAlive(german2))
{
german2.maxsightdistsqrd = (5*5);
german2.health = 10;
german2 waittill("death");
thread mission_failure();
}
wait(.05);
}


germansuccess()
{
german = getent ("german", "script_noteworthy");;

if(isAlive(german))
{
german.maxsightdistsqrd = (5*5);
german.health = 10;
german waittill("death");
}
wait(.05);
}



german2success()
{
german2 = getent ("german2", "script_noteworthy");;

if(isAlive(german2))
{
german2.maxsightdistsqrd = (5*5);
german2.health = 10;
german2 waittill("death");
}
wait(.05);
}



mission_failure()
{
setCvar("ui_deadquote", "@SCRIPT_MISSION_FAILURE_ALERTED_ENEMY");
maps\_utility::missionFailedWrapper();
}


This is annoying the living crap out of me, if anyone can rescue me I'll be eternally grateful!
Share |
SPi
General Member
Since: Jul 4, 2012
Posts: 531
Last: Nov 9, 2019
[view latest posts]
Level 6
Category: CoD2 Scripting
Posted: Monday, Dec. 28, 2015 09:57 am
Yeah I had similar problems in my Call of Duty 4 Rooftops mappack.
when you kill the german the fail function still waits for german to die and do mission failed.

You have to put the fail wait in a loop and break it when the german is dead so the fail function is not triggered.

Code:

#include maps\_utility;

#include maps\_anim;

#using_animtree("generic_human");

main()
{
maps\_load::main();
//precachemodel ("xmodel/vehicle_stuka_flying");

flag_init("disable_fail"); // initialize the flag after load main and before the main mission functions start

thread german_init();
thread obj1();
}




german_init()
{
german = getent ("german", "script_noteworthy");;


for(;;) // infinite loop
{

if(isAlive(german))
{
german.maxsightdistsqrd = (5*5);
german.health = 10;
german waittill("death");
thread mission_failure();
}

else if(flag(disable_fail)) //else if flag is set, disable the fail via flag
break; //stop loop so fail wont work if german dies.

wait 0.05;	 // when you use infinite loop put that wait here so you wont get infinite loop error

}

wait(.05);	
}





obj1()
{
obj1 = getent("obj1", "targetname"); 
objective_add(1, "active", &"OASIS_OBJECTIVE_FOLLOW",getent("obj1marker", "targetname").origin);
objective_current(1); 

obj1 waittill("trigger");

objective_state(1, "done"); 
obj1 delete();

thread obj2();	
}


obj2()
{
flag_set("disable_fail");

thread germansuccess();

obj2 = getent("obj2", "targetname"); 
objective_add(2, "active", &"OASIS_OBJECTIVE_KILL_SNIPER",getent("obj2", "targetname").origin);
objective_current(2); 

obj2 waittill("death");
objective_state(2, "done");
}

germansuccess()
{
german = getent ("german", "script_noteworthy");;

if(isAlive(german))
{
german.maxsightdistsqrd = (5*5);
german.health = 10;
german waittill("death");
}
wait(.05);	

thread continue_mission();

}




mission_failure()	
{
setCvar("ui_deadquote", "@SCRIPT_MISSION_FAILURE_ALERTED_ENEMY");
maps\_utility::missionFailedWrapper();
}


I removed and changed some stuff to hopefully make it more clear.

I hope it helps.
Share |
s6robi
General Member
Since: Jun 11, 2006
Posts: 83
Last: Feb 4, 2016
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Monday, Dec. 28, 2015 10:45 am
SPi,

Thank you so much for your reply and your help! I am unfortunately running into a script error:

*********** script compile error ************
uninitialised variable 'disable_fail'; (file 'maps/testing.gsc', line 37)
else if(flag(disable_fail)) //else if flag is set, disable the fail via flag

I have no idea where to go from there haha. Your thoughts SPi??
Share |
s6robi
General Member
Since: Jun 11, 2006
Posts: 83
Last: Feb 4, 2016
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Monday, Dec. 28, 2015 11:29 am
SPi,

Okay, so after tinkering with the code a little bit, I was able to get the map to run. Here is the code:

#include maps\_utility;

#include maps\_anim;

#using_animtree("generic_human");

main()
{
maps\_load::main();
//precachemodel ("xmodel/vehicle_stuka_flying");

flag_init("disable_fail"); // initialize the flag after load main and before the main mission functions start

thread german_init();
thread obj1();
}




german_init()
{

german = getent ("german", "script_noteworthy");;


for(;;) // infinite loop
{

if(isAlive(german))
{
german.maxsightdistsqrd = (5*5);
german.health = 10;
german waittill("death");
thread mission_failure();
}

else if(flag("disable_fail")) //else if flag is set, disable the fail via flag
break; //stop loop so fail wont work if german dies.

wait 0.05; // when you use infinite loop put that wait here so you wont get infinite loop error

}

wait(.05);
}





obj1()
{
obj1 = getent("obj1", "targetname");
objective_add(1, "active", &"OASIS_OBJECTIVE_FOLLOW",getent("obj1marker", "targetname").origin);
objective_current(1);

obj1 waittill("trigger");

objective_state(1, "done");
obj1 delete();

thread obj2();
}


obj2()
{
flag_set("disable_fail");

thread germansuccess();

obj2 = getent("obj2", "targetname");
objective_add(2, "active", &"OASIS_OBJECTIVE_KILL_SNIPER",getent("obj2", "targetname").origin);
objective_current(2);

obj2 waittill("death");
objective_state(2, "done");
}

germansuccess()
{
german = getent ("german", "script_noteworthy");;

if(isAlive(german))
{
german.maxsightdistsqrd = (5*5);
german.health = 10;
german waittill("death");
}
wait(.05);

//thread continue_mission();

}



mission_failure()
{
setCvar("ui_deadquote", "@SCRIPT_MISSION_FAILURE_ALERTED_ENEMY");
maps\_utility::missionFailedWrapper();
}


I changed the else if(flag(disable_fail)) to

else if(flag("disable_fail"))

is that correct? ^^ because my map still ends while either OBJ1 or OBJ2 are active when I kill the german.

I also // the thread continue_mission() because I don't have that for this little level.

What will I need to do to get this to work with the minor tweaks I made? We're my tweaks even beneficial?
Share |
SPi
General Member
Since: Jul 4, 2012
Posts: 531
Last: Nov 9, 2019
[view latest posts]
Level 6
Category: CoD2 Scripting
Posted: Monday, Dec. 28, 2015 02:06 pm
You successfully did correct my mistake with the flag
set disable_fail to "disable_fail"

Continue_mission()
is your own and you can remove or modify it. Its just to show you where to continue your missions script.

Now I don't know if it will 100% work the way you want.
I might have skipped something so thats why objectives dont work properly.
I may try to make a testmap with it tomorrow. Tell me if there's anything else you need.
I have learned so much stuff about cod sp mapping that i believe that i can teach a lot. Its always my pleasure to spread out my so far knowledge. keep it up.
Share |
s6robi
General Member
Since: Jun 11, 2006
Posts: 83
Last: Feb 4, 2016
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Monday, Dec. 28, 2015 02:35 pm
attachment: application(2.5Kb)
SPi,

I can't thank you enough for your willingness to help me. I've been modding COD2 off and on for the past 5 yrs however, this past 2 months I've really been trying to get the handle on scripting. Some things regarding it just confuse the crap out of me haha.

Attached is my test map (.map, .gsc, .str). I figured id just upload my work so it would alleviate you from having to create it from scratch.

Id hate to add another request but if you have time, and wouldn't mind, I am trying to figure out also how to complete an objective when an allied soldier gets to my locations. I have got it to work only off of the "wait('insert how many seconds it took for my ally to make it to me);" function. I know there is an easier way, I am just a noob to scripting still.

If the above didn't make sense, here is some code from my Main SP map I am trying to finish:

obj1()
{
org = spawn ("script_origin", level.player getorigin());
org.angles = level.player getplayerangles();
level.player linkto(org);

obj1 = getent("obj1", "targetname");
objective_add(1, "active", &"OASIS_OBJECTIVE_WAIT");
objective_current(1);

wait(11.5); //<--------It takes 11.5 seconds for my ally to reach me then I just call the "objective_state(1, "done"); function....theres gotta be a better way though because sometimes it takes a little longer to reach me and sometimes a little shorter due to my pathnodes and other allys running to me bumping into eachother.

objective_state(1, "done");
obj1 delete();

wait(1);

//*****************Intro Dialog***************\\
alert = getent ("dialog1source", "targetname");
alert playsound("dialog1");

wait(5);

alert playsound("dialog2");

wait(5);

alert playsound("dialog3");

wait(5);

alert playsound("dialog4");

wait(5);
//*****************Dialog Ends***************\\

level.player unlink();
org delete();

thread obj2();
}

Anyways, my priority is still figuring out the mission fail if I kill a german before I am supposed to, then if theres time we'll work on the completing objectives when the ally is next to you.

Again, Thank you very much for your help SPi. I'll be looking forward to your solution in a few!

edited on Dec. 28, 2015 02:36 pm by s6robi
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty 2 : CoD2 Scripting

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

»