Warcraft III resources & community, 2003–2006 · archived

Guards?

10 posts
#1

Guards?

Hi all. I had this idea of creating a map while i was in my class. But while brainstorming, i met this small problem. I thought of adding mercenary units that serve as guards. But only that when you buy them, they aren't yours. They become sorta like under the control of a computer. They follow you everywhere and stuff like that. If you move away from a fight, they'll follow you. Something like the mercenaries in diablo II. The only problem is, my triggering aint too good, but i'll just show you guys what i've brain stormed. I havent figured out the creating the guard for the computer player trigger. I'm just worrying about the intelligence of the guard.



Event:
Every 5 seconds
Condition:
none
Action:
-If <purchasing unit> (purchasing unit refers to the guy who bought the guard.) is moving ( i dont know if this is possible)
-Then order <guard> to follow <purchasing unit>
-Else do nothing

-If <purchasing unit> is attacked
-Then order <guard> to attack ground position of <purchasing unit>
-Else do nothing



I dont know if this will work or not, can someone help me?
#2
just order the merc to right click the hero every X seconds (unit - issue order targeting a unit => right click) units that are right clicked on another unit do the same as that leading unit does
#3
Trigger 1:

Event: Unit sells a Unit (your merc)

Actions:
Set sold unit = merc[x] (if u want multiple merc you need an array here)
Unit - change owner of merc[x] to Player X
set chief[player string] = buying unit
Unit - issue order merc[x] to follow chief[playerstring]



Trigger 2:
Event:
Periodic all y - secs

Action:
Loop:
issue order merc[integer A] to follow chief[player string]


----
Should be like that. Note that you will need to include the owner of merc in the array for multiplayer... like array for merc 1 player 1 = 1001
array for merc 7 player 3 = 3007 or something like that.

Hf ^^
#4
Why so difficult if u can do it so easy? when a hero buys the merc, set the merc to a var and the hero to a var and just order the merc to right click the hero every X seconds, this really works
#5
would probably be better to get the merc to

if distance from merc to player > X
- disengage merc, ie, make it move to player
else
- order merc to attack move to a position around the player

you know, so it'll keep fighting even if hte player backs off a bit but flees with the player runs completely
that and it'll chase stuff for abit till it gets too far
#6
hmmm. . .Good idea raptor. . . Why didnt i think of that. . .But what if it's like say multiple mercs? After i buy a merc, it gets shifted to a another uncontrollable plaer but then what's the trigger to move all of them to the uncontrollable player? Is the trigger like this:


Event:
A unit is sold
Condition:
Blah blah blah
Action:
Add unit to unit group <Player X mercs>
Change sold unit to colour of Player X
#7
i know of several ways to do this.
1st go to the downloadsection - spells and downlaod the guard spell from there. its already done
2nd use the search function. this question has been asked several times
3ed think how you would do it ingame and try to recreate your actions with triggers
4th use the gui like said above
5th use jass - here the semi code how i would put it:

//this initialises the whole stuff
function init_guard takes unit WhichHero returns nothing
//store within the gamecache the hero for each player
//refresh that whenever the hero changes
//you need to use the returnbug function to convert unit - integer and vise versa i call it 'U2I' and 'I2U'
//eg
StoreInteger(I2S(U2I(WhichHero)),I2S(<number of guards that unit has>, 0)
endfunction

//call this function as often as you see required to keep the units guarding
function refresh_guard takes unit WhichHero returns nothing
//now order each unit stored in the gamecache to 'rightclick' on the hero
//eg
local unit tmp_unit
local integer a
loop
set a = a + 1

set tmp_unit = I2U(GetInteger(I2S(U2I(WhichHero)), I2S(a))
//if tmp_unis is alive - order it 'rightclick' on WhichHero

exitwhen a = <number of guards>
endloop
endfunction

//use this function whenever a new guard is aquired
function add_guard takes unit WhichHero, unit WhichGuard returns nothing
set <number of guards for this unit> = <one more than before>
StoreInteger(StoreInteger(I2S(U2I(WhichHero)),I2S(<number of guards that unit has>, U2I(WhichGuard)))
endfunction


this code does NEVER decrease the number of guards, for that would require getting rid of dead saved units, even though it is faster when many guards have been used
#8
well, i mean jass is dandy and all, but i'm going to make the bold assumption that he doesn't know it and would rather use something like...

when unit is bought, add unit to ugroupMercs[player num of hiring]

every whatever time,
for A 1 to maxplayers
pick all units from ugroupMercs[A]
do whatever you want (or what i said earlier) with picked unit
endpick
endloop

of course this only works for one hero at a time per player, if you want multiple heroes to have their own guards its better to do the jass thing

and just a question,
set tmp_unit = I2U(GetInteger(I2S(U2I(WhichHero)), I2S(a))
i'm not familiar with GetInteger(n, s), whats it do? i just don't memorize a lot of jass functions to begin with, although i couldn't find this one in the API

although i'd recommend using functions
IncrementNumGuards(unit, guard)
DecrementNumGuards(unit, guard)
EnumerateGuards(unit) <-- this one so you can easily deal with any number of guards without having to actually worry about array stuff or removing guards in the middle of an array
#9
amazing raptor, you're right. . . I dont know jack about jass. . . :lol: but then again, i dont know much about array variables. So i'm heavily dependant on GUI :cry:
#10
an array variable IS GUI. its just a variable that uses a number so u can store alot in it