Page 1 of 1

Random Threads

Posted: Fri Dec 12, 2003 3:13 pm
by Krane
Ok, you have 2 or 3 threads at the end of your script.

Is there any way I can randomly run these threads? I mean, when you start a game, the game choose which thread to run?

Posted: Fri Dec 12, 2003 3:34 pm
by jv_map
Do a search, small_sumo asked nearly the same question a couple of weeks ago ;).

Posted: Fri Dec 12, 2003 3:53 pm
by Krane
Sorry and thanks. That's not exactly what I want but I'll take from there.

Posted: Tue Dec 16, 2003 3:49 pm
by nuggets
two ways of doing it
one easy way

main:
level.thread_number = (randomint (3))
end

if (level.thread_number == 0)
{thread thread_0}

if (level.thread_number == 1)
{thread thread_1}

if (level.thread_number == 2)
{thread thread_2}
end


or use switch instead of if


if you want to get into multiple random objectives, here's the end part of my own little test


the_briefing:
if (level.obj_done == level.obj_count)
{teamwin "allies"
end}
if (level.ass == 1)
{waitthread assassin_obj}
else
{level.obj_num = randomint (3)
if (level.obj_num == 0)
{if (level.bom == 1)
{waitthread bombs_obj}
else
{if (level.kot == 1)
{waitthread koth_obj}
else
{if (level.ste == 1)
{waitthread to_steal_obj}
else
{setcvar "g_obj_alliedtext1" "0 error somewhere"}}}}
if (level.obj_num == 1)
{if (level.kot == 1)
{waitthread koth_obj}
else
{if (level.ste == 1)
{waitthread to_steal_obj}
else
{if (level.bom == 1)
{waitthread bombs_obj}
else
{setcvar "g_obj_alliedtext1" "1 error somewhere"}}}}
if (level.obj_num == 2)
{if (level.ste == 1)
{waitthread to_steal_obj}
else
{if (level.bom == 1)
{waitthread bombs_obj}
else
{if (level.kot == 1)
{waitthread koth_obj}
else
{setcvar "g_obj_alliedtext1" "2 error somewhere"}}}}}

if (level.obj_done > 0)
{iprintln_noloc "******************************"
iprintln_noloc "OBJECTIVES UPDATED"
iprintln_noloc "******************************"}
if (level.obj_done < level.obj_count)
{setcvar "g_obj_alliedtext1" ("Objective " + (level.obj_done + 1) + " / " + level.obj_count + " ...")
setcvar "g_obj_alliedtext2" level.ln_2
setcvar "g_obj_alliedtext3" level.ln_3
setcvar "g_obj_axistext1" ("Objective " + (level.obj_done + 1) + " / " + level.obj_count + " ...")
setcvar "g_obj_axistext2" level.ln_5
setcvar "g_obj_axistext3" level.ln_6}
end

Posted: Tue Dec 16, 2003 5:57 pm
by Krane
Cool nuggets, txs!

I'll take a look carefully! 8-)

Posted: Thu Dec 18, 2003 10:05 am
by Parts
I think you could also do something like:

Code: Select all

// returns a number from 0 to 2
local.threadnum = randomint(3)

thread ("MyThread_" + local.threadnum)

Posted: Thu Dec 18, 2003 4:29 pm
by jv_map
Parts wrote:I think you could also do something like:

Code: Select all

// returns a number from 0 to 2
local.threadnum = randomint(3)

thread ("MyThread_" + local.threadnum)
I think that will not work... or maybe it does as long as the thread is in the same script file :?