Random Threads

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Random Threads

Post 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?
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Do a search, small_sumo asked nearly the same question a couple of weeks ago ;).
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Sorry and thanks. That's not exactly what I want but I'll take from there.
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 »

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
hope this helps, prob not cos it's all foreign 2 me :-/
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Cool nuggets, txs!

I'll take a look carefully! 8-)
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Post 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)
[VS-UK]Capt.Parts[BnHQ]
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post 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 :?
Image
Post Reply