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

[JASS] Its about to collapse

Status
Not open for further replies.
Level 19
Joined
Aug 24, 2007
Messages
2,888
I have a very weird spell here which I still wonder why it works

[Jass="here"]scope Chidori // Must be same with trigger name

globals
private real TimerPeriod = 0.035 // Changing means death
private real Damage
private real DamageIPS
private real Speed
private real SpeedIPS
private real DamageM
private real SpeedM
private player neutral = Player(15)

//! -------------- SETUP STARTS --------------

// Spell Raw Code in object Editor
private constant integer SpellId = 'A001'
// Chidori Impact Effect
private constant string ChidoriFX = "Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl"
// Chidori Charging Effect
private constant string LightningFX = "Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl"
private constant string LightningPoint = "weapon"
// Preloading (NO I WONT EXPLAIN)
private constant real PreloadAfter = 0.
endglobals


private function Setup takes integer ability_level,integer hero_level, integer str,integer agi,integer int returns nothing
// Base damage without time bonus
set Damage = 300.0 + ability_level*100.0 + 0*hero_level + str*0 + agi*0 + int*0
// Damage Bonus added per second
set DamageIPS = 100. + ability_level*50
// Base Speed bonus
set Speed = 50. + ability_level*50
// Speed bonus per second
set SpeedIPS = 50. + ability_level*10
// Maximum Speed Bonus to reach
set SpeedM = 600.
// Maximum Damage Bonus to reach
set DamageM = 5000. // Lul H4X ...
endfunction

// ability_level = Ability Level of the Spell
// hero_level = Level of Casting Hero
// str = Strenght of Casting Hero
// agi = Agility of Casting Hero
// int = Intelligence of Casting Hero

//! ---------- SETUP ENDS -------------

public function PreloadSpell takes nothing returns nothing
call Preload(ChidoriFX)
call Preload(LightningFX)
endfunction

private struct U
unit t
boolean a
integer i
endstruct

private struct S
unit c
unit t
integer i
real d
real di
real s
real si
real dm
real sm
effect e
integer con
integer id
endstruct

private struct F
unit u
integer a
endstruct

private function Fader takes nothing returns nothing
local F a = GetData(GetExpiredTimer())
if a.a <= 0 then
call RemoveUnit(a.u)
call a.destroy()
call DestroyTimer(GetExpiredTimer())
return
endif
set a.a = a.a-30
call SetUnitVertexColor(a.u,100,100,100,a.a)
endfunction


private function TimerFunc takes nothing returns nothing
local S s = GetData(GetExpiredTimer())
local U s2 = GetData(s.c)
local real r1 = GetUnitX(s.c)
local real r2 = GetUnitY(s.c)
local real r3 = GetUnitFacing(s.c)*bj_DEGTORAD
local real r4 = GetUnitX(s.t)
local real r5 = GetUnitY(s.t)

// PROBLEM
local F a
local timer f

if ModuloInteger(s.con,R2I(4000./s.s)) == 0 then
set a = F.create()
set f = CreateTimer()
set a.u = CreateUnit(neutral,s.id,0.,0.,r3*bj_RADTODEG)
call SetUnitPathing(a.u,false)
call SetUnitPosition(a.u,r1,r2)
call UnitAddAbility(a.u,'Aloc')
call SetUnitVertexColor(a.u,100,100,100,255)
call SetUnitTimeScale(a.u,0.)
call SetData(f,a)
call TimerStart(f,0.035,true,function Fader)
set a.a = 255
set f= null
endif
// ENDPROBLEM
if not (s2.a and s.i == s2.i) then
call SetUnitPathing(s.c,true)
call SetUnitTimeScale(s.c,1.)
call DestroyEffect(s.e)
call s.destroy()
call DestroyTimer(GetExpiredTimer())
return
endif


