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

[JASS] Im not good at JASS but

Status
Not open for further replies.
A while back XieLong made me a trigger, in JASS, so i just modified the constants and whatever, but ingame after a while, i starts to lag.. Alot. so I dont know whats wrong, but if anyone out there who is good at JASS, could fix the leak?

JASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
//***************************************************************************\\
//                             Spell Name: Attack                            \\
//                            Spell Author: XieLong                          \\
//                       Conforms to the JESP Standard                       \\
//***************************************************************************\\

//= Needed Object and their ids (Make sure to copy all objects into your map and adjust the rawcodes)
//== Abilities
//=== Attack
constant function Cactus1_SpellId takes nothing returns integer
	return 'A008' // The spell's rawcode.
endfunction

//== Units
//=== Missile Dummy
constant function Cactus1_MissileId takes nothing returns integer
	return 'n00E'
endfunction

//== Buffs
//=== B000 : Attack

//= End of ObjectIds
//===========================================================================
//= Spell datas and settings

constant function Cactus1_LaunchImprecision takes nothing returns real
	return 45.
endfunction

constant function Cactus1_MissileSpeed takes nothing returns integer
	return 1000 //covered distance per second
endfunction

constant function Cactus1_Range takes nothing returns integer
	return 400
endfunction

constant function Cactus1_MissileCollisonSize takes nothing returns real
	return 55.
endfunction

constant function Cactus1_AttackType takes nothing returns attacktype
	return ATTACK_TYPE_HERO
endfunction

function Cactus1_Damage takes nothing returns real
	return (1. + GetRandomInt(0, 0))
endfunction

//Defines what kind of units can be hit by a missile
//basicly the missile will hit any unit on her path so you have to define the 'not hitable targets'
function Cactus1_HitConditions takes unit attacker, unit target returns boolean
    if IsUnitAlly(target, GetOwningPlayer(attacker)) then
        return false
    endif
//    if (IsUnitType(target, UNIT_TYPE_STRUCTURE) == true) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_MECHANICAL) == true) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_ETHEREAL) == true ) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) == true ) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_GROUND) == true) then
//        return false
//    endif
    if (GetUnitState(target, UNIT_STATE_LIFE) <= 0.405) then
        return false
    endif
    return true
endfunction


//== Any other data/setting have to be changed within the object-editor

//= End of datas/settings
//===========================================================================
//                            *** Spell Script ***

// Conditions
function Cactus1_Conditions takes nothing returns boolean
 return ( GetSpellAbilityId() == Cactus1_SpellId() )
endfunction

