Dice Roll

Phil

New Member
Reaction score
0
Hey, I'm trying to create a dice roll that will "unlock" a door. Essentially they will be walking up to a door and then type -rollunlock and if the random roll is high enough they will be able to enter. I have setup a region infront of the door and have tried to experiment with it but that random number seems to be stumping me.

I've created a variable called DiceRoll which has "Set DiceRoll = (Random integer number between 1 and 8)" typed into the Initial Value. I have it connected to a floating text action so I might see the random number it creates before going forward with attaching it to the door. Currently all I get is exactly what I've typed in as the initial value.

This is a major thing that is stopping me from creating my map, especialy as I will be making dice rolls a major part of my map. I am a COMPLETE noob in this subject, in fact I have just jumped on and i do not have much knowledge in this. Suggestions as to where to go for tutorials and knowledge about this subject, and others, would also be helpful.
 

futeki

Active Member
Reaction score
4
Hi there and welcome!

Firstly, on map making be sure you spend time learning good practices, starting with memory leaks. You can find info about them and how to handle them here.

Lastly, on your issue, I'd suggest you post your trigger here. You can do so by right-clicking the title of your trigger in the Trigger Editor, and clicking "Copy As Text" and then pasting it here inside of a reply within the "WC3 GUI Tags" -- the icon looks like a giant "a". Without seeing your triggers, most will be unable to help.
 

Phil

New Member
Reaction score
0
Trigger

Thank you for the help as well as the welcome futeki!

Here is my trigger.


Trigger:
  • RollurDie
    • Events
      • Player - Player 1 (Red) types a chat message containing -rollunlock as An exact match
    • Conditions
    • Actions
      • Floating Text - Create floating text that reads DiceRollx2 at (Center of Region 000 <gen>) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
 

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
Inside the actions category there's a "set variable" action. You can use this to set any variable to a value.

Trigger:
  • Set diceroll = (Random integer number between 1 and 10)
 

Okay

New Member
Reaction score
2
If this is the only trigger you have, then there is clearly a problem. This is what you need to do

create a variable of type integer and name it whatever you want

then your trigger should be this:

Trigger:
  • RollurDie
    • Events
      • Player - Player 1 (Red) types a chat message containing -rollunlock as An exact match
    • Conditions
    • Actions
      • Set Dicerollx2 = (Random integer number between 1 and 8)
      • Floating Text - Create floating text that reads (String(Dicerollx2)) at (Center of (Region 000 <gen>)) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency


You might want to also code in a way to know if player 1 is actually at the region. For example have 2 extra triggers, 1 doing a unit enters the region turn on the trigger, the other unit leaves the region, turn off the trigger. You would need to have it initially off. Or you could do a condition, number of units in unit group units owned by player 1 in the region is greater than or equal to 1.

I think that you might have made your variable a string variable instead of an integer. You can't put a formla into a integer variable, you need to randomize it every time you use it.
 

Phil

New Member
Reaction score
0
Thank you so much AoW_Hun7312 and Okay for the information.

and Okay you read my mind. I was going to set up a regioned area were they would have to walk in and type so that I could restrict the use of the command. Don't need them unlocking all the doors at once lol.

Thanks again.
 

Okay

New Member
Reaction score
2
Well actually you said so in your first post. But anyway, if you want me to make an example of how you could do that, just ask.

And just some advice: you should start with something simple, play around with the object editor and trigger editor so you can get used to it before you try anything complex. You might want to read some of the great tutorials here or elsewhere, but they are not necessary.

EDIT: Oh I forgot to add, if you are looking for some good tutorials, you can go to the tutorial and resources section and go to the tutorial repository, or you can go to the link world edit tutorials that is along the left edge under affiliated sites, there are some great tutorials there
 

Phil

New Member
Reaction score
0
Well Ok.

I've tried as much as I can with these 2 Triggers to get this door to work, and nothing. I can't seem to get my RollUnlock trigger to turn on. I've changed up my RollUnlock a bit as I've read about Memory Leaks. So here is what I have

