Err, I'm really kind of noob with triggers and scripts, but what I'm trying to do is this:
I have a trigger that when run, picks a random trigger out of 5 or so and runs it. (I'm planning for 100 or so which is why I need help here)
I have the 5 triggers named r00,r01,r02.. ..r04 etc.
My random trigger goes as so.
RANDOMPICKEventsDialog-AnyDialogItemisusedbyPlayerAnyPlayerwitheventtypeClicked//I only have one dialog item which is why it's set to AnyLocalVariablesa=(Emptyplayergroup)<PlayerGroup>b=NoTrigger<Trigger[5]>ConditionsActionsPlayerGroup-Addplayer(Triggeringplayer)toaGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If(Player(Triggeringplayer)hasatleast100Mineralsandatleast0Gas)==trueThenPlayer-Modifyplayer(Triggeringplayer)Minerals:Subtract100Variable-Setb[0]=r00Variable-Setb[1]=r01Variable-Setb[2]=r02Variable-Setb[3]=r03Variable-Setb[4]=r04Trigger-Runb[(Randomintegerbetween0and4)](CheckConditions,Don'tWaituntilitfinishes)ElseUI-Display"Not enough resources. You require a..."foratoSubtitleareaPlayerGroup-Removeplayer(Triggeringplayer)froma
Is there a way so instead of setting 100 variables to triggers I can change the:
(Addthisnewinteger)rand=0<Integer>General-Foreachintegerrandfrom0to4withincrement1,do(Actions)ActionsVariable-Setb[rand] = (Some way I can set this to r0[rand], meaning if rand is set to 4 then it will set b[4] to trigger r04)
Is there any way of doing this using custom script or whatnot?
Probably not. In script I'm sure they don't call the activator by his name. r00 means nothing to the script, probably changed to another kind of ID.
That triggers are so different that you need to have them in different triggers? You can group them by similar functions and do another random inside the trigger for variations or something.
Give assigns each trigger to a non-array variable. So it's not that easy.
I can think of two ways to do that:
1) You create all your triggers in custom script and use one large trigger array to store them all. You would have to know quite a bit of Custom Scripting though.
2) The second way is actually a little trick. We can use a small custom script to quickly re-create one of the triggers and run it.
To key is knowing how GUI names all it's triggers in the background.
When I create a trigger called "Add Kill Score" then GUI calls these script actions to create it:
So it names the trigger variable "gt_<Our trigger name without spaces>"
And the actual name of the function that becomes our trigger is called "gt_<Out trigger name without spaces>_Func"
Now, the trigger variable is useless to use, but the function name is interesting.
We can predict the name of our trigger function.
r00 would be called "gt_r00_Func" and r01 is "gt_r01_Func". It's always the same principle.
Now we can predict the name of any function ourself by using a similar algorithm. Since our functions are all called r00, r01, r02 we can say that:
"gt_r<our random number here>_Func"
will give us our function name.
So we can create the random number and insert it into our string. The result would look like this:
RANDOMPICKEventsDialog-AnyDialogItemisusedbyPlayerAnyPlayerwitheventtypeClicked//I only have one dialog item which is why it's set to AnyLocalVariablesa=(Emptyplayergroup)<PlayerGroup>funcTrigger=NoTrigger<Trigger>funcName=""<String>ConditionsActionsPlayerGroup-Addplayer(Triggeringplayer)toaGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If(Player(Triggeringplayer)hasatleast100Mineralsandatleast0Gas)==trueThenPlayer-Modifyplayer(Triggeringplayer)Minerals:Subtract100SetVariable:funcName=String(RandomIntegerbetween0and99)If(LengthoffuncName==1)Thendo(Actions)ThenSetVariable:funcName="0"+funcNameElseSetVariable:funcName="gt_r"+funcName+"_Func"CustomScript:"lv_funcTrigger = TriggerCreate(lv_funcName);"Trigger-RunfuncTrigger(CheckConditions,DontWaituntilitfinishes)CustomScript:"TriggerDestroy(lv_funcTrigger);"ElseUI-Display"Not enough resources. You require a..."foratoSubtitleareaPlayerGroup-Removeplayer(Triggeringplayer)froma
Do note that I haven't exactly copied all the new actions, but I wrote them from memory. So some things won't look exactly as I wrote them down, but it's close enough.
Let's quickly go over my additions:
//This will set funcName to a random integer and turn this integer into a string.SetVariable:funcName=String(RandomIntegerbetween0and99)//If funcName's string length is only 1 (read: if the number is less than 10) we have to add a 0 in front of//it since our functions are called r00, r01, etc and not r0, r1.If(LengthoffuncName==1)Thendo(Actions)ThenSetVariable:funcName="0"+funcNameElse//Now we use the aforementioned principle to create the actual name of the function. So //if the random number would be 8 ( 08 after we add the 0) then we'd assemble it:// "gt_r" + "08" + "_Func" --> "gt_r08_Func"SetVariable:funcName="gt_r"+funcName+"_Func"//Now we use custom script to set our local trigger variable to our trigger function.//The "lv_" in front of the variable name is just an indication that it's a Local Variable.CustomScript:"lv_funcTrigger = TriggerCreate(lv_funcName);"//Now we run our triggeTrigger-RunfuncTrigger(CheckConditions,DontWaituntilitfinishes)//Since we have created a new trigger which is only supposed to run this one time we//need to get rid of it again. Gotta destroy it (dont worry, it will be re-created next time this//trigger runs)CustomScript:"TriggerDestroy(lv_funcTrigger);"
If you have any questions ask away.
PS: You shoud make sure that there is no way this could accidently create a trigger that doesn't exist.
So don't try to run the r99 trigger when there is none.
Set the (Random Integer between 0 and x) to the max of triggers you've created till now. In your case it's probably 4 (including the 0).
PPS: Copy the custom script lines exactly how the are (the part between the two "). It should be correct that way and it's case sensitive. Also don't forget the semi-colon at the end.
Err, I'm really kind of noob with triggers and scripts, but what I'm trying to do is this:
I have a trigger that when run, picks a random trigger out of 5 or so and runs it. (I'm planning for 100 or so which is why I need help here) I have the 5 triggers named r00,r01,r02.. ..r04 etc. My random trigger goes as so.
Is there a way so instead of setting 100 variables to triggers I can change the:
Into something like:
Is there any way of doing this using custom script or whatnot?
Help greatly appreciated.
Probably not. In script I'm sure they don't call the activator by his name. r00 means nothing to the script, probably changed to another kind of ID.
That triggers are so different that you need to have them in different triggers? You can group them by similar functions and do another random inside the trigger for variations or something.
Give assigns each trigger to a non-array variable. So it's not that easy.
I can think of two ways to do that:
1) You create all your triggers in custom script and use one large trigger array to store them all. You would have to know quite a bit of Custom Scripting though.
2) The second way is actually a little trick. We can use a small custom script to quickly re-create one of the triggers and run it.
To key is knowing how GUI names all it's triggers in the background.
When I create a trigger called "Add Kill Score" then GUI calls these script actions to create it:
So it names the trigger variable "gt_<Our trigger name without spaces>"
And the actual name of the function that becomes our trigger is called "gt_<Out trigger name without spaces>_Func"
Now, the trigger variable is useless to use, but the function name is interesting.
We can predict the name of our trigger function.
r00 would be called "gt_r00_Func" and r01 is "gt_r01_Func". It's always the same principle.
Now we can predict the name of any function ourself by using a similar algorithm. Since our functions are all called r00, r01, r02 we can say that:
"gt_r<our random number here>_Func"
will give us our function name.
So we can create the random number and insert it into our string. The result would look like this:
Do note that I haven't exactly copied all the new actions, but I wrote them from memory. So some things won't look exactly as I wrote them down, but it's close enough.
Let's quickly go over my additions:
If you have any questions ask away.
PS: You shoud make sure that there is no way this could accidently create a trigger that doesn't exist.
So don't try to run the r99 trigger when there is none.
Set the (Random Integer between 0 and x) to the max of triggers you've created till now. In your case it's probably 4 (including the 0).
PPS: Copy the custom script lines exactly how the are (the part between the two "). It should be correct that way and it's case sensitive. Also don't forget the semi-colon at the end.