Warcraft III resources & community, 2003–2006 · archived

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

18 posts
#1

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

-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.
#2

I got it

OK, I did some playing around and came up with a good answer to # 2 and 3.
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
#3
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
#4
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.
#5

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.
#6
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


//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

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


//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
#7
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
#8
131ueDragonOk. 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)
#9
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
#10
131ueDragonYea 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
#11
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
#12
131ueDragonlol 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
#13
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.
#14
DeathbringerOk 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
#15
but u had it in JASS form didnt you?