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

[JASS] Find the caster on projectile collision (cs16.0)

Status
Not open for further replies.
Level 14
Joined
Jul 26, 2008
Messages
1,009
Alright I'm using Vexorian's Caster System 16.0 and wanted to make a Fireball spell. Basically the fireball explodes upon contact and then knocks back enemies while damaging them. Simple 'nuff and nice since I don't know crap for math.

However, since the code can't take anything I don't know how to get the caster on collision without losing MUI/MPI (Not an option). I was thinking of doing some structs and methods but am clueless on how to call the data on them back up once created.

Any help or ideas? +rep :3

JASS:
// function CollisionMissile_Create      takes string MissileModelPath, real x, real y, real dirangle, real speed, real AngleSpeed, real MaxDist,  real height, boolean UseNewCaster, real Collision, code OnImpact returns unit


scope Fireball initializer Init

globals
    private constant integer SPELLID = 'FiBa'
    private constant string MisModel = "Abilities\\Weapons\\RedDragonBreath\\RedDragonMissile.mdl"
    private constant attacktype atk = ATTACK_TYPE_MAGIC
    private constant damagetype dmg = DAMAGE_TYPE_NORMAL
    private unit TempUnit
endglobals

private function GroupCheck takes nothing returns boolean
 local real dam1 = GetUnitAbilityLevel(TempUnit, SPELLID)*50 + 20
 local real dam
 local real a
 local integer INT = GetHeroInt(TempUnit, true)
 local integer lvl = GetUnitLevel(TempUnit)
 
    if IsUnitType(TempUnit, UNIT_TYPE_HERO) then
        set dam = dam1 + INT*2
    else
        set dam = dam1 + lvl*10
    endif
    
    if IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(TempUnit)) and GetWidgetLife(GetFilterUnit()) > 0.405 and not(IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)) then
     set a = 57.29582 * Atan2(GetUnitY(GetFilterUnit()) - GetUnitY(TempUnit), GetUnitX(GetFilterUnit()) - GetUnitX(TempUnit))
        call UnitDamageTarget(TempUnit, GetFilterUnit(), dam, true, false, atk, dmg, null)
        call KnockbackTarget(TempUnit, GetFilterUnit(), a, 250., 700., true, false, false, "Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl")
    endif
    
    return true
endfunction

private function OnImpact takes nothing returns nothing
 local group g = NewGroup()
 local unit c = GetTriggerUnit()
    call GroupEnumUnitsInRange(g, GetUnitX(c), GetUnitY(c), 175, function GroupCheck)
 set c = null
 call ReleaseGroup(g)
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELLID
endfunction

private function Actions takes nothing returns nothing
 local unit c = GetTriggerUnit()
    call CollisionMissile_Create(MisModel, GetSpellTargetX(), GetSpellTargetY(), AngleBetweenPoints(GetUnitLoc(c), GetSpellTargetLoc()), 900, 0, 1100, 25, true, 125, OnImpact)
 set c = null
endfunction

//===========================================================================
public function Init takes nothing returns nothing
 local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition(t, function Conditions )
    call TriggerAddAction(t, function Actions )
endfunction

endscope
 
E.g.:
JASS:
struct Initiate
 unit u
 real x
 real y

    public method XY takes nothing returns nothing
     set .u = GetTriggerUnit()
     set .x = GetUnitX (.u)
     set .y = GetUnitY (.u)
    endmethod
endstruct

function OhBay takes nothing returns nothing
     local Initiate I = Initiate.create()
     call CreateUnit(GetOwningPlayer(I.u),'hfoo', I.x, I.y, 270)
endfunction

P.S. Thanks to PurgeandFire111 for letting me know of structs.
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
K I've simulated what you've displayed but the first and foremost error is this:

"Undeclared variable this" for

JASS:
    function s__Fireball__Data_XY takes nothing returns nothing
     set s__Fireball__Data_c[this]=GetTriggerUnit()  //<<<<<
    endfunction

Which is essentially the entirity of the struct and method.

Further, anything with a . syntax outside of the function where the struct is created will result in an error such as D is not of a type that allows . syntax, I assume because the function is unable to call the data of the struct inside functions that don't either create or recall it.

I've used timerutils to transfer data, but this doesn't require a timer so I'm at a loss on how to transfer the data in this case.

This is my attempt to use your suggested fix in my trigger, so that you can be sure if I am doing something incorrectly.

JASS:
scope Fireball initializer Init

globals
    private constant integer SPELLID = 'FiBa'
    private constant string MisModel = "Abilities\\Weapons\\RedDragonBreath\\RedDragonMissile.mdl"
    private constant attacktype atk = ATTACK_TYPE_MAGIC
    private constant damagetype dmg = DAMAGE_TYPE_NORMAL
    //private unit TempUnit
endglobals

private struct Data

    unit c
    
    static method XY takes nothing returns nothing
     set .c = GetTriggerUnit()
    endmethod
    
endstruct

private function GroupCheck takes nothing returns boolean
 local real dam1 = GetUnitAbilityLevel(D.c, SPELLID)*50 + 20
 local real dam
 local real a
 local integer INT = GetHeroInt(D.c, true)
 local integer lvl = GetUnitLevel(D.c)
 
    if IsUnitType(D.c, UNIT_TYPE_HERO) then
        set dam = dam1 + INT*2
    else
        set dam = dam1 + lvl*10
    endif
    
    if IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(D.c)) and GetWidgetLife(GetFilterUnit()) > 0.405 and not(IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)) then
     set a = 57.29582 * Atan2(GetUnitY(GetFilterUnit()) - GetUnitY(D.c), GetUnitX(GetFilterUnit()) - GetUnitX(D.c))
        call UnitDamageTarget(D.c, GetFilterUnit(), dam, true, false, atk, dmg, null)
        call KnockbackTarget(D.c, GetFilterUnit(), a, 250., 700., true, false, false, "Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl")
    endif
    
    return true
endfunction

private function OnImpact takes nothing returns nothing
 local group g = NewGroup()
 local unit c = GetTriggerUnit()
    call GroupEnumUnitsInRange(g, GetUnitX(c), GetUnitY(c), 175, function GroupCheck)
 set c = null
 call ReleaseGroup(g)
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELLID
endfunction

private function Actions takes nothing returns nothing
 local unit c = GetTriggerUnit()
 local Data D = Data.create()
    call CollisionMissile_Create(MisModel, GetSpellTargetX(), GetSpellTargetY(), AngleBetweenPoints(GetUnitLoc(c), GetSpellTargetLoc()), 900, 0, 1100, 25, true, 125, function OnImpact)
 set c = null
endfunction

//===========================================================================
public function Init takes nothing returns nothing
 local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition(t, function Conditions )
    call TriggerAddAction(t, function Actions )
endfunction

endscope

Also, I'm using xe as well. Unfortunately I'm still so minimum in vJASS that xe confuses the hell out of me.
 
Status
Not open for further replies.
Top