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

simple system

Status
Not open for further replies.
Level 9
Joined
Apr 7, 2010
Messages
480
how do i add a system where if a unit gets hit by a moving vehicle, the unit dies.

how can i do this with triggers and without any skills?
 
Level 7
Joined
May 13, 2011
Messages
310
LOL, when you said without any skills at first I thought you mean "without being skillful" XD

Well, how about you check out this thread. If you want to use only triggers then you could try defskull's suggestion, however I personally think I would use TLI-Inferno's method. That way you can just add the ability to the vehicle(s) you want.

Well, whatever method you choose, I hope it works.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Of course TLI's suggestion has greater potential for that thread because the thread starter wanted that if Unit A walks in a straight line, every enemy of Unit A (this is conditions, this is for you to decide) will be killed if it gets too close to Unit A

That's not a "detecting collision system", it just kills any nearby unit (your condition)

With my system, you can do whatever you want with the collided units

Conclusion:
TLI System: Detect to kill
My System: Detect to do whatever you want to the detected unit
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
+ he asked how to do it with triggers, not abilities, so defskull's method would be the only solution in this case.

I do suggest you remove the event of defskull's trigger and then do this for every vehicle:
  • Trigger - Add to Some Trigger the event (Unit - A unit comes within 150.00 of Vehicle)
You don't need the timer for that (running a trigger every 0.03 seconds is slightly more demanding) and it doesn't have the potential to leak a location and a group.
Of course, you can't edit the range in this case, nor can you easily get the vehicle.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
@ap0calypse

Try moving a unit behind the vehicle while it's idle =P
LOL That'd be funny.
I'm writing this system right now :)

Oh, right... a /moving/ vehicle... :p

Well, in that case: if you want to do it correctly, you'll need some math to check whether the unit is actually in front of vehicle too ^^
Simple stuff though, nothing too fancy.
 
I wrote this library:
JASS:
library CarAccident
    globals
        private constant integer OFFSET = 0x100000 // DONT EDIT
    endglobals
    
    ////////////////////////////////////////////////////
    //////// HOW TO USE THIS SYSTEM IN GUI /////////////
    ////////////////////////////////////////////////////
    ////                                            ////
    ////   If there's a car, all you have to do is  ////
    ////   use a Custom script to call this:        ////
    ////                                            ////
    ////   -> call RegisterCar(udg_<yourunit>)      ////
    ////                                            ////
    ////////////////////////////////////////////////////
    ////////////////////////////////////////////////////
    ////////////////////////////////////////////////////
    
    private keyword Car // LOL
    
    private function IsCar takes unit u returns boolean
        return Car[u] != 0
    endfunction
    
    private function filter takes nothing returns boolean
        return not IsCar(GetFilterUnit())
    endfunction
    
    private struct Car
        unit car
        static integer array index
        static integer array trigindex
        static method operator [] takes unit u returns thistype
            return index[GetHandleId(u)-OFFSET]
        endmethod
        static method getData takes trigger t returns thistype
            return trigindex[GetHandleId(t)-OFFSET]
        endmethod
        static method check takes nothing returns boolean
            local thistype this = thistype.getData(GetTriggeringTrigger())
            local unit u = GetTriggerUnit()
            local real a = Atan2(GetUnitY(u)-GetUnitY(.car),GetUnitX(u)-GetUnitX(.car))
            local real f = GetUnitFacing(.car)*bj_DEGTORAD
            if a <= f + 1.0472 and a >= f - 1.0472 then
                call KillUnit(u)
            endif
            call BJDebugMsg("Checking")
            set u = null
            return false
        endmethod
        static method create takes unit u returns thistype
            local thistype this = thistype.allocate()
            local trigger t = CreateTrigger()
            set this.car = u
            set index[GetHandleId(u)-OFFSET]=this
            set trigindex[GetHandleId(t)-OFFSET]=this
            call TriggerRegisterUnitInRange(t,u,175.0,function filter)
            call TriggerAddCondition(t,Condition(function thistype.check))
            call BJDebugMsg("Registered")
            set t = null
            return this
        endmethod
        method destroy takes nothing returns nothing
            set this.car = null
            call this.deallocate()
        endmethod
    endstruct
    
    // Wrapper
    function RegisterCar takes unit u returns nothing
        local Car c = Car.create(u)
    endfunction
endlibrary

But it's not working >.<
yeah... I'm lifeless =P
 
Level 9
Joined
Apr 7, 2010
Messages
480
i don't use jass since my WE doesn't work on newgen

the thread works but i changed the collision from 160 to 110 making the system work only for moving units. but there is also a problem, if the unit was the one to charge the vehicle it still gets killed ^^
 
Level 7
Joined
May 13, 2011
Messages
310
Try changing this line:

  • Unit - Kill (Picked unit)
To this:

  • If ((Owner of (Picked unit)) Equal to Player 2 (Blue)) then do (Unit - Kill (Picked unit)) else do (Do nothing)
That is of course, assuming that the enemy is Player 2 (Blue). If not, just change the Player there to the owner of the units you want to be killable. Then it won't kill your own units, which, as I understand, was your problem.

defskull said:
Of course TLI's suggestion has greater potential for that thread because the thread starter wanted that if Unit A walks in a straight line, every enemy of Unit A (this is conditions, this is for you to decide) will be killed if it gets too close to Unit A

That's not a "detecting collision system", it just kills any nearby unit (your condition)

With my system, you can do whatever you want with the collided units

Conclusion:
TLI System: Detect to kill
My System: Detect to do whatever you want to the detected unit

I knew Klann would use your method since he wanted it with triggers only, but even so, if I were in his position and I didn't mind using skills I would use TLI's method, since what he also wants to kill the unit. Obviously, if I wanted to do anything other than kill them I would use your method.
 
Level 9
Joined
Apr 7, 2010
Messages
480
Changing this line :
  • Unit - Kill (Picked unit)
To this :
  • If ((Owner of (Picked unit)) Equal to Player 2 (Blue)) then do (Unit - Kill (Picked unit)) else do (Do nothing)
will prevent killing my own units. but isn't this prevents a friendly/allied unit from getting killed by this system? (this was already in the test map)-->
  • Unit Group - Pick every unit in (Units within 160 of UnitPoint (((Matching unit) belongs to an enemy of (Owner of Unit) Equal to True)) and do (Actions)
 
Level 7
Joined
May 13, 2011
Messages
310
What it does is it only kills units that are owned by the specified Player (Player 2 in my example).
What exactly is your question? Your wording was a bit strange. Are you asking if this:

  • Unit Group - Pick every unit in (Units within 160 of UnitPoint (((Matching unit) belongs to an enemy of (Owner of Unit) Equal to True)) and do (Actions)
does the same? or are you asking something else?
 
Status
Not open for further replies.
Top