HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Collision Issues

06-19-2009, 09:42 PM#1
DeathRing
I'm having trouble with this Gun Firing spell I made. It seems to have trouble colliding with enemy units that are close to the spell caster. Here's the trigger:
Collapse JASS:
scope FireShotgun

    globals
        private constant integer SPELL_ID  = 'A006'

//=======================================================================
// ONLY MODIFY THESE VALUES WITHIN THE GREEN LINES

        //Modifies the damage of the missile
        private constant real MISSILE_DAMAGE = 8.

        //Modifies the model of the missile
        private constant string MISSILE_SFX = "Bulletsmall.MDX"
        
        private constant string MUZZLE_FLASH = "Konstrukt_ShotgunEffektAttachment.MDX"
        
        //Modifies the speed of the missile
        private constant real MISSILE_SPEED = 2200.00
        
        //Modifies the turning speed of the missile
        private constant real MISSILE_ANGLESPEED = 0.00
        
        //Modifies the maximum distance traveled by the missile
        private constant real MISSILE_MAXDIST = 2500.00
        
        //Modifies the actucal height from where the missile is fired
        private constant real MISSILE_HEIGHT = 25.00
        
        //Modifies the collision radius of the missile
        private constant real MISSILE_COLLISION = 80.00
        
    
//=======================================================================
        private constant string BLOOD_SFX = "Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl"
        
        private trigger SPELL_TRIGGER
        private constant attacktype ATTACKTYPE = ATTACK_TYPE_CHAOS
        private constant damagetype DAMAGETYPE = DAMAGE_TYPE_FIRE
    endglobals


    private struct Missile_Data
        unit target
        unit u
    endstruct
    
    
    private function missile_hit takes nothing returns nothing
        local unit m=GetTriggerCollisionMissile()
        local Missile_Data T = Missile_Data( CollisionMissile_GetTag(m) ) //See how we are using CollisionMissile tags instead of CSData.

        local unit o = T.u
        local player po = GetOwningPlayer(o)
        local unit u = GetTriggerUnit()
        local integer l
        local integer s
        local real f
        local timer x

        
        if IsUnitEnemy(u,po)==true then
            call UnitDamageTarget(o,u,MISSILE_DAMAGE,true,false,ATTACKTYPE,DAMAGETYPE, null)
            call DestroyEffect(AddSpecialEffectTarget(BLOOD_SFX,u,"chest"))
            call CollisionMissile_Destroy(m)
            call T.destroy()
        endif
        
        if (u==null) then
            call T.destroy() //cleanup the missile
        endif
         set u=null
         set m=null
         set o=null
    endfunction
    
    
    
    
    private function casting takes nothing returns nothing
        local Missile_Data T = Missile_Data.create()
        local unit u = GetTriggerUnit()
        local player pu = GetOwningPlayer(u)
        local unit m
        local location loc = GetSpellTargetLoc()
        local location loc2 = GetUnitLoc(u)
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local real angle = AngleBetweenPoints(loc2,loc)
        local real angle2 = 0.
        local integer gold = GetPlayerState(pu, PLAYER_STATE_RESOURCE_GOLD)
        local integer i = 0

                
        call SetUnitAnimation(u,"Attack")
        
        if gold >= 1 then
            call DestroyEffect(AddSpecialEffectTarget(MUZZLE_FLASH,u,"weapon"))
            loop
                exitwhen i==7
                set angle2 = angle + GetRandomReal(-15.,15.)
                set m = CollisionMissile_Create(MISSILE_SFX,x,y,angle2,(MISSILE_SPEED),0.00,(MISSILE_MAXDIST-GetRandomReal(-100.,100.)),MISSILE_HEIGHT,false,MISSILE_COLLISION,function missile_hit)
           
                call CollisionMissile_SetTag(m,integer(T) )
                call SetPlayerState(pu,PLAYER_STATE_RESOURCE_GOLD,(gold-1))
                set i = i + 1
            endloop
            set T.u = u
        else
            call CS_Error(pu,"No ammo!")
        endif
        
        
        call RemoveLocation(loc)
        call RemoveLocation(loc2)
        
        set u = null
        set m = null
        set loc = null
        set loc2 = null
    endfunction

//===========================================================================
    public function InitTrig takes nothing returns nothing
        call OnAbilityEffect(SPELL_ID, SCOPE_PRIVATE+"casting")
    endfunction
    
endscope

Sorry if its not understood well, I'm still trying to make it friendly for everyone!

Great, great thanks in advance.
06-19-2009, 10:36 PM#2
Vexorian
Try this:
Collapse JASS:
scope FireShotgun

    globals
        private constant integer SPELL_ID  = 'A006'