function Cactus1_Effects takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit c = GetHandleUnit(t, "c")
    local unit u = GetHandleUnit(t, "u")
    local integer i = GetHandleInt(t, "i")
    local integer j = 0
    local real x = GetUnitX(u) + 18 * Cos(GetUnitFacing(u) * bj_DEGTORAD)
    local real y = GetUnitY(u) + 18 * Sin(GetUnitFacing(u) * bj_DEGTORAD)
    local unit v
    local group g = CreateGroup()
    if (i < R2I((Cactus1_Range() / 14) + .5) ) and ((GetRectMinX(GetWorldBounds()) <= x) and (x <= GetRectMaxX(GetWorldBounds())) and (GetRectMinY(GetWorldBounds()) <= y) and (y <= GetRectMaxY(GetWorldBounds()))) then
        call SetUnitX(u, x)
        call SetUnitY(u, y)
        call GroupEnumUnitsInRange(g, x, y, Cactus1_MissileCollisonSize(), null)
        call GroupRemoveUnit(g, u)
        loop
            set v = FirstOfGroup(g)
            exitwhen (v == null)
            call GroupRemoveUnit(g, v)
            if Cactus1_HitConditions(c, v) then
                call UnitDamageTarget(c, v, Cactus1_Damage(), true, false, Cactus1_AttackType(), DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
                call KillUnit(u)
                call GroupClear(g)
                set i = R2I((Cactus1_Range() / 14) + .5)
            endif
        endloop
    else
        call KillUnit(u)
        call PauseTimer(t)
        call FlushHandleLocals(t)
        call DestroyTimer(t)
    endif
    call SetHandleInt(t, "i", i+1)
    set c = null
    call DestroyGroup(g)
    set g = null
    set u = null
    set v = null
endfunction

function Cactus1_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local real f = GetUnitFacing(c)
    local integer i = 0
    local unit u
    local timer t = CreateTimer()
    set u = CreateUnit(GetOwningPlayer(c), Cactus1_MissileId(), (GetUnitX(c) + 14 * Cos(f * bj_DEGTORAD)), (GetUnitY(c) + 14 * Sin(f * bj_DEGTORAD)), ModuloReal((f + GetRandomReal(-1*Cactus1_LaunchImprecision(), Cactus1_LaunchImprecision())), 360) )
    call SetHandleHandle(t, "c", c)
    call SetHandleHandle(t, "u", u)
    call TimerStart(t, 0.02, true, function Cactus1_Effects)
    set c = null
    set u = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Cactus1 takes nothing returns nothing
	local integer i = 0
    set gg_trg_Cactus1 = CreateTrigger(  )
	loop
		call TriggerRegisterPlayerUnitEvent(gg_trg_Cactus1, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, Condition(function ReturnTrue))
		set i = i + 1
		exitwhen i == 16
	endloop
    call TriggerAddCondition( gg_trg_Cactus1, Condition( function Cactus1_Conditions ) )
    call TriggerAddAction( gg_trg_Cactus1, function Cactus1_Actions )
endfunction
 
Level 14
Joined
Nov 23, 2008
Messages
187
Just store values of minX, maxX, minY, maxY somewhere, and use it when needed. Example with global variables:

JASS:
// . . .
    if (i < R2I((Cactus1_Range() / 14) + .5) ) and (udg_xmin <= x) and (x <= udg_xmax) and (udg_ymin <= y) and (y <= udg_ymax)) then
        call SetUnitX(u, x)
        call SetUnitY(u, y)
// . . .

function InitTrig_Cactus1 takes nothing returns nothing
  local rect r = GetWorldBounds()
  // . . .
  set udg_xmin = GetRectMinX(r)
  set udg_xmax = GetRectMaxX(r)
  set udg_ymin = GetRectMinY(r)
  set udg_ymax = GetRectMaxY(r)
  call RemoveRect(r)
  set r = null
endfunction

In fact, the map size is constant in game, so there's no need to get coordinates every time unit casts the spell.
 
Just store values of minX, maxX, minY, maxY somewhere, and use it when needed. Example with global variables:

JASS:
// . . .
    if (i < R2I((Cactus1_Range() / 14) + .5) ) and (udg_xmin <= x) and (x <= udg_xmax) and (udg_ymin <= y) and (y <= udg_ymax)) then
        call SetUnitX(u, x)
        call SetUnitY(u, y)
// . . .

function InitTrig_Cactus1 takes nothing returns nothing
  local rect r = GetWorldBounds()
  // . . .
  set udg_xmin = GetRectMinX(r)
  set udg_xmax = GetRectMaxX(r)
  set udg_ymin = GetRectMinY(r)
  set udg_ymax = GetRectMaxY(r)
  call RemoveRect(r)
  set r = null
endfunction

In fact, the map size is constant in game, so there's no need to get coordinates every time unit casts the spell.

i tried this but came up with some errors,

all the set udg_xmin/max/y/min/max got errors that they expect a variable name.

what am i doing wrong?
 
thx eccho, im still getting 3 more errors however,

on these lines


JASS:
if (i < R2I((cactus1_Range() / 14) + .5) ) and (udg_xmin <= x) and (x <= udg_xmax) and (udg_ymin <= y) and (y <= udg_ymax)) then
Expected 'then'



