• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

How To Use xemissile?

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hello,

I decided to try xe for a spell request I am working on involving a missile. I can't seem to get xemissile working properly, perhaps someone could explain? I'm not good at simply reading and understanding others' code.

This is what I have so far:

JASS:
private struct Data extends xemissile
    unit caster
    xemissile missile
    
    method onHit takes nothing returns nothing
        call KillUnit(.caster)
    endmethod
    
    private static method create takes unit c, real x, real y returns thistype
        local thistype this = thistype.allocate(GetUnitX(c), GetUnitY(c), 0.0, x, y, 0.0)
        
        set .caster = GetTriggerUnit()
        set .missile = xemissile.create(GetUnitX(.caster), GetUnitY(.caster), 0.0, x, y, 0.0)
        call .missile.launch(1000.0, 0.25)
        
        return this
    endmethod

    private static method spell takes nothing returns nothing
        call thistype.create(GetTriggerUnit(), GetSpellTargetX(), GetSpellTargetY())
    endmethod

    private static method onInit takes nothing returns nothing
        call RegisterSpellEffectEvent(SPELL_ID, function thistype.spell)
    endmethod
    
endstruct
- How can I add a model to the missile?
- How can I get onHit working? Currently nothing happens...

Thanks,

Mr_Bean

EDIT: Just realised this should be posted in Triggers and Scripts, sorry!
 
Level 5
Joined
Jun 16, 2004
Messages
108
Here is a simple xehomingmissile from a spell of mine:
JASS:
struct arrow extends xehomingmissile
    static constant string EFFECT = "Abilities\\Spells\\Other\\FrostArrows\\NagaColdArrowMissile.mdl"
    static constant real SCALE = 1.
    
    static constant real VELOCITY = 1400.
    static constant real ARC_MIN = 0.
    static constant real ARC_MAX = 1.8
    
    static constant real ZSTART = 60.
    static constant real ZEND = 60.
    
    static constant real DAMAGE = 40.
    
    unit caster
    unit target
    
    method onHit takes nothing returns nothing
        if (GetWidgetLife(.target) > .405) then
            call UnitDamageTarget(.caster, .target, thistype.DAMAGE, false, false, ATTACK_TYPE_NORMAL, ConvertDamageType(1), null)
        endif
    endmethod
    
    static method create takes unit caster, unit target returns thistype
        local thistype tt = thistype.allocate(GetWidgetX(caster), GetWidgetY(caster), thistype.ZSTART, target, thistype.ZEND)
        if (tt > 0) then
            set tt.fxpath = thistype.EFFECT
            set tt.scale = thistype.SCALE
            call tt.launch(thistype.VELOCITY, GetRandomReal(thistype.ARC_MIN, thistype.ARC_MAX))
            set tt.caster = caster
            set tt.target = target
        endif
        return tt
    endmethod
    
    method onDestroy takes nothing returns nothing
        
    endmethod
endstruct

Homing missiles will execute onHit when they hit their launched at target (set in the allocate method), whereas normal missiles will go to a target point and execute onHit when it is reached.

Your current code seems like it will kill the caster once the missile reaches its target point, that sounds a bit odd I guess.

Your current code creates a generic xemissile within your xemissile extending struct, which is not how it is intended to be used. You can change the effect of the generic xemissile by changing .fxpath, and other parameters in a similar way, but you cannot redefine onHit and loopControl that way, which is why one extends from xemissile in the first place.

The code I posted should be simple enough to get the right idea.
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
Thanks!
Haha, it kills the caster just as a test. When I get it working I will do the proper thing :p
Your example explains a lot. I will try it when I get the chance.
- Can the methods be private? Never mind, it works.
- Also, please explain what extends does. I have worked with structs a lot, but never used extends. Is it similar to inheritance from C++?
- How do I deallocate my struct instance when the missile hits? I try adding .deallocate() but it gives some weird error.

Thanks again.
 
Last edited:
Level 5
Joined
Jun 16, 2004
Messages
108
Yes, the idea is inheritance. Read about it in the vJASS manual if you want: http://www.wc3c.net/vexorian/jasshelpermanual.html

xemissile specifies that you should use terminate when you want to clean up a missile. However, when a missile's onHit is called, the missile will automatically clean itself up afterwards, unless you call launch again from within onHit.
 
Level 5
Joined
Jun 16, 2004
Messages
108
Since the idea is inheritance, yes, your struct instance will be cleaned up at the same time as the generic xemissile provided that you are extending from the xemissile class(es).
 
Status
Not open for further replies.
Top