//=======================================================================
// ONLY MODIFY THESE VALUES WITHIN THE GREEN LINES

        //Modifies the damage of the missile
        private constant real MISSILE_DAMAGE = 8.

        //Modifies the model of the missile
        private constant string MISSILE_SFX = "Bulletsmall.MDX"
        
        private constant string MUZZLE_FLASH = "Konstrukt_ShotgunEffektAttachment.MDX"
        
        //Modifies the speed of the missile
        private constant real MISSILE_SPEED = 2200.00
        
        //Modifies the turning speed of the missile
        private constant real MISSILE_ANGLESPEED = 0.00
        
        //Modifies the maximum distance traveled by the missile
        private constant real MISSILE_MAXDIST = 2500.00
        
        //Modifies the actucal height from where the missile is fired
        private constant real MISSILE_HEIGHT = 25.00
        
        //Modifies the collision radius of the missile
        private constant real MISSILE_COLLISION = 80.00
        
    
//=======================================================================
        private constant string BLOOD_SFX = "Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl"
        
        private trigger SPELL_TRIGGER
        private constant attacktype ATTACKTYPE = ATTACK_TYPE_CHAOS
        private constant damagetype DAMAGETYPE = DAMAGE_TYPE_FIRE
    endglobals


    private struct Missile_Data
        unit target
        unit u
    endstruct
    
    
    private function missile_hit takes nothing returns nothing
        local unit m=GetTriggerCollisionMissile()
        local Missile_Data T = Missile_Data( CollisionMissile_GetTag(m) ) //See how we are using CollisionMissile tags instead of CSData.

        local unit o = T.u
        local player po = GetOwningPlayer(o)
        local unit u = GetTriggerUnit()
        local integer l
        local integer s
        local real f
        local timer x

        call BJDebugMsg("The target is "+GetUnitName(u)+I2S(CS_H2I(u) ) )
         call BJDebugMsg("The caster is "+GetUnitName(o)+I2S(CS_H2I(o) ) )
        if IsUnitEnemy(u,po)==true then
            call UnitDamageTarget(o,u,MISSILE_DAMAGE,true,false,ATTACKTYPE,DAMAGETYPE, null)
            call DestroyEffect(AddSpecialEffectTarget(BLOOD_SFX,u,"chest"))
            call CollisionMissile_Destroy(m)
            call T.destroy()
        endif
        
        if (u==null) then
            call T.destroy() //cleanup the missile
        endif
         set u=null
         set m=null
         set o=null
    endfunction
    
    
    
    
    private function casting takes nothing returns nothing
        local Missile_Data T = Missile_Data.create()
        local unit u = GetTriggerUnit()
        local player pu = GetOwningPlayer(u)
        local unit m
        local location loc = GetSpellTargetLoc()
        local location loc2 = GetUnitLoc(u)
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local real angle = AngleBetweenPoints(loc2,loc)
        local real angle2 = 0.
        local integer gold = GetPlayerState(pu, PLAYER_STATE_RESOURCE_GOLD)
        local integer i = 0

                
        call SetUnitAnimation(u,"Attack")
        
        if gold >= 1 then
            call DestroyEffect(AddSpecialEffectTarget(MUZZLE_FLASH,u,"weapon"))
            loop
                exitwhen i==7
                set angle2 = angle + GetRandomReal(-15.,15.)
                set m = CollisionMissile_Create(MISSILE_SFX,x,y,angle2,(MISSILE_SPEED),0.00,(MISSILE_MAXDIST-GetRandomReal(-100.,100.)),MISSILE_HEIGHT,false,MISSILE_COLLISION,function missile_hit)
           
                call CollisionMissile_SetTag(m,integer(T) )
                call SetPlayerState(pu,PLAYER_STATE_RESOURCE_GOLD,(gold-1))
                set i = i + 1
            endloop
            set T.u = u
        else
            call CS_Error(pu,"No ammo!")
        endif
        
        
        call RemoveLocation(loc)
        call RemoveLocation(loc2)
        
        set u = null
        set m = null
        set loc = null
        set loc2 = null
    endfunction

//===========================================================================
    public function InitTrig takes nothing returns nothing
        call OnAbilityEffect(SPELL_ID, SCOPE_PRIVATE+"casting")
    endfunction
    
endscope
Tell me what messages you see when the missile is created near those "enemy units that are close to the caster."
06-20-2009, 01:46 AM#3
DeathRing
Using that trigger ya modified Vexorian, it says "The target is 0. The caster is Combat Marine1049425" and it repeats that 7 times.
06-21-2009, 03:05 AM#4
DeathRing
Whoops, meant it repeated it 6 times.