Unit Movement problems!

OneBadPsycho

10100111001
Reaction score
93
Hello, I have this problem; whenever my unit enters a region, I wan't him to move to a random region, however it may not move back to the region it came from and may not be sent to the same region as it enters.

I have this trigger:
Code:
Move
    Events
        Unit - A unit enters 1 <gen>
        Unit - A unit enters 2 <gen>
        Unit - A unit enters 3 <gen>
        Unit - A unit enters 4 <gen>
        Unit - A unit enters 5 <gen>
    Conditions
        (Unit-type of (Entering unit)) Equal to Footman
    Actions
        Set LocO = LocI
        Custom script:   loop
        Set LocI = (Random integer number between 1 and 5)
        Custom script:   exitwhen udg_LocO != udg_LocI
        Custom script:   endloop
        Unit - Order (Entering unit) to Move To Point[LocI]
        [COLOR="Red"]Game - Display to (All players) for 1.00 seconds the text: (String(LocI)) [I]//For debugging[/I]
        Game - Display to (All players) for 1.00 seconds the text: (|cffff0000 + ((String(LocO)) + |r)) [I]//For debugging[/I][/COLOR]

With this trigger it won't sent the unit to the same region as it enters, unless it is send like this:

view


The white numbers is the region numbers.
The black arrow indicates that the unit enters region 2. and are sent to region 4.
The red arrow indicates collision with region 1. and the unit is send to another region.


But when it enters region 1. the variable LocI is still 4 and the option of sending the unit to region 1. is still avaible.

Any help on fixing these bugs would be greatly appreciated.
 

Diamondeye

New Member
Reaction score
10
How about implementing an
if(Loc0==Loc1)
Do(run(This Trigger))
Else(normal trigger)

That way the trigger would rerun if the locations were the same, giving it a new place to go?
 

OneBadPsycho

10100111001
Reaction score
93
How about implementing an
if(Loc0==Loc1)
Do(run(This Trigger))
Else(normal trigger)

That way the trigger would rerun if the locations were the same, giving it a new place to go?

Thats what I do:
Code:
        Custom script:   loop
        Set LocI = (Random integer number between 1 and 5)
        Custom script:   exitwhen udg_LocO != udg_LocI
        Custom script:   endloop
The loop exits when LocO is not equal to LocI
 

Choppa

www.warcraft-gamers.po.gs
Reaction score
59
This is as far as I got before getting bored, lol it's so half ass...
 

Attachments

  • Choppas RandomButNotPreviousRegionEnterer.w3x
    18.2 KB · Views: 102

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Basically, you have a set amount of options, except for 2. The region you came from, and the region you're in. You have 5 regions, so we'll create an array of 3 choices.

We need an integer to store what region you came from. We'll call this "from". We also need an integer to store what region we're heading to, so we'll call this "from".

Now let's try writing the code.

We have our choices inside the array, so let's set a temporary variable to a random number between 1 and 3.

We want to set our "from" variable to our to variable, since we have arrived at our destination, and want to head to a new one. However, we'll need to keep the from variable, since when the unit arrives at the next place, our old from will now be a valid destination. We can do this by setting a temporary variable to "from", and then setting "from" to "to".

Now we'll need a new target location. Let's get a random array index:
set to = choices[rand]

Now we want to replace the array member of the choice we just made with our temporary variable, so that it will become valid for next time:
set choices[rand] = temp

Now we can order the unit to move to "to".

Here's a basic outline for the code:

JASS:
globals
    array choices = (1,2,3)
    from = 5
    to = 4
    rand
    temp
endglobals

Actions
    set rand = Random(1,3)
    set temp = from
    set from = to
    set to = choices[rand]
    set choices[rand] = temp
    call MoveTo(to)
 

OneBadPsycho

10100111001
Reaction score
93
Uhm, thanks for the code Darthfett, but it only fixes one of my problems. ^^
Now the unit won't be send back to the previous region or the same as it enters, but if this situation happen:
(Pic from 1st post)
view

The white numbers is the region numbers.
The black arrow indicates that the unit enters region 2. and are sent to region 4.
The red arrow indicates collision with region 1. and the unit is send to another region.
There is still a chance that the unit will be send to the same region as it enters because the trigger "thinks" it has reached its destinated region.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
EDIT:

Ah. Well add an attachment to the unit somehow (you can use custom value if you like), and compare it with the entered region. If the unit's custom value is 1, and the region is 1, then allow the actions to run, but don't allow the actions to run if the unit's custom value is 4, and he enters region 1.
 

OneBadPsycho

10100111001
Reaction score
93
With the code I gave you, both the "to" and "from" region are not included in the list of options. Try "running" the code I wrote by putting in the numbers.

I did this:
Code:
Move Copy
    Events
        Unit - A unit enters 1 <gen>
        Unit - A unit enters 2 <gen>
        Unit - A unit enters 3 <gen>
        Unit - A unit enters 4 <gen>
        Unit - A unit enters 5 <gen>
    Conditions
        (Unit-type of (Entering unit)) Equal to Footman
    Actions
        Set rand = (Random integer number between 1 and 3)
        Set temp = From
        Set From = To
        Set To = choices[rand]
        Set choices[rand] = temp
        Unit - Order (Entering unit) to Move To Point[To]
        Game - Display to (All players) for 1.00 seconds the text: (String(To))
        Game - Display to (All players) for 1.00 seconds the text: (|cffff0000 + ((String(From)) + |r))

-and it doesn't seem to work.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Those are actual variables, right?

Make sure "from" and "to" are set to a starting number (in my example, I used 5 and 4), and that choices[1],choices[2],and choices[3] are set to the other three numbers that "from" and "to" are not using.
 

OneBadPsycho

10100111001
Reaction score
93
Those are actual variables, right?

Thats right.

Make sure "from" and "to" are set to a starting number (in my example, I used 5 and 4), and that choices[1],choices[2],and choices[3] are set to the other three numbers that "from" and "to" are not using.

Everything is fine, but how would I implement the custom value thingy?

-Sorry for being this stupid. XD
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Thats right.



Everything is fine, but how would I implement the custom value thingy?

This doesn't work:
Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    If - Conditions
        (Custom value of (Entering unit)) Not equal to To
    Then - Actions
        Skip remaining actions
    Else - Actions

Add
Code:
 (Custom value of (Entering unit)) Equal to To
To the conditions, and
Code:
Set the Custom Value of (Entering unit) to To
To the actions (don't forget that the unit has to start out with To as his custom value, otherwise you'll never start this system-loop).

Potential problem: The original code I gave you won't work with multiple units. You'd have to get an attachment system for that.
 

OneBadPsycho

10100111001
Reaction score
93
Add
Code:
 (Custom value of (Entering unit)) Equal to To
To the conditions, and
Code:
Set the Custom Value of (Entering unit) to To
To the actions (don't forget that the unit has to start out with To as his custom value, otherwise you'll never start this system-loop).

Potential problem: The original code I gave you won't work with multiple units. You'd have to get an attachment system for that.

I'm sorry to say this, but it doesn't work. ^^

-and I know why: The condition
Code:
(Custom value of (Entering unit)) Equal to To
will always be true.
 

Choppa

www.warcraft-gamers.po.gs
Reaction score
59
You have to have a group of regions that the unit can go to, and each time he enters a region that specific region is taken out of the group of random choice that he can be ordered to, that is what I was getting at before I got bored.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top