• 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.

How can I make a 'training' system like in Battle Realms?

Status
Not open for further replies.
Level 1
Joined
May 10, 2004
Messages
2
-Sorry but I'm afraid I wasn't specific enough.

I'd like the buidings to be 'buildable' by the player and work in essentially the same way as the undead sacrificial pit.-



I'd like to implement a system like the one found in Battle Realms in one of my maps - but its proving somewhat more complicated that i'd expected. What I essentially want to be able to do is this:


1. The only unit the player can recruit are villager units that are useless in themselves.

2. These villages must go to specific buildings to recieve training - in order to become specialised units (e.g. go to the barracks to become a soldier).

3. The villager disapears into the aforementioned building and comes out as a different unit.


I thought that this could be done by using modified sacrificial pits that 'sacrifice' the villages unit - replacing them with another one. However, there is no way to specify what unit they are 'sacrificed' into so they simply become shades. Is there any way to resolve this?

I attempted to use triggers but it hasn't worked so far.
 
Level 2
Joined
Apr 8, 2005
Messages
10
I got it

OK, I did some playing around and came up with a good answer to # 2 and 3.
Code:
EVENT
        Units-A unit enters {region}
CONDITIONS
        Unit-type of (triggering unit) equal to {type}
ACTIONS
        Unit-Hide(Entering unit)
        Wait x seconds (<- Training time)
        Unit-Replace(Entering unit) with {new type)      using blah,blah,blah...
        Unit-Unhide(Entering unit)
The regoin has to go around where the building is.
I made this code in a minute or two so i think there may be a problem mainly with hideing and unhiding. I think that can cause a memory leak if you have a lot of units training (i mean about 100). I can give you another code if you want that does not have this problem(but you have to add landscape objects) but then again i don't now for sure if this code can cause a memory leak. I hope this helps
 
Level 6
Joined
Mar 25, 2005
Messages
304
Yea that should work. You could also probably also have it so when the unit enters the building area, you can control the building, and then you can train the unit you want. (Ex: Villager enters barracks. Barracks becomes your control. You can choose archer, footman etc. Once one unit is trained, the ownership of the building defaults back to a computer.) That'd give you more option. Trigger would look something like:
Event: Unit enters region X
Condition: Unit type=X/Owner of the entering unit=player 1
Action: Change the ownership of X building to Player X and maintain color.
Then you'd need a second one to default the building back. Good luck
-Blue
 
Level 1
Joined
May 10, 2004
Messages
2
I really appreciate your advice - but I'm afraid I wasn't specific enough.

I'd like the buidings to be 'buildable' by the player and work in essentially the same way as the undead sacrificial pit.
 
Level 2
Joined
Apr 8, 2005
Messages
10
Looked around

I looked around and came up with what i think you need too do. Go the the spell forums and ask because your asking for spells to change a unit to another type and the sacrifist pit has that spell but you need a good spell maker to change that spell to make new units.
 
Level 7
Joined
Jul 30, 2004
Messages
451
heres a way, by all means not the definite way just something i came up with really fast on the spot

give the building cargo hold

Code:
//Trigger catches loading of civilians into a
//barracks and makes barracks have more 'supply' left
E: a unit is loaded into a transpot
C: unit type of transporting == whatever (barracks)
   unit type of loaded == whatever (guy)
A: remove loaded unit
   unit - set custom value of transporting unit to (custom value of transporting unit + 1)
   //this part maybe theres a better way, enable this building to build at least
   unit - unpause transporting unit

//Catches a unit being built, reduces 'supply' of
//barracks
E: a unit is trained
C: training unit == barracks
A: unit - set custom value of transporting unit to (custom value of transporting unit - 1)
   if (custom value of transporting unit == 0) then
       unit - pause training unit
   else
       do nothing
   endif

if theres a better way to disable a building from training units then use that instead of pausing the unit, that was just the only way i could think of right now

if you don't want to have to build the unit and simply want it to come out later, then 2 options i can give you

