• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

2 questions about cargo

Status
Not open for further replies.
Level 17
Joined
Mar 21, 2011
Messages
1,597
Hey there,

question 1: i have a custom vehicle system. Vehicles are neutral and you can enter them per right click. that works fine as long as the vehicle is a ground unit, but if its flying, the hero stops at a certain distance. i would need to manually walk close enough to the vehicle and then right click it.

question 2: is there a trick or option to kill all units loaded in a vehicle on death? (without using triggers!)

thanks
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Never used transport units, but I think the only possiblity to kill all units in the transport unit is to kill it on a location, where the loaded units cannot be unloaded.
What do you mean by custom vehicle system?
Why don't you want to use triggers for this?
 
Level 18
Joined
Nov 21, 2012
Messages
835
Hi Gimli
question1: OE -> Unit Classification -> Walkable (for goblin zeppelin/car)
question2: use Bribe's Unit Event 2.2.1.0 it has On Load/On Unload events
with this trigger:
  • On Unload
    • Events
      • Game - CargoEvent becomes Equal to 2.00
    • Conditions
    • Actions
      • Game - Display to (All players) the text: ((Name of UDexUnits[UDex]) + ( was unloaded from + (Name of CargoTransportUnit[UDex])))
just add condition if not IsUnitAlive(CargoTransportUnit[UDex]) then kill unit UDexUnits[UDex]
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
question1: OE -> Unit Classification -> Walkable (for goblin zeppelin/car)
thanks!

just add condition if not IsUnitAlive(CargoTransportUnit[UDex]) then kill unit UDexUnits[UDex]
this does not work unfortunately, because the unload happens before the death or at the same time. i used damage detection to solve the problem.