The new RollUnlock
Trigger:
  • RollUnlock
    • Events
      • Player - Player 1 (Red) types a chat message containing rollunlock as An exact match
    • Conditions
      • (This trigger) Equal to Unlock Door1 On <gen>
    • Actions
      • Set DiceRoll = (Random integer number between 1 and 10)
      • Floating Text - Create floating text that reads (String(DiceRoll)) above Blood Mage 0001 <gen> with Z offset 0.00, using font size 10.00, color (0.00%, 100.00%, 0.00%), and 0.00% transparency
      • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
      • Wait 2.00 seconds
      • Floating Text - Destroy (Last created floating text)
      • Set DiceRoll = 0


Here is what I have for the turn off
Trigger:
  • Unlock Door1 Off
    • Events
      • Map initialization
      • Unit - A unit leaves Region 000 <gen>
    • Conditions
    • Actions
      • Trigger - Turn off RollUnlock <gen>


Here is what I have for the turn on
Trigger:
  • Unlock Door1 On
    • Events
      • Unit - A unit enters Region 000 <gen>
    • Conditions
    • Actions
      • Trigger - Turn on RollUnlock <gen>


and here is what I have for the door to open

Trigger:
  • Door1 Open
    • Events
      • Player - Player 1 (Red) types a chat message containing rollunlock as An exact match
    • Conditions
      • DiceRoll Greater than or equal to 3
    • Actions
      • Destructible - Open Demonic Gate (Horizontal) 0003 <gen>


I think this will be the last post for the day. I will keep trying and get back to this Thread ASAP.
 

Okay

New Member
Reaction score
2
Your second and third triggers should work fine, but there are some problems with your other 2

Trigger:
  • RollUnlock
    • Events
      • Player - Player 1 (Red) types a chat message containing rollunlock as An exact match
    • Conditions
      • (This trigger) Equal to Unlock Door1 On <gen>
    • Actions
      • Set DiceRoll = (Random integer number between 1 and 10)
      • Floating Text - Create floating text that reads (String(DiceRoll)) above Blood Mage 0001 <gen> with Z offset 0.00, using font size 10.00, color (0.00%, 100.00%, 0.00%), and 0.00% transparency
      • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
      • Wait 2.00 seconds
      • Floating Text - Destroy (Last created floating text)
      • Set DiceRoll = 0

Your condition is messed up. It says "if the trigger Rollunlock is the same trigger as the trigger unlock door1 on, then and only then will this trigger run"
Well obviously those 2 triggers are not the same trigger, so it will never run. You are trying to do a check to see if the trigger has been enabled, but that is unnecessary. By turning it off, it will never run until turned back on. So in otherwords, just get rid of your condition and don't worry about why if you don't understand.
You should also turn off your first trigger as its first action, and turn it back on as its last. This is so that the player can't have multiple floating texts at the same time, causing some to never be deleted.
Setting DiceRoll to 0 at the end of your trigger has no practical reason.
Also, for turning off your first trigger, instead of running your turn off trigger at map initialization, just uncheck the box in the editor that says initially enabled

And just get rid of your last trigger. Instead, add to your first trigger (making sure that it is after setting your variable) the if/then/else action if DiceRoll greater than or equal to 3 then do open demonic gate, else do nothing

Finally, you might want to name your regions, or else it might get confusing later if you add more regions.
 

Moridin

Snow Leopard
Reaction score
144
Phil you do not need more than 1 trigger to manage this. Just saying ;).