first, timed output, rather simple, replace second trigger
Code:
E: periodic every 15 seconds
C:
A: custom: local unitgroup g = all units of type barracks
   custom: local location p
   pick all units in g and do
       if custom value of picked unit > 0 then
           p = position of picked unit
           create 1 soldier at p for owner of picked unit
           custom: call RemoveLocation( p )
       else
           do nothing
       endif
   endpick
   custom: call DestroyGroup( g )

or, on an in-out basis, this set replaces everything no need for above triggers

Code:
//CUSTOM SCRIPT**
//This function creates specified unit type at the
//position of a building after a set time delay, if the
//building unit is dead it doesn't create the unit
//NOTE: i dunno if unittype is a real type, if not
//i'll have to check that out and change it, but the
//principle is there
function createUnitBasis takes unittype ut, real time, unit builder returns nothing
    call PolledWait(time)
    if ( IsUnitAliveBJ( builder ) == true ) //If the barracks is dead we don't want units to be made anymore
        call CreateNUnitsAtLoc( 1, ut, GetOwningPlayer(builder), GetUnitLoc(builder), bj_UNIT_FACING )
    else
        Call DoNothing()
    endif
endfunction
//END CUSTOM SCRIPT**

//Trigger catches loading of civilians into a
//barracks and makes barracks 'train' a unit
E: a unit is loaded into a transpot
C: unit type of transporting == whatever (barracks)
   unit type of loaded == whatever (guy)
A: remove loaded unit
   custom: call createUnitBasis( 'hfoo', 15.00, GetTransportUnitBJ() )
   //note 'hfoo' is an example of footman, it can be whatever else

if theres any slight inconsistancies its cause i came up with and wrote this on the spot in a few minutes so i didn't have time to really look over it
 
Level 6
Joined
Mar 25, 2005
Messages
304
Ok. Do the same trigger I wrote, but make sure to make the building's possession goes to another player when you build it. And then execute the rest. Thats one way to do it. Good luck
-Blue
 
Level 7
Joined
Jul 30, 2004
Messages
451
131ueDragon said:
Ok. Do the same trigger I wrote, but make sure to make the building's possession goes to another player when you build it. And then execute the rest. Thats one way to do it. Good luck
-Blue

i don't think thats a very good way, plus it requires a region for each player built structure, not too efficient, that and multiple players will have buildings, if you send a unit to an enemy building, since its neutrally owned it sounds like it will allow you to train there (i know you can work around with unit groups or custom value, just saying)
 
Level 6
Joined
Mar 25, 2005
Messages
304
Yea thats true. My way would work if it was a smaller scale RPG or somthing.
Here is another way to do it then:

*Event:
Unit comes within range of unit

*Condition:
Triggering unit type = X
Owner of building = X (Neutral Player)
Player is equal to X = true

*Action:
Give the player control of building.

I dunno somthing like that might work. I guess I'm just trying to take the lazy way out. Good luck
-Blue
 
Level 7
Joined
Jul 30, 2004
Messages
451
131ueDragon said:
Yea thats true. My way would work if it was a smaller scale RPG or somthing.
Here is another way to do it then:

*Event:
Unit comes within range of unit

*Condition:
Triggering unit type = X
Owner of building = X (Neutral Player)
Player is equal to X = true

*Action:
Give the player control of building.

I dunno somthing like that might work. I guess I'm just trying to take the lazy way out. Good luck
-Blue

note unit comes in range is a unit specific event, so you'd have to dynamically add events to the trigger for each new building, also i'm not perfectly sure but i believe you can't access the 'building' because theres no reference to it, you simply have an entering unit and a region -- now assumably you can 'tag' the type to different triggers, finding out who owns the building is a very convoluted process and is not as easy as saying 'triggering building' or such since theres no reference to it
nor can you say 'give control of the building' because you cna't access the 'building' easily
 
Level 6
Joined
Mar 25, 2005
Messages
304
lol way to prove me wrong on everything. Thx raptor. Jk :) I think you are right. But what i mean was the condition would make sure that the unit that was being targeted was a building. I dunno. I dont have my editor running right now. Thx anyways
-Blue
 