call SetUnitTimeScale(s.c,(GetUnitMoveSpeed(s.c)+s.s)/250)
call SetUnitX(s.c,r1+Cos(r3)*s.s*TimerPeriod)
call SetUnitY(s.c,r2+Sin(r3)*s.s*TimerPeriod)
set s.d = RMinBJ(s.d+s.di*TimerPeriod,s.dm)
set s.s = RMinBJ(s.s+s.si*TimerPeriod,s.sm)



if SquareRoot((r5-r2)*(r5-r2)+(r4-r1)*(r4-r1)) < 150 then
set s2.a = false
call DestroyEffect(AddSpecialEffect(ChidoriFX,r4,r5))
call UnitDamageTarget(s.c,s.t,s.d,true,true,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_UNKNOWN,WEAPON_TYPE_WHOKNOWS)
endif
set s.con = s.con+1
endfunction

private function SpellCast takes nothing returns nothing
local unit caster = GetTriggerUnit()
local timer t = CreateTimer()
local integer level = GetUnitAbilityLevel(caster,GetSpellAbilityId())
local integer hlevel = GetHeroLevel(caster)
local integer agi = GetHeroAgi(caster,true)
local integer int = GetHeroInt(caster,true)
local integer str = GetHeroStr(caster,true)
local S s = S.create()
local U s2
call Setup(level,hlevel,str,agi,int)
if GetData(caster) == 0 then
call SetData(caster,U.create())
endif
set s2 = GetData(caster)
set s.c = caster
set s2.i = s2.i +1
set s.i = s2.i
set s.t = GetSpellTargetUnit()
set s2.t = s.t
set s2.a = true
set s.d = Damage
set s.s = Speed
set s.di = DamageIPS
set s.si = SpeedIPS
set s.dm = DamageM
set s.sm = SpeedM
set s.id = GetUnitTypeId(s.c)
set s.e = AddSpecialEffectTarget(LightningFX,caster,LightningPoint)
call SetUnitPathing(caster,false)
call SetData(t,s)
call IssueTargetOrder(caster,"attack",s.t)
call TimerStart(t,TimerPeriod,true,function TimerFunc)
set t = null
set caster = null
endfunction

private function CANCEL takes nothing returns nothing
local U s = GetData(GetTriggerUnit())
if GetOrderTarget() != s.t then
set s.a = false
endif
endfunction

private function CConditions takes nothing returns boolean
return GetData(GetTriggerUnit()) != 0
endfunction

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

//===========================================================================
public function InitTrig takes nothing returns nothing
local trigger spell = CreateTrigger()
local integer i = 0
loop
exitwhen i == 16
call TriggerRegisterPlayerUnitEvent(spell,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
set i = i+1
endloop
call TriggerAddCondition(spell,Condition(function Conditions))
call TriggerAddAction(spell,function SpellCast)

set spell = CreateTrigger()
set i = 0
loop
exitwhen i == 16
call TriggerRegisterPlayerUnitEvent(spell,Player(i),EVENT_PLAYER_UNIT_ISSUED_ORDER,null)
call TriggerRegisterPlayerUnitEvent(spell,Player(i),EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER,null)
call TriggerRegisterPlayerUnitEvent(spell,Player(i),EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER,null)
set i = i+1
endloop
call TriggerAddCondition(spell,Condition(function CConditions))
call TriggerAddAction(spell,function CANCEL)
if PreloadAfter >= 0 then
call TimerStart(CreateTimer(),PreloadAfter,false,function PreloadSpell)
elseif PreloadAfter == -1 then
call PreloadSpell()
endif
endfunction

endscope[/code]


Problems: Caster stops spell when moving to target (it still keeps his attack order and still keeps walking at target but timer and lightning ball gets destroyed)
If I delete the part between PROLEM-ENDPROBLEM comments it works perfectly fine
So I tought its maybe because of some thread limit problem
because creating shadow images has nothing to do with spell itself

I attached the map
But you need to save once before testing (my Jass NewGen pack in moms office doesnt work properly <maybe cause of old wc3 version or maybe low system>)
!!! Most importantly Change the code in Chidori trigger with the one I posted here !!!
 
Last edited:
Status
Not open for further replies.
Top