Try this out:
Note: Freehand (I didn't actually open the editor, I typed this out, so the wording might not be exact)

Trigger:
  • RollUnlock
    • Events
      • Player - Player 1 (Red) types a chat message containing -rollunlock as An exact match
    • Conditions
    • Actions
      • If (Multiple conditions are true) then do (then actions) else do (else actions)
        • If - Conditions
          • (Triggering unit is in Region 000 <gen>) Equal to True
        • Then - Actions
          • Set DiceRoll = (Random integer number between 1 and 10)
          • Floating Text - Create floating text that reads (String(DiceRoll)) above (Triggering unit) with Z offset 0.00, using font size 10.00, colour (0.00%, 100.00%, 0.00%), and 0.00% transparency
          • Floating text - Change (last created floating text): Disable Permanence
          • Floating text - Change the lifespan of (last created floating text) to 3.00 seconds
          • If (All conditions are True) then do (then actions) else do (else actions)
            • If - Conditions
              • (DiceRoll Greater than or Equal to 3)
            • Then - Actions
              • Destructible - Open Demonic Gate (Horizontal) 0003 <gen>
            • Else - Actions
              • Set Player_Group = (All players matching ((Matching Player) is Equal to (Triggering Player))
              • Game - Display to Player_Group the text "Sorry, you didn't roll high enough"
              • Custom script: call DestroyForce( udg_Player_Group )
        • Else - Actions
          • Set Player_Group = (All players matching ((Matching Player) is Equal to (Triggering Player))
          • Game - Display to Player_Group the text "You need to be closer to the gate!"
          • Custom script: call DestroyForce( udg_Player_Group )


Alright, now to explain certain actions and conditions.
First, the variables I used:

DiceRoll - Integer variable
Player_Group - Player_Group variable

--------------------------
Secondly, a few explanations:

Any custom script you see in that trigger is to remove leaks. For a detailed explanation on what leaks are and how to remove them, you can look here. :)

I would suggest not using a wait anywhere in your trigger, as that might not go as planned. Let's say after player 1 types -rollunlock, you have some other trigger that also spawns floating text. Suddenly, the roll unlock text is not the last created floating text, meaning it won't get destroyed and will just hang around. It's always easier just to give the floating text a lifespan. Adding a lifespan to the floating text automatically gets it destroyed after a specific amount of time, meaning it isn't a hassle to you anymore.

You do not need to set DiceRoll back to 0, because it will keep resetting itself anyway everytime the person types the command.

If you have any problem locating a condition or an action, ask here and I'll direct you to it.

One thing you might want to do is add a cooldown. With the current trigger, the person can keep spamming -rollunlock and he will eventually get a good roll, even if he's extremely unlucky. If you need a cooldown, you will require a timer.

Another thing I wanted to ask is, do you have more than 1 player in your map? You must keep in mind that this trigger will only work for 1 player (that being player 1 (red) specifically).
 

Okay

New Member
Reaction score
2
Trigger:
  • Actions
    • If (Multiple conditions are true) then do (then actions) else do (else actions)
      • If - Conditions
        • (Triggering unit is in Region 000 <gen>) Equal to True

No that is wrong. There is no triggering unit mentioned in the trigger, so it won't work right

if you did that, (which is unnecessary but fine) you would need to use this condition instead
Trigger:
  • (Number of units in (Units in (Region 000) owned by Player 1 (Red))) Greater than or equal to 1
 

Moridin

Snow Leopard
Reaction score
144
I'm sorry, I forgot to mention in my explanation that you would need to save the specific unit in a variable and use that instead of triggering unit. :p
 

Phil

New Member
Reaction score
0
Thanks for clarifying that. Would not of caught that on my own lol. And thanks for jumping in on the thread moridin, I appreciate the input.
 

Phil

New Member
Reaction score
0
Well I"m working on a new part to game. I wanted the person to walk up to the door and roll to try and open it with a STR roll and find it's locked. That works. But when I have him try to unlock it, the second message I have written down does not show. I'm unsure if it is simply that I have it on an auto time text message and simply need to put in a timed one to get rid of the old one fast enough or if it has to do with something else.

I'm now using Variables

StrRoll / Integer
DiceRoll / Integer
Locked_Door / Boolean / set to False
Players_Group / Player Group
Speach2 / Player Group


Here is my Doors Locked Trigger. I have it check a boolean called locked to see if it is locked. Its a little backwards as locked is false and open is true. But I will fix that later. It then runs an animation and gives text stating the door is locked. This runs fine I just wanted to put it on here so that you might be able to see the Locked Variable.

Trigger:
  • Doors Locked
    • Events
      • Player - Player 1 (Red) types a chat message containing open as An exact match
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Locked_Door Equal to True) and ((Region 000 <gen> contains Blood Mage 0000 <gen>) Equal to True)
        • Then - Actions
          • Set StrRoll = (Random integer number between 1 and 10)
          • Floating Text - Create floating text that reads (String(DiceRoll)) above Blood Mage 0000 <gen> with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 0.00%), and 0.00% transparency
          • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • StrRoll Greater than or equal to 3
            • Then - Actions
              • Destructible - Open Elven Gate (Horizontal) 0000 <gen>
            • Else - Actions
              • Set Player_Group = Player Group - Player 1 (Red)
              • Game - Display to Player_Group the text: "Too weak"
              • Animation - Play Elven Gate (Horizontal) 0000 <gen>'s Stand Hit animation
              • Custom script: call DestroyForce( udg_Player_Group )
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Region 000 <gen> contains Blood Mage 0000 <gen>) Equal to False) and ((Region 001 <gen> contains Blood Mage 0000 <gen>) Equal to False)
            • Then - Actions
              • Set Player_Group = Player Group - Player 1 (Red)
              • Game - Display to Player_Group the text: "You need to get cl...
              • Custom script: call DestroyForce( udg_Player_Group )
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Region 000 <gen> contains Blood Mage 0000 <gen>) Equal to True) and ((Region 001 <gen> contains Blood Mage 0000 <gen>) Equal to False)
            • Then - Actions
              • Set Player_Group = Player Group - Player 1 (Red)
              • Animation - Play Elven Gate (Horizontal) 0000 <gen>'s Stand Hit animation
              • Game - Display to Player_Group the text: "Door is Locked!"
              • Custom script: call DestroyForce( udg_Player_Group )
            • Else - Actions