Level 7
Joined
Jul 30, 2004
Messages
451
131ueDragon said:
lol way to prove me wrong on everything. Thx raptor. Jk :) I think you are right. But what i mean was the condition would make sure that the unit that was being targeted was a building. I dunno. I dont have my editor running right now. Thx anyways
-Blue

i just know that because i've tried that before :p
you get stuck trying to figure out which unit the region/range belongs to

i think an alternative way of that method i came up with was to assign a 'unit tag' to all the civilians and when the civilian is smart ordered to a building or move ordered to one you'd put that targeted unit into the 'unit tag' and then everytime you came in range of a building you'd check to see if the 'unit tagged' building is also in range of the unit entering

very convoluted as i said
 
Ok hate to but in but, Im going to give a simple explanation in trigger form of what he can do...

Event
Unit loads another unit

Condition
Loading Unit = Barracks
Loaded Unit = Villager

Actions
If
Owner of Loading Unit's Gold Greater than (price for unit)
Then
Remove Loaded Unit from game
Else
Unload Loaded Unit
Display message (Not enough gold to train)

That should be about how it would work.

Well burns, just try that one on your map, if you want I could make a spell map for you to copy the triggers from.
 
Level 7
Joined
Jul 30, 2004
Messages
451
Deathbringer said:
Ok hate to but in but, Im going to give a simple explanation in trigger form of what he can do...

Event
Unit loads another unit

Condition
Loading Unit = Barracks
Loaded Unit = Villager

Actions
If
Owner of Loading Unit's Gold Greater than (price for unit)
Then
Remove Loaded Unit from game
Else
Unload Loaded Unit
Display message (Not enough gold to train)

That should be about how it would work.

Well burns, just try that one on your map, if you want I could make a spell map for you to copy the triggers from.

uh, thats exactly what i wrote up there except i added either the possibility of building a unit or using the custom script to choose a unit type and unit length build time
 
Level 2
Joined
Mar 10, 2005
Messages
19
i have an easy way to build this system. what you need is symple a building having an dummy spell targeting only one unit, your worker and your produkt the soldier

events - unit - unit starts casting an abilty
conditions - ability beeing cast equal <<dummy spell>>
actions - if - then - else---multiple functions
condition - unit type of ability beeing cast equal to
<<worker>>
then -unit - remove unit of ability beeing cast
-unit - order casting unit to train/upgrade
<<soldier>>
else - do nothing

this one should work nearly perfectly. your worker will be removed and the building starts to train your soldier. but if your soldier takes 2 supplie while your worker takes only one and your current supply is for instance 70/70, the worker will be remove -> 69/70 and your soldier wont be upgradet caus it would be 71/70 and you wont be noticed that you need more supply so either synchronize the supply, or include into the trigger a function which disables the removing and training.
hope this helps you.
 
Level 7
Joined
Jul 30, 2004
Messages
451
Devran04 said:
i have an easy way to build this system. what you need is symple a building having an dummy spell targeting only one unit, your worker and your produkt the soldier

events - unit - unit starts casting an abilty
conditions - ability beeing cast equal <<dummy spell>>
actions - if - then - else---multiple functions
condition - unit type of ability beeing cast equal to
<<worker>>
then -unit - remove unit of ability beeing cast
-unit - order casting unit to train/upgrade
<<soldier>>
else - do nothing

this one should work nearly perfectly. your worker will be removed and the building starts to train your soldier. but if your soldier takes 2 supplie while your worker takes only one and your current supply is for instance 70/70, the worker will be remove -> 69/70 and your soldier wont be upgradet caus it would be 71/70 and you wont be noticed that you need more supply so either synchronize the supply, or include into the trigger a function which disables the removing and training.
hope this helps you.

well aside from the fundamental problem that the building has to have the ability to build the soldier unit in the first place, which means instead of casting that spell the player could just click on the soldier icon to build it
 
Status
Not open for further replies.
Top