HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

random unit changing ownership

06-07-2004, 09:47 PM#1
xtacb
in my map all units are placed already, there are 2 armies aposing each other on a battlefield

as the game starts each players gets one of the generals on either side

i set all the generals to heroes array
Code:
Events
    Time - Elapsed game time is 0.01 seconds
Action - 
set heroes[1] = first general 
set heroes[2] = second general 
set heroes[3] = third general
N = 3

for player 1 the trigger is
Code:
Event- Time - Elapsed game time is 0.02 seconds
Set rnd = (Random integer number between 1 and N)
Unit - Change ownership of heroes[rnd] to Player 1 (Red) and Change color
Set N = (N - 1)


thats basically same structure for all the players (except for 2 which are the 2 computers armies)
then few seconds later alliances are set by setting all the players on each side to be allied

the problem is that sometimes, when i test it, (as player 1 red) i get no hero changed to my control (the entire map is covered in fog of war)
im not sure why it doesnt give me a hero, is there something im missing?
06-07-2004, 10:14 PM#2
PatruX
I'm not quite sure about that (Random integer number between 1 and N) aswell as Change ownership of heroes[rnd]
06-07-2004, 11:08 PM#3
xtacb
Set rnd = (Random integer number between 1 and N)
works, along with create hero(rnd) works for creating random heros from a unit group , that how u pick random heros from a unit group

i think its just not changing the unit control over because i split it into 2 triggers and
Code:
Time - Elapsed game time is 0.02 seconds
Set rnd = (Random integer number between 1 and N)
Set unittogive[1] = heroes[rnd]
Set N = (N - 1)

Code:
Time - Elapsed game time is 0.50 seconds
Game - Display to (All players) the text: (Name of unittogive[1])
Unit - Change ownership of unittogive[1] to Player 1 (Red) and Change color


it displays the unit's name but then it doesnt change owner of the unit because its all still fog of war
why sometimes it doesnt change the owner?
06-08-2004, 12:00 AM#4
johnfn
Can I see the map? To be honest, I just gave this code a 3 minute long hard stare without me seeing anything.

If your protective (and you have every right to be) then why dont you try making the unit die, and typing in the cheat "i see dead peopl" [no "'s] and see if anyone dies.
06-08-2004, 12:12 AM#5
yotaku
What is stopping it from changing the owner of the same unit twice?

For player one, it randomly selects heros[2] and gives that to player one.
Then for player two, it randomly selects heros[2] and gives that to player two.

Now player 1 is left without a hero.
06-08-2004, 12:28 AM#6
Nabren
Quote:
Originally Posted by yotaku
What is stopping it from changing the owner of the same unit twice?

For player one, it randomly selects heros[2] and gives that to player one.
Then for player two, it randomly selects heros[2] and gives that to player two.

Now player 1 is left without a hero.

That's exactly what's going on. I read the trigger and this will happen. What you should do is set the units to a neutral computer player in the editor without triggers, and then when giving the unit to someone else just add a condition that the unit belongs to the neutral computer player, if it doesn't, it's already been given to someone and you need to reroll your number.
06-08-2004, 12:49 AM#7
xtacb
yea maybe thats whats happening, but doesnt set N=N-1 remove that unit from the array?
i had a random hero being created in my other map that was the same thing except instead of change owner of heroes[rnd] it was create heroes[rnd] for player and it worked fine
and there were no doubles because N=N-1 was supposedly removing the unit from the array as it was picked


how should i check condition if the unit is owned by neutral player then if not then reroll?
and all the players slots are used (10 players with 1 computer player for each side) theres player 4(purple) computer then theres player 11(light blue) computer
how would i check if a hero is owned by either and then if not get it to repick/reroll?
06-08-2004, 01:02 AM#8
Nabren
Your logic is flawed. Let me walk you through it.

N=3

Random number between 1 and N(3) comes up 2.

Now, N=N-1, now N=2.

So next time it's

Random number between 1 and N(2) and again comes up 2, so the same hero is given to a different player.

What you really need is what I suggested or add a history array and each time you random a number, add it to that and then compare the two numbers to make sure it hasn't been chosen. Example(modifying your code) use the multiple if/then/else action, for this you will need an integer array called randomHistory of size 3 and an index integer set to 0:

Events
Time - Elapsed game time is 0.02 seconds
Actions
Set rnd = (Random integer number between 1 and N)
Set randomHistory[index] = rnd
Set index = index + 1
If
randomHistory[0] = rnd
randomHistory[1] = rnd
randomHistory[2] = rnd
Then
set index = index -1 <-- need to reset index variable back one so it doesnt get higher than the actual array
Trigger - Run(This Trigger) (Ignoring Conditions)
Else
Unit - Change ownership of heroes[rnd] to Player 1 (Red) and Change color

If you need further help let me know.
06-08-2004, 01:25 AM#9
xtacb
hmm... well N=N-1 worked for my other map just fine , heros were always random and never doubles either (i didnt really understand how N=N-1 would remove it from array but it worked and i got the code while ago from some guy that was a mod or something)

ok, i just thought of something, should be simpler too

Player 1
Code:
Time - Elapsed game time is 0.02 seconds
Condition-
Action-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    If - Conditions
        (Random integer number between 1 and 2) Equal to 1
    Then - Actions
        Unit - Change ownership of (Random unit from (Units owned by Player 10 (Light Blue) matching (((Matching unit) is A Hero) Equal to True))) to Player 1 (Red) and Change color
    Else - Actions
        Unit - Change ownership of (Random unit from (Units owned by Player 4 (Purple) matching (((Matching unit) is A Hero) Equal to True))) to Player 1 (Red) and Change color

that should work right? doesnt need variables either
06-08-2004, 01:39 AM#10
Nabren
That would work, but only on two heroes, and you would have to create seperate heroes so other players could get some too.
06-08-2004, 01:44 AM#11
xtacb
doesnt it pick from all the heroes available to each side? purple and light blue have 8 heroes each
the If - Conditions
(Random integer number between 1 and 2) Equal to 1
is just to determine which side the player will be on (whether they pick a hero from purple or light blue)
06-08-2004, 02:00 AM#12
Nabren
Quote:
Originally Posted by xtacb
doesnt it pick from all the heroes available to each side? purple and light blue have 8 heroes each
the If - Conditions
(Random integer number between 1 and 2) Equal to 1
is just to determine which side the player will be on (whether they pick a hero from purple or light blue)

OOOOHHHH, ya, just reread it. That would work SUPER.