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: 101

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.

      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