Now here is my Rollunlock1 Trigger

I can't seem to get the text "Click! Door unlocked" when they have unlocked the door. Why not? It works when I walk straight up to the door and unlock it, but not after my previous text states that it's locked.

Trigger:
  • Rollunlock1
    • Events
      • Player - Player 1 (Red) types a chat message containing unlock as An exact match
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Blood Mage 0000 <gen> is in (Units in Region 000 <gen>)) Equal to True
        • Then - Actions
          • Set DiceRoll = (Random integer number between 1 and 10)
          • Floating Text - Create floating text that reads (String(DiceRoll)) above Blood Mage 0000 <gen> with Z offset 0.00, using font size 10.00, color (0.00%, 100.00%, 0.00%), and 0.00% transparency
          • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • DiceRoll Greater than or equal to 1
            • Then - Actions
              • Set Speach2 = Player Group - Player 1 (Red)
              • Set Locked_Door = True
              • Game - Display to Speach2 the text: "Click! Door unlock...
              • Custom script: call DestroyForce( udg_Speach2 )
            • Else - Actions
              • Set Player_Group = Player Group - Player 1 (Red)
              • Game - Display to Player_Group the text: "Sorry, you didn't ...
              • Custom script: call DestroyForce( udg_Player_Group )
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Region 000 <gen> contains Blood Mage 0000 <gen>) Equal to False) and ((Region 001 <gen> contains Blood Mage 0000 <gen>) Equal to False)
            • Then - Actions
              • Set Player_Group = Player Group - Player 1 (Red)
              • Game - Display to Player_Group the text: "You need to get cl...
              • Custom script: call DestroyForce( udg_Player_Group )
            • Else - Actions
 

Moridin

Snow Leopard
Reaction score
144
Alright, looked through your triggers and I can't really see what might go wrong. The two triggers shouldn't interfere with each other in any way really....

Try debugging your code. You can do this by using "Game - Display to ____" text messages so you know exactly where the trigger goes when it fires. That way you can see exactly where its not supposed to stop/run.

Also, rename that Locked_Door variable of yours to Open_Door please :p. It really confused me twice.
-------------------
A small suggestion, when you have if conditions like this:

Trigger:
  • (Locked_Door Equal to True) and ((Region 000 <gen> contains Blood Mage 0000 <gen>) Equal to True)

You can place both conditions on seperate lines. That's automatically connected by an AND. You can also use Or - multiple conditions, to place conditions with an OR between them. Placing them on seperate lines makes it easier to read as well as easier to edit/delete. Right now if you had to delete one condition you'd have to remake the other. Something like this would work:

Trigger:
  • Locked_Door Equal to True
    • (Region 000 <gen> contains Blood Mage 0000 <gen>) Equal to True
 

Phil

New Member
Reaction score
0
Thanks for the help Moridin. I've been quite busy lately and have had no time for my map, :( But as soon as I can I will make the nesseary corrections as to not confuse more people looking at my program and will also try out that Game-text code you suggest.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top