scripting a counter?

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Desert Eagle
Captain
Posts: 237
Joined: Mon Jan 13, 2003 1:05 am
Location: Mapping Bunker
Contact:

scripting a counter?

Post by Desert Eagle »

In my map I have 3 player useable flak cannons that can take damage from weapons to be destoryed, along with correct collision, etc....

I would like to script some sort of counter so when all 3 flak cannons are destroyed(I am not using bombs to destory) the allies win.

I have tried a few things, but can not get my counter to work correctly.

I have given the targetnames flak1 flak2 and flak3 to the flaks

I can only get it to work if one is destoryed.

As always any help would be appericated
Desert-Eagle
....The Eagle Has Landed...
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

try this...

beginning of the round, type level.flaksleft = 3

im guessing your using a single death thread for all 3 flaks.
in that case, at the end of the thread, type "level.flaksleft--" that will decrease the level.flaksleft by 1.

so when all flaks die, the level.flaksleft will have went down 3 times. it should be at 0 when all 3 are gone.

to script the win part, try this...

if (level.flaksleft == 0)
{
. //yourcodehere (remove period)
}
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

post

Post by tltrude »

Post your script and someone will help.
Tom Trude,

Image
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

help is at hand

but... i'm gonna guess that u have triggers that will destroy the flaks are all trigger->use
key: targetname
value: flak_trigger1
key: setthread
value: flak1

then have in the script

main:
level.flak1 = 0
level.flak2 = 0
level.flak3 = 0
level.desert_eagle_counter = 0

flak1:
if ( parm.other.dmteam == allies )
{
iprintlnbold_noloc "The Allies have destroyed the North Flak88!"
setcvar "g_obj_alliedtext1" "North Flak88 destroyed [x]"
//change the anim here
level.desert_eagle_counter++
$flak_trigger1 remove
}
wait 1
if (level.desert_eagle_counter == 3)
{teamwin allies}
end

flak2:
if ( parm.other.dmteam == allies )
{
iprintlnbold_noloc "The Allies have destroyed the South Flak88!"
setcvar "g_obj_alliedtext2" "South Flak88 destroyed [x]"
//change the anim here
level.desert_eagle_counter++
$flak_trigger2 remove
}
wait 1
if (level.desert_eagle_counter == 3)
{teamwin allies}
end

flak3:
if ( parm.other.dmteam == allies )
{
iprintlnbold_noloc "The Allies have destroyed the Centre Flak88!"
setcvar "g_obj_alliedtext1" "Centre Flak88 destroyed [x]"
//change the anim here
level.desert_eagle_counter++
$flak_trigger3 remove
}
wait 1
if (level.desert_eagle_counter == 3)
{teamwin allies}
end


/*as you'll see only once the counter has reached 3, the allies will win
level.any_counter++ just means level.any_counter = level.any_counter + 1
i.e 0 = 0 + 1 therefore becomes one
.... 1 = 1 + 1 becomes two
..... 2 = 2 + 1 becomes three (the allies win) :D
*/
hope this helps, prob not cos it's all foreign 2 me :-/
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

All you need is:

Code: Select all

$flak1 waittill death
if($flak2)
  $flak2 waittill death
if($flak3)
  $flak3 waittill death

teamwin allies
8)
Image
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

lol, yeah but mine was in yellow and orange :D
hope this helps, prob not cos it's all foreign 2 me :-/
Desert Eagle
Captain
Posts: 237
Joined: Mon Jan 13, 2003 1:05 am
Location: Mapping Bunker
Contact:

Here is what I had

Post by Desert Eagle »

Here is my script below. Nothing works right, maybe because an entity can not run 2 threads? One for the collision and one for the objective?

// MP_SNOWY_AMBUSH_OBJ
// ARCHITECTURE: [FS] Desert Eagle
// SCRIPTING: [FS] Desert Eagle

main:

// set scoreboard messages
setcvar "g_obj_alliedtext1" " Destroy Three 88s"
setcvar "g_obj_alliedtext2" " By Whatever Means"
setcvar "g_obj_alliedtext3" " You Have At Hand"
setcvar "g_obj_axistext1" " Defend Three 88s"
setcvar "g_obj_axistext2" " Destroy The Allies"
setcvar "g_obj_axistext3" ""

setcvar "g_scoreboardpic" ""

level waitTill prespawn

//----------------------------------------------
//Map Prep
//----------------------------------------------

