Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

(xe)projectile

Discussion in 'Graveyard' started by aznricepuff, Jun 3, 2009.

  1. Cheezeman

    Cheezeman

    Joined:
    Aug 19, 2008
    Messages:
    488
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    Sorry for not knowing structs, but what exactly does this do?
    All the title says is "Projectile System", and I can think of many things such a headline fits with.
    And how to use it?
     
  2. aznricepuff

    aznricepuff

    Joined:
    Feb 22, 2006
    Messages:
    749
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    It simulates wc3 projectiles. Like the arrow that an archer shoots when it attacks, or the hammer that gets thrown when you cast storm bolt.

    If you want to know how to use it, look at the documentation.
     
  3. Cheezeman

    Cheezeman

    Joined:
    Aug 19, 2008
    Messages:
    488
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    Why would anyone want that? Is Blizzard's ineffective?

    Edit
    Oh I see you can stop the projectile whenever you want (at least I think so)
    But apart from that, what's special?
     
  4. aznricepuff

    aznricepuff

    Joined:
    Feb 22, 2006
    Messages:
    749
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    If you wanted to trigger a spell like storm bolt, or if you just want some fancy projectile special effects.
     
  5. madcd

    madcd

    Joined:
    Jun 21, 2007
    Messages:
    647
    Resources:
    2
    Maps:
    2
    Resources:
    2
    i'm a terrianer jumping head long into trying to get a working projectile system, now knowing only basics of wc3 i would like to know how i cam implament it, now i know that this system requires another jass trigger for it to work . . but can any one piont me in the right direction of how to get a working projectile trigger . . all it hass to do is be triggerd by a spell and head in a straight line with collision dectection
     
  6. aznricepuff

    aznricepuff

    Joined:
    Feb 22, 2006
    Messages:
    749
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    Update. xeprojectile.destroy() is now private, which means to destroy a projectile, you are forced to use xeprojectile.terminate(). This allowed me to get rid of the annoying delegate trick I was using to make xeprojectile.destroy() not bug things up.
     
  7. Yixx

    Yixx

    Joined:
    Oct 12, 2008
    Messages:
    1,492
    Resources:
    3
    Spells:
    3
    Resources:
    3
    call this.deallocate
    is this supposed to be in onDestroy Always? Because i have never seen that before, not when using standard onDestroy nor when using custom-made. Or is everybody that is not calling it in a custom onDestroy doing it wrong?
     
  8. aznricepuff

    aznricepuff

    Joined:
    Feb 22, 2006
    Messages:
    749
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    You've never seen it before because it's only been in existence for about 5 days. It's a new thing since jasshelper 0.9.Z.0. You can now override a struct's .destroy() method much like how you could previously override a struct's constructor, .create(). So therefore, just like how you needed to call thistype.allocate() inside an overidden .create() to actually allocate a struct, you need to call this.deallocate() inside an overidden .destroy() to actually deallocate (garbage collect) the struct.
     
  9. YourNameHere

    YourNameHere

    Joined:
    Apr 29, 2007
    Messages:
    745
    Resources:
    4
    Maps:
    1
    Spells:
    2
    JASS:
    1
    Resources:
    4
    Since you can override the destroy method, why not put all the stuff from your terminate method into that?

    e/ ahh nvm, didn't look at the script before. ;_;
     
  10. Yixx

    Yixx

    Joined:
    Oct 12, 2008
    Messages:
    1,492
    Resources:
    3
    Spells:
    3
    Resources:
    3
    If you look closely, .terminate only sets a boolean to make it destroy in the execute loop.

    @ aznricepuff, so if i do not call .deallocate() i will 'leak' a struct index?
     
  11. aznricepuff

    aznricepuff

    Joined:
    Feb 22, 2006
    Messages:
    749
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    If you override destroy, yes.
     
  12. Mooglefrooglian

    Mooglefrooglian

    Joined:
    Nov 28, 2008
    Messages:
    701
    Resources:
    0
    Resources:
    0
    One boolean: "InUse = true" inside the struct declaration. Set it to default to true, and make your destroy method set it to false. It's what I've been doing in my projectile loops anyways.
     
  13. Slaydon

    Slaydon

    Joined:
    Jan 6, 2008
    Messages:
    2,432
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Excuse me, but could i get a test map, and also what projectile is, x)
     
  14. watermelon_1234

    watermelon_1234

    Joined:
    Nov 18, 2007
    Messages:
    1,066
    Resources:
    10
    Spells:
    9
    JASS:
    1
    Resources:
    10
    It's kind of late, but I've uploaded a test map showing a spell using xeprojectile for those that are interested in this.
    It helps having experience in using xefx before using xeprojectile.
    It also helps to look at xefx's and xeprojectile's documentation if you don't understand something.

    Here's the code:
    Code (vJASS):
    scope Shocker initializer Init
        globals
            private constant integer SPELL_ID = 'A000'    
            private constant string TARGET_SFX = "Abilities\\Weapons\\Bolt\\BoltImpact.mdl" //SFX played when the unit gets hurt
            private constant string TARGET_ATTACH = "origin"  
            private constant attacktype ATK_TYPE = ATTACK_TYPE_NORMAL
            private constant damagetype DMG_TYPE = DAMAGE_TYPE_UNIVERSAL
            //Missile Properties
            private constant real HEIGHT = 60. //Missile height on creation
            private constant real ARC = 0.1 //Arc of the missile when reaching the target
            private constant real SPEED = 500. //Speed of missile, in WC3 units        
            private constant real BASE_SCALE = 0.75 //Initial scale of the missile  
            private constant string MISSILE_SFX = "Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl" //SFX of the missile
            private constant string MISSILE_ATTACH = "chest"
        endglobals
       
        private function Damage takes integer lvl, real time returns real
            return 15.+15*lvl + 30*time
        endfunction  
             
        private struct Data extends xeprojectile //Struct must extend xeprojectile. Consider this struct as the missile itself  
            unit cast
            integer lvl
            real count = 0
            method onHit takes nothing returns nothing //This method deals with when the missile reaches the target.
                call DestroyEffect(AddSpecialEffectTarget(TARGET_SFX,.target,TARGET_ATTACH)) //Note that .target came from xeprojectile
                call UnitDamageTarget(.cast,.target,Damage(.lvl,.count),false,true,ATK_TYPE,DMG_TYPE,null) //Damage is based on .count
                call .terminate() //Use terminate instead of destroy to make sure everything will get cleaned up
            endmethod
           
            method onTick takes nothing returns nothing //Method deals with every interval the missile moves. In this example, it increases .count and makes the missile bigger
                set .count = .count + XE_ANIMATION_PERIOD
                set .scale = BASE_SCALE + .count //Note that xeprojectile allows you to use xefx methods like scale
            endmethod
        endstruct
           
        private function Conditions takes nothing returns boolean
            return GetSpellAbilityId() == SPELL_ID    
        endfunction

        private function Actions takes nothing returns nothing
            local unit c = GetTriggerUnit()
            local unit s = GetSpellTargetUnit()
            local real ang = Atan2(GetUnitY(s) - GetUnitY(c),GetUnitX(s) - GetUnitX(c))
            local Data D = Data.create(GetUnitX(c),GetUnitY(c),60.,ang) //The create method is the same as xeprojectile.
            //Setting the missile properties
            set D.fxpath = MISSILE_SFX //Method is from xefx, sets what the missile should look like
            set D.destroyOnHit = true //Determines if you want the missle to be destroyed on impact        
            set D.speed = SPEED        
            set D.target = s //Setting this makes the missile travel to the spell target unit
            //The following is what it would look like if you wanted the missile to travel to the target's coordinates. In this case, you don't need to set D.target to anything
                //set D.targetX = GetUnitX(s)
                //set D.targetY = GetUnitY(s)
            set D.arc = ARC
            set D.start = true //You should set all of the missile properties before doing this.
            //Sets the other variables in the struct
            set D.cast = c
            set D.lvl = GetUnitAbilityLevel(D.cast,SPELL_ID)        
            set c = null
            set s = null
        endfunction

        private function Init takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
            call TriggerAddCondition( t, Condition(function Conditions))
            call TriggerAddAction( t, function Actions )
            call Preload(MISSILE_SFX)
            call Preload(TARGET_SFX)
        endfunction
    endscope
     

    Attached Files:

  15. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,220
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    I still don't like the use of xefx and the lack of features.
    What I like is that you did xeprojectile.
     
  16. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,374
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25