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

A bullet hits the target

Status
Not open for further replies.
Level 29
Joined
Jul 29, 2007
Messages
5,174
I need a trigger that will make it so that when a "bullet" (a unit with diffrent model) hits another unit it will kill the BULLET.

No need to damage the unit who got hit, only to kill the bullet.

I tried using 2 group picks, that will pick every unit with a aura that the bullet has, then pick every unit around the picked unit that is the unit-type of the bullet, and kill picked unit.
This did nothing :/

Any ideas on how to make it ?
 
Level 11
Joined
Feb 22, 2006
Messages
752
I dont know how you create your bullet, but I'm guessing it's with JASS since I can't think of any other way to do it, so here's my suggestion (requires Kattana's Handle Vars or some similar gamecache attachment system):

JASS:
function Bullet_Kill takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
    local triggeraction taction = GetHandleTAction( t, "taction" ) //pretty sure this function isn't one of Kattana's premade ones, just make it yourself using return bug
    local unit bullet = GetHandleUnit( t, "bullet" )
    call RemoveUnit( bullet )
    call TriggerRemoveAction( t, taction )
    call DestroyTrigger( t )
    set t = null
    set taction = null
    set bullet = null
endfunction

function Create_Bullet takes nothing returns nothing //I'm not sure what your function is actually called so I'll just call it this...
    local trigger t = CreateTrigger()
    local triggeraction taction
    local unit bullet
    local real range = 50.00 //How close you want units to get to your bullet before the bullet is destroyed
//more stuff...
    set bullet = CreateUnit( Player(1), 'h000', x, y, 0 ) //so you create your bullet...
//more stuff...
    call TriggerRegisterUnitInRange( t, bullet, range, null )
    set taction = TriggerAddAction( t, function Bullet_Kill )
    call SetHandleHandle( t, "bullet", bullet )
    call SetHandleHandle( t, "taction", taction )
    set t = null
    set taction = null
    set bullet = null
//more cleanup if needed...
endfunction
 
Last edited:
Level 11
Joined
Feb 22, 2006
Messages
752
Yes, it is SetHandleHandle(), and yes, I was getting it mixed with CSCache cuz I've been using CSCache for a while. But i know a lot more beginners use Kattana's system so I made by script compat with that instead.

And I also know the bullet isn't moving with the script I posted. I assume he already has a system to make the bullet move (timers and all that). I'm just posting the script that will remove the bullet.
 
Level 6
Joined
Aug 15, 2007
Messages
209
Ghost, I don't know why this is so complicated to everyone else. This doesn't need Kattana's handles or anything. Make a loop within the same trigger that the bullet is moved with. Make a loop that runs like every .1 seconds. Then do this...
if CountUnitsInRange(GetUnitLoc(Bullet/thing), 50) > 0 then
call KillUnit(Bullet)
endif

You don't even need a new trigger. All you do is check if any units are near the bullet. You can even make conditions to check if its an enemy.
 

TKF

TKF

Level 19
Joined
Nov 29, 2006
Messages
1,266
Well, I have a death detection system in my map with my fireballs. (ty for your help earlier ^^ ) I just add 0.01 expiration timer to nearby bullets within proximity and they die. They both to damage that stacks if someone is unfortunate to stay near the blast.

The issue is that the other fireball explodes 0.03 second later in my crappy system since only 1 triggers at the time... But it's not like I have a bullet wars either...
 
Level 11
Joined
Aug 25, 2006
Messages
971
Heres how I do it in my contest entry.
JASS:
function DoneWhatMakesThemWork takes nothing returns nothing //Do Damage
local unit u1 = GetEnumUnit()
    call KillUnit(ToPass) //During the next timer cycle this missile will be destroyed, we can't destroy it here because we don't have the struct number, and its not attached to the unit
    call UnitDamageTarget(ToPass,u1,DAMAGE_PER_MISSILE,false,true,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_COLD,WEAPON_TYPE_WHOKNOWS)//This isn't AOE damage, but the missile will still effect every unit in its col. radius.
endfunction

function MakeDoCollisions takes nothing returns nothing
local unit u = GetEnumUnit() //Slightly faster then calling the function 3 times
local group g = CreateGroup()
    set ToPass = u //Yes I'm using a global to pass around my local...
    call GroupEnumUnitsInRange(g,GetUnitX(u),GetUnitY(u),PRJEXTSIZE,Filter(function TriG))
    call ForGroup(g,function DoneWhatMakesThemWork)
    
    call DestroyGroup(g)
    set u = null //Clean up Clean up Clean up Clean up!
endfunction

function Trig_PeriodicRun_Actions takes nothing returns nothing
    //This part allows the trigger to self disable if no spells are running
    set bj_groupCountUnits = 0
    call ForGroup(AllEffected,function CountUnitsInGroupEnum)
    if bj_groupCountUnits == 0 then
        call DisableTrigger(gg_trg_PeriodicRun)
    endif
//    set bj_groupCountUnits = 0
//        call ForGroup(PAllrojex,function CountUnitsInGroupEnum)
//        call BJDebugMsg("Col = " + I2S(bj_groupCountUnits))
    call ForGroup(PAllrojex, function MakeDoCollisions) //Make collisions work! I'm not sure if this is an efficient method, but I like it
    call ForGroup(AllEffected , function MakeSpellDoStuff) //Now all this crazy stuff  
endfunction

Not everything here is relevant to collisions. The top two functions are strictly collisions while the bottom one calls my other functions (including the collisions.)

If you've seen my spell, you'll see that whenever an enemy unit comes close enough to one of the flying snow balls, the snow ball explodes and the unit takes damage.

'PAllrojex' is a global group containing all my projectiles.
'ToPass' is a global unit which I use to pass the unit from the first 'ForGroup' to the second 'ForGroup'
'PRJEXTSIZE' us the missile collision size
 
Level 11
Joined
Feb 22, 2006
Messages
752
GhostWolf said:
I only need a system that will detect when a bullet is near any unit and then kill him, not remove him.


Then just replace RemoveUnit() with KillUnit().

Need_O2 said:
uh man start using vJASS

I actually do use vJass, but not everyone knows vJass and not everyone has JNGP or jasshelper. Kattana's handles are more basic and require no preprocessor.

wd40bomber7 said:
Heres how I do it in my contest entry.

I have a question, what exactly triggers your Periodic_Run trigger (what's the event?). And I don't think you need to be destroying/creating all of those unit groups. Just have global groups and recycle them every time you run MakeDoCollisions().
 
Level 11
Joined
Aug 25, 2006
Messages
971
Thats true, I should have simply recycled my unit group. I realized it not that long after the contest should have ended. I'll fix it, but I won't submit the fixed version because the contest should be closed by now...

The actions are triggered by a timer, if you accept the default constants, the timer runs every .025 seconds.
 
Level 6
Joined
Aug 15, 2007
Messages
209
This is where JASS comes in handy. Local variables can have many instances at the same time, but can't be used in GUI. Also, it is MUCH (like srsly way) more effective to make the object move in small increments over time. It doesn't even have to look skippy. Do it every .1 seconds and you're good to go. Orders get....ugly.
 
Level 11
Joined
Aug 25, 2006
Messages
971
Your using orders? Those can get very ugly.
Using orders:
+Its really simple to do!
-Your units might walk around other units
-Slow to respond
-Not always straight
-They can't overlap
-Very slow moving
Using triggers, you can move the unit a few pixels every .01 seconds, which looks like movement:
+You can go as fast as you want
+Smooth, quick to respond
+They can overlap
-Collisions need to be programmed
-You have to be very careful about leaks
-Sometimes/Manytimes hard to make MUI because its uses realtime processing
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Your using orders? Those can get very ugly.
Using orders:
+Its really simple to do!
-Your units might walk around other units
-Slow to respond
-Not always straight
-They can't overlap
-Very slow moving


((++++++++)*(9999^9999))The only way I found making it MUI without leaks in GUI

And about your minuses:

1. Locust ? (anyway they have locust... would be stupid if you can select bullets lol)
2. "slow" means what ? 0.10 seconds ? does that really matter ? and I don't think its even slower then anything else with triggers.
3. Never happend to me
4. What does "overlap" means ?
5. With Mini_Me's system it can be as fast as you want (once did it by mistake so fast I saw the bullet only twice before it was gone from the map lol)
 
Level 11
Joined
Aug 25, 2006
Messages
971
If your using a missile system, your not using orders. I meant like giving a unit the locust ability and ordering it to move. In that case the max Movement speed would be 512
 
Level 6
Joined
Aug 15, 2007
Messages
209
wd40...You have to realize that the only reason you use orders is for convenience. The way mechanical man explains it, and the way I would do it, is the most commonly used way to do it. In fact, some of the most advanced JASS systems and games do the way we did, like Elimination Tournament, Hindy's SEE, Madballz Arena, Soldiers, TCX Deathmatch, Real And Crazy Grenades, and Counterstrike. To name a few.
 
Status
Not open for further replies.
Top