exec global/DMprecache.scr
exec maps/obj/mp_snowy_ambush_obj_precache.scr
exec global/ambient.scr mohdm5
level.script = maps/obj/mp_snowy_ambush_obj.scr
level.dmrespawning = 0 // 1 or 0
level.dmroundlimit = 5 // round time limit in minutes
level.clockside = axis // set to axis, allies, kills, or draw
level.flaksleft = 3

//----------------------------------------------
//Flak Collision Setup
//----------------------------------------------

$flak1.collisionent = $flak88_collision
$flak1_turret0.collisionent = $flak88_turret_collision
$flak1 thread global/stationaryweapons.scr::MountedStationaryWeaponWithCollision "models/

statweapons/flak88_d.tik" $flak1_destroyed_collision

$flak2.collisionent = $flak88_collision
$flak2_turret0.collisionent = $flak88_turret_collision
$flak2 thread global/stationaryweapons.scr::MountedStationaryWeaponWithCollision "models/

statweapons/flak88_d.tik" $flak2_destroyed_collision

$flak3.collisionent = $flak88_collision
$flak3_turret0.collisionent = $flak88_turret_collision
$flak3 thread global/stationaryweapons.scr::MountedStationaryWeaponWithCollision "models/

statweapons/flak88_d.tik" $flak3_destroyed_collision

level waittill spawn

//----------------------------------------------
// Set Up Sounds
//----------------------------------------------

$truck_run loopsound sub_idle
$truck_burn1 loopsound fire_med1
$truck_burn2 loopsound fire_med1
$burn_barrel loopsound fire_small

//level waittill roundstart //rem out for testing

//----------------------------------------------
// Set Up Objectives
//----------------------------------------------

$flak1 thread obj_flak_death
$flak2 thread obj_flak_death
$flak3 thread obj_flak_death
thread allied_victory
thread axis_victory



//----------------------------------------------
// Let It Snow
//----------------------------------------------

snow:
wait 1

level.rain_speed = "60"
level.rain_speed_vary = "2"
level.rain_length = "2"
level.rain_width = "1"
level.rain_density = "5"
level.rain_slant = "1"
level.rain_min_dist = "768"
level.rain_numshaders = 12
level.rain_shader = "textures/snow"


end

//----------------------------------------------
// Objective Thread
//----------------------------------------------

obj_flak_death:

self waittill death
inprintln "A Flak 88 Has Been Destoryed"
level.flaksleft--

end

//----------------------------------------------
//Allies Win
//----------------------------------------------

allied_victory:

if (level.flaksleft == 0)
{
teamwin allies
}

end

//----------------------------------------------
//Axis Win
//----------------------------------------------


axis_victory:

level waittill axiswin

end
Desert-Eagle
....The Eagle Has Landed...
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

inprintln

should be

iprintln
Image
Desert Eagle
Captain
Posts: 237
Joined: Mon Jan 13, 2003 1:05 am
Location: Mapping Bunker
Contact:

Post by Desert Eagle »

I just used your little thread Jv and everything worked great!

jv_map = god of scripting....:)
Desert-Eagle
....The Eagle Has Landed...
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

but thanks to nuggets for his time and effort also ;)

post subject = scripting a counter?

jv's wasn't a counter and you said you weren't using bombs, therefore it was to be presumed that you were not destroying the flak88's in the normal way and just possilby wanted them disabled not destroyed

therefore waittill death wouldn't apply :D

some people really make you wonder why you ever bother
hope this helps, prob not cos it's all foreign 2 me :-/
Desert Eagle
Captain
Posts: 237
Joined: Mon Jan 13, 2003 1:05 am
Location: Mapping Bunker
Contact:

Thanks

Post by Desert Eagle »

Sorry nuggets. Thanks have to go to nuggets and Alcoholic and tltrude and everyone at .map!

Was just so excited that simple thread that jv supplied worked so easily and solved my problems.

I am not destorying the flaks with triggers or bombs. Just simply using the P_flak (like in Berlin_TOW), that is useable but can still be destoryed by nades, bazookas, or other flaks. So instead of the counter idea, jv supplied a simple waittill death thread that worked.


I myself struggle with scripting, and only ask questions after exhausting all my scripting ideas. I can do mapping but scripting is just harder. It took me over 35 hours to do the scripting for my ComeInFighting_TOW map.

So again thanks to everyone who asks questions or gives answers here at .map.
Desert-Eagle
....The Eagle Has Landed...
Post Reply