[Trigger] Changing Unit Ownership

Status
Not open for further replies.
Level 5
Joined
Nov 1, 2007
Messages
71
Hello, I was wondering if I could get some help with a trigger involving the changing of unit ownership.

What I want to do is make it so if A certain unit reaches below a certain amount of health, than the player who attacked said unit, and got the unit's health that low, would gain ownership of that unit.

Any help would be appreciated :thumbs_up:
 
Level 5
Joined
Nov 1, 2007
Messages
71
Alright, something weird is happening..

  • Events
    • Unit - Capturable Point 0225 <gen> Is attacked
  • Conditions
    • (Point-value of Capturable Point 0225 <gen>) less than 500
  • Actions
    • Unit - Change ownership of Capturable Point 0225 <gen> to (Owner of (Attacking unit)) and Change color
As soon as my unit attacks the Capturable Point, it instantly changes ownership, instead of the unit getting below 500 health.
 
Level 24
Joined
May 9, 2007
Messages
3,563
Hmm, why are you using point value.

Would it not be simpler to make it so that when it dies it recreates the unit. If the unit is used in triggers just add it to a unitgroup and base the triggers off the unit group instead of the unit.

Wait one sec for code.

Here it is:

Code:
function CaptureGoldMineConds takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'h000'
endfunction

function CaptureGoldMine takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(GetKillingUnit())
    call DisplayTextToPlayer(GetLocalPlayer(),0,0,GetPlayerName(p) + " has taken a gold mine from " + GetPlayerName(GetOwningPlayer(u)) + "!")
    call CreateUnit(p,'h000',GetUnitX(u),GetUnitY(u),270)
    call RemoveUnit(u)
    set u = null
endfunction

function InitTrig_CaptureGoldMine takes nothing returns nothing
    set gg_trg_CaptureGoldMine = CreateTrigger()
    call SetPlayerState(Player(0),PLAYER_STATE_RESOURCE_GOLD,700)
    call SetPlayerState(Player(1),PLAYER_STATE_RESOURCE_GOLD,700)
    call TriggerRegisterAnyUnitEventBJ(gg_trg_CaptureGoldMine,EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddCondition(gg_trg_CaptureGoldMine,Condition(function CaptureGoldMineConds))
    call TriggerAddAction(gg_trg_CaptureGoldMine,function CaptureGoldMine)
endfunction

Replace all reference of goldmine to get to work.
 
Level 5
Joined
Nov 1, 2007
Messages
71
I really appreciate the help, guys.. but I'm not good with JASS.. don't really know anything about it.. so if you could put that in GUI terms, I'd really appreciate it.

What I'm trying to do with this trigger, is to make capturable points [being a building] around the map, but other plays can come back and attack that point that you've gained, and gain it for themselves...
 
Level 24
Joined
May 9, 2007
Messages
3,563
That is what this does. To use it simply cut and paste into a trigger. As Poot said some things need to be changed. I'm not sure really what but you could take a JASS tutorial. By the way that is not my code but Poot's in the first place so. . . you would have to ask him.
 
Level 17
Joined
Apr 13, 2008
Messages
1,603
Nonono. Guys. He says in the condition:
POINT VALUE.

That's a freaking completely different thing. So the point value is an integer attached to your unit. You can edit this value in the object editor and use it in the game where it is not visible by any means but you can refer to it. You can store data in there, in TDs they like to store the gold amount you get back when sell it, for example.
A unit's point value is 100 by default, if my memory serves me well.

So Point Value has nothing to do with life.
A unit's life is a real variable. Look it up and your trigger will work without any JASS magic.
 
Last edited:
Status
Not open for further replies.
Top