Killtread isn't working
Moderator: Moderators
Killtread isn't working
Huy !
Let me anybody say: why killthreaddidn't work in singleplayer map (i.e. when soldier is dead thread didn't work). Functionisalivei don't want to use.
P.S.:where i can read tutorial about hitting and exploding static vehicles (for example, airfield m1l3b AA)
Let me anybody say: why killthreaddidn't work in singleplayer map (i.e. when soldier is dead thread didn't work). Functionisalivei don't want to use.
P.S.:where i can read tutorial about hitting and exploding static vehicles (for example, airfield m1l3b AA)
Ukraine is the best
1) If you open SDK/docs/MOH_GameClasses, you can read this function killthread ( String thread ) (Set the thread to execute when this model is killed).
2) And here is script:
level waittill prespawn
$player item weapons/m1_garand.tik
$player ammo rifle 50
$player useweaponclass rifle
level waittill spawn
thread mission1
thread mission2
end
mission1:
waitthread global/objectives.scr::add_objectives 1 2 "Kill the officer." $officer_1.origin
waitthread global/objectives.scr::current_objectives 1
if (isalive $officer_1)
$officer_1 waittill death
{
waitthread global/objectives.scr::add_objectives 1 3 "Kill the officer." $officer_1.origin
waitthread global/objectives.scr::current_objectives 0
}
end
mission2:
while ((isalive $soldier_1)||(isalive $soldier_2)||(isalive $soldier_3))
{
if (isalive $soldier_1)
$soldier_1 waittill death
{iprintln_noloc "Soldier_1 is dead."}
if (isalive $soldier_2)
$soldier_1 waittill death
{iprintln_noloc "Soldier_2 is dead."}
if (isalive $soldier_3)
$soldier_1 waittill death
{iprintln_noloc "Soldier_3 is dead."}
}
end
When I killed the 2-nd soldier, but the 1-st isalive, function don't print
"Soldier_2 is dead". That's why I decide to use killthread (as entering the trigger, work setthread)
P.S.: I want to kill enemyes in different ways, not following step by step.
2) And here is script:
level waittill prespawn
$player item weapons/m1_garand.tik
$player ammo rifle 50
$player useweaponclass rifle
level waittill spawn
thread mission1
thread mission2
end
mission1:
waitthread global/objectives.scr::add_objectives 1 2 "Kill the officer." $officer_1.origin
waitthread global/objectives.scr::current_objectives 1
if (isalive $officer_1)
$officer_1 waittill death
{
waitthread global/objectives.scr::add_objectives 1 3 "Kill the officer." $officer_1.origin
waitthread global/objectives.scr::current_objectives 0
}
end
mission2:
while ((isalive $soldier_1)||(isalive $soldier_2)||(isalive $soldier_3))
{
if (isalive $soldier_1)
$soldier_1 waittill death
{iprintln_noloc "Soldier_1 is dead."}
if (isalive $soldier_2)
$soldier_1 waittill death
{iprintln_noloc "Soldier_2 is dead."}
if (isalive $soldier_3)
$soldier_1 waittill death
{iprintln_noloc "Soldier_3 is dead."}
}
end
When I killed the 2-nd soldier, but the 1-st isalive, function don't print
"Soldier_2 is dead". That's why I decide to use killthread (as entering the trigger, work setthread)
P.S.: I want to kill enemyes in different ways, not following step by step.
Ukraine is the best
Try this
This might work. The "!" symbol means "not" or "is not".
I'm not sure if the "wait" line is needed, but it may loop too fast without it.
"Waittill" (wait until) makes the script stop reading lines until that event happens. So, your thread was waiting until soldier_1 died before checking soldier_2.
PS: The above thread is not correct. Use Ric-hard's thread below.
I'm not sure if the "wait" line is needed, but it may loop too fast without it.
Code: Select all
mission2:
while ((isalive $soldier_1)||(isalive $soldier_2)||(isalive $soldier_3))
{
if !(isalive $soldier_1) // If not alive.
{
iprintln_noloc "Soldier_1 is dead."
}
if !(isalive $soldier_2) // If not alive.
{
iprintln_noloc "Soldier_2 is dead."
}
if !(isalive $soldier_3) // If not alive.
{
iprintln_noloc "Soldier_3 is dead."
}
wait .01
}
end
PS: The above thread is not correct. Use Ric-hard's thread below.
Last edited by tltrude on Tue May 01, 2007 3:22 am, edited 1 time in total.
Something like this would be ok I think.
Code: Select all
mission2:
while ( (isalive $soldier_1)||(isalive $soldier_2)||(isalive $soldier_3) )
{
if ( !(isalive $soldier_1) && (level.soldier_1_checked == NIL) )
{
level.soldier_1_checked = 1
iprintln_noloc "Soldier_1 is dead."
}
if ( !(isalive $soldier_2) && (level.soldier_2_checked == NIL) )
{
level.soldier_2_checked = 1
iprintln_noloc "Soldier_2 is dead."
}
if ( !(isalive $soldier_3) && (level.soldier_3_checked == NIL) )
{
level.soldier_3_checked = 1
iprintln_noloc "Soldier_3 is dead."
}
waitframe // I dont think u can wait .01, .05/waitframe is minimum
}
end
Last edited by Ric-hard on Mon Apr 30, 2007 8:42 pm, edited 1 time in total.
Because i'm bored, and feeling adventurous, this is how i would do the thing. Plus, i just scored an apple in a different thread and feel professor-ey.
1. You're making a lot of duplicate compares, checking the isAlive for one soldier (on average) 4 times in one frame, times 3 soldiers. You only need to get it once and use that variable. Using memory > using compares.
2. You only need to check if all of the soldiers are dead when one dies. They cannot die and not be caught by the thread, so why check them every update?
3. You can wait as much as .5 to .8, to upgrade the performance, nobody will notice if a message is displayed a frame later, depending on the map and machine it's running on, you could be making these compares 25-200 times in a second. Waiting a half a second splits that down to 2 calls a second.
One last thing, soldier_#_checked doesn't need to be level.; if you're only using it in this thread it should be local.. But that doesn't affect performance at all, i think.
1. You're making a lot of duplicate compares, checking the isAlive for one soldier (on average) 4 times in one frame, times 3 soldiers. You only need to get it once and use that variable. Using memory > using compares.
2. You only need to check if all of the soldiers are dead when one dies. They cannot die and not be caught by the thread, so why check them every update?
3. You can wait as much as .5 to .8, to upgrade the performance, nobody will notice if a message is displayed a frame later, depending on the map and machine it's running on, you could be making these compares 25-200 times in a second. Waiting a half a second splits that down to 2 calls a second.
One last thing, soldier_#_checked doesn't need to be level.; if you're only using it in this thread it should be local.. But that doesn't affect performance at all, i think.
Code: Select all
mission2:
while ( true )
{
local.soldier1Alive = (isAlive $soldier_1)
local.soldier2Alive = (isAlive $soldier_2)
local.soldier3Alive = (isAlive $soldier_3)
if ( !local.soldier1Alive && (level.soldier_1_checked == NIL) )
{
level.soldier_1_checked = 1
iprintln_noloc "Soldier_1 is dead."
if( !local.soldier2Alive && !local.soldier3Alive)
{
// point of interest, if 'return' works in mohaa scripting you could just do that too.
break;
}
}
if ( !local.soldier2Alive && (level.soldier_2_checked == NIL) )
{
level.soldier_2_checked = 1
iprintln_noloc "Soldier_2 is dead."
if( !local.soldier1Alive && !local.soldier3Alive)
{
break;
}
}
if ( !local.soldier3Alive && (level.soldier_3_checked == NIL) )
{
level.soldier_3_checked = 1
iprintln_noloc "Soldier_3 is dead."
if( !local.soldier1Alive && !local.soldier2Alive)
{
break;
}
}
wait .7
}
endModerator
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
۞
Abyssus pro sapientia
Olympus pro Ignarus
۞
AND STUFF™ © 2006
My turn
Code: Select all
mission2:
$soldier1 thread living 1
$soldier2 thread living 2
$soldier3 thread living 3
end
living local.num:
self waittill death
iprintln_noloc ( "Soldier_" + local.num + " is dead" )
endobjective
My guess is that Guderian is replacing the printing lines with singleplayer objectives. But, bdbodger's two threads are cool, none the less.

