• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Guards?

Status
Not open for further replies.
Level 3
Joined
Oct 30, 2005
Messages
51
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?
 
Level 7
Joined
Mar 12, 2006
Messages
407
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 ^^
 
Level 7
Joined
Jul 30, 2004
Messages
451
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
 
Level 3
Joined
Oct 30, 2005
Messages
51
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
 
Level 6
Joined
Feb 18, 2005
Messages
263
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
 
Level 7
Joined
Jul 30, 2004
Messages
451
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
 
Level 3
Joined
Oct 30, 2005
Messages
51
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:
 
Status
Not open for further replies.
Top