JASS:
                call UnitDamageTarget(c, v, Seedling_Damage(), true, false, cactus1_AttackType(), DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
                call KillUnit(u)
                call GroupClear(g)
                set i = R2I((Seedling_Range() / 14) + .5)
            endif
        endloop
    [b]else[/b]
Expected 'endif'


JASS:
                set i = R2I((cactus1_Range() / 14) + .5)
            endif
        endloop
    else
        call KillUnit(u)
        call PauseTimer(t)
        call FlushHandleLocals(t)
        call DestroyTimer(t)
    [b]endif[/b]
Expected 'endif'


whats the problem now?
 
lol i was trying to bold the part thats highlighted in the error box.

JASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
//***************************************************************************\\
//                             Spell Name: Attack                            \\
//                            Spell Author: XieLong                          \\
//                       Conforms to the JESP Standard                       \\
//***************************************************************************\\

//= Needed Object and their ids (Make sure to copy all objects into your map and adjust the rawcodes)
//== Abilities
//=== Attack
constant function Seedling_SpellId takes nothing returns integer
	return 'A002' // The spell's rawcode.
endfunction

//== Units
//=== Missile Dummy
constant function Seedling_MissileId takes nothing returns integer
	return 'n001'
endfunction

//== Buffs
//=== B000 : Attack

//= End of ObjectIds
//===========================================================================
//= Spell datas and settings

constant function Seedling_LaunchImprecision takes nothing returns real
	return 0.
endfunction

constant function Seedling_MissileSpeed takes nothing returns integer
	return 1000 //covered distance per second
endfunction

constant function Seedling_Range takes nothing returns integer
	return 400
endfunction

constant function Seedling_MissileCollisonSize takes nothing returns real
	return 60.
endfunction

constant function Seedling_AttackType takes nothing returns attacktype
	return ATTACK_TYPE_HERO
endfunction

function Seedling_Damage takes nothing returns real
	return (1. + GetRandomInt(0, 0))
endfunction

//Defines what kind of units can be hit by a missile
//basicly the missile will hit any unit on her path so you have to define the 'not hitable targets'
function Seedling_HitConditions takes unit attacker, unit target returns boolean
    if IsUnitAlly(target, GetOwningPlayer(attacker)) then
        return false
    endif
//    if (IsUnitType(target, UNIT_TYPE_STRUCTURE) == true) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_MECHANICAL) == true) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_ETHEREAL) == true ) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) == true ) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_GROUND) == true) then
//        return false
//    endif
    if (GetUnitState(target, UNIT_STATE_LIFE) <= 0.405) then
        return false
    endif
    return true
endfunction


//== Any other data/setting have to be changed within the object-editor

//= End of datas/settings
//===========================================================================
//                            *** Spell Script ***

// Conditions
function Seedling_Conditions takes nothing returns boolean
 return ( GetSpellAbilityId() == Seedling_SpellId() )
endfunction

function Seedling_Effects takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit c = GetHandleUnit(t, "c")
    local unit u = GetHandleUnit(t, "u")
    local integer i = GetHandleInt(t, "i")
    local integer j = 0
    local real x = GetUnitX(u) + 16 * Cos(GetUnitFacing(u) * bj_DEGTORAD)
    local real y = GetUnitY(u) + 16 * Sin(GetUnitFacing(u) * bj_DEGTORAD)
    local unit v
    local group g = CreateGroup()
    if (i < R2I((Seedling_Range() / 14) + .5) ) and (udg_xmin <= x) and (x <= udg_xmax) and (udg_ymin <= y) and (y <= udg_ymax)) then
        call SetUnitX(u, x)
        call SetUnitY(u, y)
        call GroupEnumUnitsInRange(g, x, y, Seedling_MissileCollisonSize(), null)
        call GroupRemoveUnit(g, u)
        loop
            set v = FirstOfGroup(g)
            exitwhen (v == null)
            call GroupRemoveUnit(g, v)
            if Seedling_HitConditions(c, v) then
                call UnitDamageTarget(c, v, Seedling_Damage(), true, false, Seedling_AttackType(), DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
                call KillUnit(u)
                call GroupClear(g)
                set i = R2I((Seedling_Range() / 14) + .5)
            endif
        endloop
    else
        call KillUnit(u)
        call PauseTimer(t)
        call FlushHandleLocals(t)
        call DestroyTimer(t)
    endif
    call SetHandleInt(t, "i", i+1)
    set c = null
    call DestroyGroup(g)
    set g = null
    set u = null
    set v = null
    set t = null
endfunction

function Seedling_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local real f = GetUnitFacing(c)
    local integer i = 0
    local unit u
    local timer t = CreateTimer()
    set u = CreateUnit(GetOwningPlayer(c), Seedling_MissileId(), (GetUnitX(c) + 14 * Cos(f * bj_DEGTORAD)), (GetUnitY(c) + 14 * Sin(f * bj_DEGTORAD)), ModuloReal((f + GetRandomReal(-1*Seedling_LaunchImprecision(), Seedling_LaunchImprecision())), 360) )
    call SetHandleHandle(t, "c", c)
    call SetHandleHandle(t, "u", u)
    call TimerStart(t, 0.02, true, function Seedling_Effects)
    set c = null
    set u = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Seedling takes nothing returns nothing
  local rect r = GetWorldBounds()
	local integer i = 0
    set gg_trg_Seedling = CreateTrigger(  )
	loop
		call TriggerRegisterPlayerUnitEvent(gg_trg_Seedling, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, Condition(function ReturnTrue))
		set i = i + 1
		exitwhen i == 16
	endloop
    call TriggerAddCondition( gg_trg_Seedling, Condition( function Seedling_Conditions ) )
    call TriggerAddAction( gg_trg_Seedling, function Seedling_Actions )
  set udg_xmin = GetRectMinX(r)
  set udg_xmax = GetRectMaxX(r)
  set udg_ymin = GetRectMinY(r)
  set udg_ymax = GetRectMaxY(r)
  call RemoveRect(r)
  set r = null
endfunction


pretend its the same trigger, i just changed the name of it.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Well, it appears it is just a syntax error. There is one paranthese which shouldnt be there.

Try
if (i < R2I((Seedling_Range() / 14) + .5) and (udg_xmin <= x) and (x <= udg_xmax) and (udg_ymin <= y) and (y <= udg_ymax)) then
 
Level 14
Joined
Nov 23, 2008
Messages
187
I noticed, that you didn't initialized "i" (in game cache), so the condition (i < R2I((Seedling_Range() / 14) + .5) might return true earlier, than it should be.
Try to add this:

JASS:
// . . .
    call SetHandleHandle(t, "c", c)
    call SetHandleHandle(t, "u", u)
    // --->>
    call SetHandleInt(t, "i", 0)
    // <<---
    call TimerStart(t, 0.02, true, function Seedling_Effects)
// . . .
 
EDIT: ok so it works all properly now, but i feel as though it still leaks.

JASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
//***************************************************************************\\
//                             Spell Name: Attack                            \\
//                            Spell Author: XieLong                          \\
//                       Conforms to the JESP Standard                       \\
//***************************************************************************\\

//= Needed Object and their ids (Make sure to copy all objects into your map and adjust the rawcodes)
//== Abilities
//=== Attack
constant function Seedling_SpellId takes nothing returns integer
	return 'A002' // The spell's rawcode.
endfunction

//== Units
//=== Missile Dummy
constant function Seedling_MissileId takes nothing returns integer
	return 'n001'
endfunction

//== Buffs
//=== B000 : Attack

//= End of ObjectIds
//===========================================================================
//= Spell datas and settings

constant function Seedling_LaunchImprecision takes nothing returns real
	return 0.
endfunction

constant function Seedling_MissileSpeed takes nothing returns integer
	return 1000 //covered distance per second
endfunction

constant function Seedling_Range takes nothing returns integer
	return 400
endfunction

constant function Seedling_MissileCollisonSize takes nothing returns real
	return 60.
endfunction

constant function Seedling_AttackType takes nothing returns attacktype
	return ATTACK_TYPE_HERO
endfunction

function Seedling_Damage takes nothing returns real
	return (1. + GetRandomInt(0, 0))
endfunction

//Defines what kind of units can be hit by a missile
//basicly the missile will hit any unit on her path so you have to define the 'not hitable targets'
function Seedling_HitConditions takes unit attacker, unit target returns boolean
    if IsUnitAlly(target, GetOwningPlayer(attacker)) then
        return false
    endif
    if (IsUnitType(target, UNIT_TYPE_STRUCTURE) == true) then
        return false
    endif
//    if (IsUnitType(target, UNIT_TYPE_MECHANICAL) == true) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_ETHEREAL) == true ) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) == true ) then
//        return false
//    endif
//    if (IsUnitType(target, UNIT_TYPE_GROUND) == true) then
//        return false
//    endif
    if (GetUnitState(target, UNIT_STATE_LIFE) <= 0.405) then
        return false
    endif
    return true
endfunction


//== Any other data/setting have to be changed within the object-editor

//= End of datas/settings
//===========================================================================
//                            *** Spell Script ***

// Conditions
function Seedling_Conditions takes nothing returns boolean
 return ( GetSpellAbilityId() == Seedling_SpellId() )
endfunction

function Seedling_Effects takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit c = GetHandleUnit(t, "c")
    local unit u = GetHandleUnit(t, "u")
    local integer i = GetHandleInt(t, "i")
    local integer j = 0
    local real x = GetUnitX(u) + 16 * Cos(GetUnitFacing(u) * bj_DEGTORAD)
    local real y = GetUnitY(u) + 16 * Sin(GetUnitFacing(u) * bj_DEGTORAD)
    local unit v
    local group g = CreateGroup()
    if (i < R2I((Seedling_Range() / 14) + .5) and (udg_xmin <= x) and (x <= udg_xmax) and (udg_ymin <= y) and (y <= udg_ymax)) then
        call SetUnitX(u, x)
        call SetUnitY(u, y)
        call GroupEnumUnitsInRange(g, x, y, Seedling_MissileCollisonSize(), null)
        call GroupRemoveUnit(g, u)
        loop
            set v = FirstOfGroup(g)
            exitwhen (v == null)
            call GroupRemoveUnit(g, v)
            if Seedling_HitConditions(c, v) then
                call UnitDamageTarget(c, v, Seedling_Damage(), true, false, Seedling_AttackType(), DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
                call KillUnit(u)
                call GroupClear(g)
                set i = R2I((Seedling_Range() / 14) + .5)
            endif
        endloop
    else
        call KillUnit(u)
        call PauseTimer(t)
        call FlushHandleLocals(t)
        call DestroyTimer(t)
    endif
    call SetHandleInt(t, "i", i+1)
    set c = null
    call DestroyGroup(g)
    set g = null
    set u = null
    set v = null
    set t = null
endfunction

function Seedling_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local real f = GetUnitFacing(c)
    local integer i = 0
    local unit u
    local timer t = CreateTimer()
    set u = CreateUnit(GetOwningPlayer(c), Seedling_MissileId(), (GetUnitX(c) + 14 * Cos(f * bj_DEGTORAD)), (GetUnitY(c) + 14 * Sin(f * bj_DEGTORAD)), ModuloReal((f + GetRandomReal(-1*Seedling_LaunchImprecision(), Seedling_LaunchImprecision())), 360) )
    call SetHandleHandle(t, "c", c)
    call SetHandleHandle(t, "u", u)
    call SetHandleInt(t, "i", 0)
    call TimerStart(t, 0.02, true, function Seedling_Effects)
    set c = null
    set u = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Seedling takes nothing returns nothing
  local rect r = GetWorldBounds()
	local integer i = 0
    set gg_trg_Seedling = CreateTrigger(  )
	loop
		call TriggerRegisterPlayerUnitEvent(gg_trg_Seedling, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, Condition(function ReturnTrue))
		set i = i + 1
		exitwhen i == 16
	endloop
    call TriggerAddCondition( gg_trg_Seedling, Condition( function Seedling_Conditions ) )
    call TriggerAddAction( gg_trg_Seedling, function Seedling_Actions )
  set udg_xmin = GetRectMinX(r)
  set udg_xmax = GetRectMaxX(r)
  set udg_ymin = GetRectMinY(r)
  set udg_ymax = GetRectMaxY(r)
  call RemoveRect(r)
  set r = null
endfunction

EDIT2: Maybe not leaking But can anyone check for me please?
 
Last edited:
Status
Not open for further replies.
Top