• 🏆 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!

[Trigger] Building Deselection Problem

Status
Not open for further replies.
Level 6
Joined
Mar 17, 2012
Messages
51
This thing is weird.
  • Demolish
    • Events
      • Unit - A unit owned by Player 1 (Red) Begins training a unit
    • Conditions
      • (Trained unit-type) Equal to Demolish Tower
    • Actions
      • Unit - Remove (Trained unit) from the game
      • Unit - Remove (Triggering unit) from the game
      • Selection - Clear selection for Player 1 (Red)
      • Player - Set Player 1 (Red) Current gold to 200
      • Player - Set Player 1 (Red) Current lumber to 200
I added:
  • Selection - Clear selection for Player 1 (Red)
But the selection would be still on the trained unit that has been removed from the game... Please help....+ REP for those who will give me the correct thing to do.....
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
begins training a unit will call when a building trains something under Techtree - Units Trained. you might want to change the event
 
Level 6
Joined
Jun 19, 2010
Messages
143
Looks like you simply want to sell that building. There is a simpler way to do this.
Base your upgrade off Animal War Training. You can think of something similar with this help of using Animal War Training as an upgrade instead of the trained unit/building. Think of the players, do you need them to see the removed Demolish Tower? Removing an unit when training or upgrading halfway can either consume much memory or even crash the game.
  • Sell
    • Events
      • Unit - A unit Begins research
    • Conditions
      • (Researched tech-type) Equal to Sell
    • Actions
      • Unit - Remove (Triggering unit) from the game
  • //change the amounts of Gold & Lumber return to player here.
    • Player - Add 10 to (Owner of (Triggering unit)) Current gold
    • Player - Add 10 to (Owner of (Triggering unit)) Current lumber
 
Last edited:
Level 6
Joined
Jun 19, 2010
Messages
143
Another way is using berserk or similar one as dummy ability for the building.
  • selfdestruct
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Destroy
    • Actions
      • Unit - Kill (Casting unit)
      • If ((Unit-type of (Casting unit)) Equal to ArcaneTower) then do (Player - Add 5 to (Owner of (Casting unit)) Current gold) else do (Player - Add 800 to (Owner of (Casting unit)) Current gold)
In this case, 5 gold will be returned to the player if arcane tower is sold, 800 gold if other towers sold. You can store the return value in variables & make nest condition to check which building is sold.
No need to deselect building in this case.
**Notice that using Triggering Unit is faster than Casting Unit. Try using it in most cases would be efficient.
 
Level 6
Joined
Jun 19, 2010
Messages
143
And if you really want the deselect one. I can give you an example which is just fine in GUI but not work well in vJass script I still try to figure out. 8 Peasants were created in another trigger/script. Surely you can only select one peasant not the others. Good for some game you need to board all those units into a plane or ship. A ship cannot load an allied unit.

  • Deselect
    • Events
      • Player - Player 1 (Red) Selects a unit
      • Player - Player 2 (Blue) Selects a unit
      • Player - Player 3 (Teal) Selects a unit
      • Player - Player 4 (Purple) Selects a unit
      • Player - Player 5 (Yellow) Selects a unit
      • Player - Player 6 (Orange) Selects a unit
      • Player - Player 7 (Green) Selects a unit
      • Player - Player 8 (Pink) Selects a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Peasant
    • Actions
      • Unit - Move FinalBuilding instantly to ((Triggering player) start location)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Peasant[(Player number of (Triggering player))] Not equal to (Triggering unit)
        • Then - Actions
          • Selection - Remove (Triggering unit) from selection
        • Else - Actions
And here, Jass script is now working fine. All the variables are defined, some are defined as global in library like this. It's also about deselection.
JASS:
library Peon
              globals
                  unit array Peon
                  integer whichPlayer=0
               endglobals
endlibrary

JASS:
scope Deselection initializer Deselect
    function Des_Conditions takes nothing returns boolean
        local unit u=GetTriggerUnit()
        set whichPlayer=GetPlayerId(GetTriggerPlayer())
        if GetUnitTypeId(u)==PEONID then
            if Peon[whichPlayer]!=u then 
                  call SelectUnit(u,false)
            endif
        endif
        set u=null
        return false
    endfunction
    function Deselect takes nothing returns nothing
        local trigger Des=CreateTrigger()
        set whichPlayer=0
        loop
            exitwhen whichPlayer>7
//change 7 to number of players you want to put under deselection trigger
//If the player numbers are scattered, then take the event out of the loop and remove the loop,like this
//call TriggerRegisterPlayerUnitEvent(Des,Player(0),EVENT_PLAYER_UNIT_SELECTED,null)
//call TriggerRegisterPlayerUnitEvent(Des,Player(3),EVENT_PLAYER_UNIT_SELECTED,null)
//call TriggerRegisterPlayerUnitEvent(Des,Player(9),EVENT_PLAYER_UNIT_SELECTED,null)
            call TriggerRegisterPlayerUnitEvent(Des,Player(whichPlayer),EVENT_PLAYER_UNIT_SELECTED,null)
            set whichPlayer=whichPlayer+1
        endloop
        call TriggerAddCondition(Des,Condition(function Des_Conditions))
        set Des=null
    endfunction
endscope
 
Last edited:
Status
Not open for further replies.
Top