edit: does not work with walkable :(
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
How did you make this work with a neutral transport unit? I would like to recreate your problem so I can better understand it.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
You are using method 1 right? And you want it to work with air units.

Edit: It did work for me. The hero only stops moving once the loading process begins, I did not have to manually move the hero near the transporter.

All I did was copying the tank method 1, changing movement type to flying, movement height to 200 and setting combat targeted as to air.
 
Last edited:

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
That's weird, because it works perfectly for me. Are you using the tank concept map to test or are you using your own map? Maybe there is a different trigger, that causes the unit to stop.
I was thinking that problems could occur because of vision and the unit stopping because it no longer sees the target unit. Maybe also that the air path towards the target and the ground path to the transport are different and then they stop.

I really don't know what the problem could be.

I will just attach the slightly modified version of NightSkyAurora's tank concept with flying tanks.
 

Attachments

  • AirTank.w3x
    22.2 KB · Views: 27

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
I see. So they are not supposed to move towards the target. I guess this is hardcoded then, that the order gets canceled if it's not succesful. Maybe you could try to work around it. You could try to save the order when a unit wants to load into a transport unit. Then you continuously order the unit to move towards the transport unit. Once the unit is close enough you order it to load.
I will try if this works.
 
Level 18
Joined
Nov 21, 2012
Messages
835
maybe it is acceptable for you
for load a neutral transport:
JASS:
function Trig_ord_Conditions takes nothing returns boolean
    local unit t = GetOrderTargetUnit()
    // order smart and target=your transport and passive & units close enough
    // transort should be "walkable" in unit classification
    if GetIssuedOrderId()==851971 and t != null and GetOwningPlayer(t)==Player(15) then
        if GetUnitTypeId(t)=='nzep' and IsUnitInRange(GetOrderedUnit(), t, 80.00) then
            set t=null
            return true
        endif
    endif       
    set t=null
    return false
endfunction

function Trig_ord_Actions takes nothing returns nothing
    local unit u = GetOrderedUnit()
    local unit t = GetOrderTargetUnit()
    local player pla = GetOwningPlayer(u)
    call SetUnitOwner(u, GetOwningPlayer(t), false)
    call IssueTargetOrderById(t, 852046, u) // load order
    call TriggerSleepAction(0.00)
    call SetUnitOwner(t, pla, false)
    set u=null
    set t=null
    set pla=null
endfunction
//============================================================
function InitTrig_ord takes nothing returns nothing
    set gg_trg_ord = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ord, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddCondition( gg_trg_ord, Condition( function Trig_ord_Conditions ) )
    call TriggerAddAction( gg_trg_ord, function Trig_ord_Actions )
endfunction
 

Attachments

  • Unit Event 2.2.1.0GimliTest.w3x
    28.2 KB · Views: 21
Level 17
Joined
Mar 21, 2011
Messages
1,597
JASS:
if GetUnitTypeId(t)=='nzep' and IsUnitInRange(GetOrderedUnit(), t, 80.00) then
it works for distance < load range, so it doesnt work for larger distances.

JASS:
library Vehicle initializer Event uses SpellEffectEvent

    globals
        private integer spawnInterval
        private unit array driver
    endglobals
  
    private function Timed takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local integer id = GetTimerData(t)
        if UnitAlive(udg_UDexUnits[id]) then
            call SetUnitInvulnerable(udg_UDexUnits[id], true)
        endif
        call ReleaseTimer(t)
        set t = null
    endfunction
  
    private function OnUnload takes nothing returns boolean
        call SetUnitOwner(udg_CargoTransportUnit[udg_UDex], Player(PLAYER_NEUTRAL_PASSIVE), true)
        call SetUnitMoveSpeed(udg_CargoTransportUnit[udg_UDex], 0)
        call UnitAddAbility(udg_CargoTransportUnit[udg_UDex], ABILITY_DETECTION)
        call TimerStart(NewTimerEx(GetUnitUserData(udg_CargoTransportUnit[udg_UDex])), 0, false, function Timed)
        if (GetLocalPlayer() == GetOwningPlayer(udg_UDexUnits[udg_UDex])) then
            call ClearSelection()
            call SelectUnit(udg_UDexUnits[udg_UDex], true)
        endif
        set driver[GetUnitUserData(udg_CargoTransportUnit[udg_UDex])] = null
        return false
    endfunction
  
    private function OnLoad takes nothing returns boolean
        local player p = GetOwningPlayer(udg_UDexUnits[udg_UDex])
        call PauseUnit(udg_CargoTransportUnit[udg_UDex], true)
        call SetUnitOwner(udg_CargoTransportUnit[udg_UDex], p, true)
        call PauseUnit(udg_CargoTransportUnit[udg_UDex], false)
        call SetUnitMoveSpeed(udg_CargoTransportUnit[udg_UDex], 290)
        call UnitRemoveAbility(udg_CargoTransportUnit[udg_UDex], ABILITY_DETECTION)
        call SetUnitInvulnerable(udg_CargoTransportUnit[udg_UDex], false)
        if (GetLocalPlayer() == p) then
            call ClearSelection()
            call SelectUnit(udg_CargoTransportUnit[udg_UDex], true)
        endif
        set driver[GetUnitUserData(udg_CargoTransportUnit[udg_UDex])] = udg_UDexUnits[udg_UDex]
        return false
    endfunction
  
    private function OnDestroy takes nothing returns boolean
        if IsUnitType(udg_DamageEventTarget, UNIT_TYPE_MECHANICAL) and udg_DamageEventAmount >= GetUnitState(udg_DamageEventTarget, UNIT_STATE_LIFE) then
            call UnitDamageTarget(udg_DamageEventSource, driver[GetUnitUserData(udg_DamageEventTarget)], 1000.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        endif
        return false
    endfunction
  
    private function OnDeath takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local unit vehicle
        if GetUnitTypeId(u) == 'h00V' then
            set vehicle = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), vehicleType[GetRandomInt(0, 2)], GetUnitX(u), GetUnitY(u), 0)
            call SetUnitMoveSpeed(vehicle, 0)
            call UnitAddAbility(vehicle, ABILITY_DETECTION)
            call SetUnitInvulnerable(vehicle, true)
            set vehicle = null
        endif
        set u = null
        return false
    endfunction
  
    private function SpawnVehicles takes nothing returns nothing
        local unit u
        local real x
        local real y
        local integer rnd
        if isEvent == false then
            set spawnInterval = spawnInterval - 1
            if spawnInterval == 0 then
                set rnd = GetRandomInt(0, 7)
                set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h00V', GetRandomX(rnd), GetRandomY(rnd), 0.00)
                call SetUnitAnimation(u, "birth")
                call UnitApplyTimedLife(u, 'BTLF', 5.00)
                set spawnInterval = SETTINGS_VEHICLE_INTERVAL
                set u = null
            endif
        endif
    endfunction
  
    function RunVehicleEvent takes nothing returns nothing
        call TimerStart(NewTimer(), 1.00, true, function SpawnVehicles)
        set spawnInterval = SETTINGS_VEHICLE_INTERVAL
    endfunction

    private function Event takes nothing returns nothing
  
        local trigger load = CreateTrigger()
        local trigger unload = CreateTrigger()
        local trigger ondestroy = CreateTrigger()
      
        call TriggerRegisterVariableEvent(load, "udg_CargoEvent", EQUAL, 1.00)
        call TriggerAddCondition(load, Condition(function OnLoad))
      
        call TriggerRegisterVariableEvent(unload, "udg_CargoEvent", EQUAL, 2.00)
        call TriggerAddCondition(unload, Condition(function OnUnload))
      
        call TriggerRegisterVariableEvent(ondestroy, "udg_DamageEvent", EQUAL, 1.00)
        call TriggerAddCondition(ondestroy, Condition(function OnDestroy))
  
        call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function OnDeath)
      
        set load = null
        set unload = null
        set ondestroy = null
    endfunction
  
endlibrary
thats the current code.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
I implemented the method mentioned above. Once a unit right clicks on a transport unit, I order the target to move towards the unit. Once it has reached the unit it will try to load.
You can set the unit-types of the transport units and how close a unit should move to start loading.
If you have problems getting this to work you can ask me for help of course.
 

Attachments

  • AirTankOrder.w3x
    25.2 KB · Views: 25
Status
Not open for further replies.
Top