• 🏆 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] Improve Spell System wont work D:

Status
Not open for further replies.
ok, so i made a system in jass that works like this, You cast a spell a certain ammount of times and it goes to the next level, but i cant get it to work. Any suggestions?


JASS:
globals
    integer iscount   = 1                // How many spells there are, no changes needed
    spell array spells               // The Spells, No changes needed
    constant real impdt = 0.5 // Update timer for spells
endglobals
// dont touch from here on unless you know what your doing
struct spell
    integer spellid
    integer levels
    integer levelupcount
    integer maxlevel
    integer casted
    unit caster
    integer ID
    
    static method create takes integer sid, integer l, integer c, integer m, unit ca returns spell
        local spell s = spell.allocate()
        set s.spellid = sid
        set s.levels = l
        set s.levelupcount = c
        set s.maxlevel = m
        set s.caster = ca
        set s.casted = 0
        set s.ID = iscount
        return s
    endmethod
    

endstruct

function GetSpellCaster takes spell s returns unit
    local unit u = s.caster
    return u
endfunction

function GetSpellCasted takes spell s returns integer
    local integer i = s.casted
    return i
endfunction

function GetSpellMaxCasts takes spell s returns integer
    local integer m = s.levelupcount
    return m
endfunction

function GetSpellMaxLevel takes spell s returns integer
    local integer ml = s.maxlevel
    return ml
endfunction

function GetSpellAbilCode takes spell s returns integer
    local integer abl = s.spellid
    return abl
endfunction

function GetSpellID takes spell s returns integer
    local integer i = s.ID
    return i
endfunction

function GetSpellID2 takes unit c, integer a returns spell
    local integer i
    local integer ID
    local spell s
    local spell d
    loop
     exitwhen i > iscount
     set s = spells[i]
     if ( c == s.caster ) then
      if (a == s.spellid ) then
      set a = spells[i]
      endif
     endif
    endloop
    return d
endfunction
    

function AddSpell takes integer sid, integer l, integer c, integer m, unit u returns nothing
    local spell s = spell.create(sid,l,c,m,u)
    set spells[iscount] = s
    set iscount = (iscount + 1)
endfunction

function UpdateSpells takes nothing returns nothing
    local integer i = 0
    local integer abl
    local integer ca 
    local integer mc
    local integer ml
    local unit cs
    local integer sl
    local spell s
    loop
     exitwhen i > iscount
     set s = spells[i]
     set ca = GetSpellCasted(s)
     set mc = GetSpellMaxCasts(s)
     set ml = GetSpellMaxLevel(s)
     set cs = GetSpellCaster(s)
     set abl = GetSpellAbilCode(s)
     set sl = GetUnitAbilityLevel(cs,abl)
     
     if ( ca > mc ) then
      if ( sl < ml ) then
       call SetUnitAbilityLevel(cs,abl,(sl + 1))
       call DisplayTextToForce( bj_FORCE_PLAYER[GetPlayerId(GetOwningPlayer(cs))], "Congratulations, your spell has advanced to the next level" )
       endif
     endif
     
    endloop
     
      
    
endfunction

function IncreaseCasts takes spell s returns nothing
    local integer i = GetSpellID(s)
    set spells[i].casted = ( spells[i].casted + 1)
endfunction

function InitImpSpell takes nothing returns nothing
    local timer t = CreateTimer()
    call TimerStart(t,impdt,false,function UpdateSpells)
endfunction
That is the main system, then i have two other triggers that look like this

JASS:
function Trig_imp_Actions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local integer i = GetSpellAbilityId()
    local spell q = GetSpellID2(u,i)
    call IncreaseCasts(q)
    
endfunction

//===========================================================================
function InitTrig_imp takes nothing returns nothing
    set gg_trg_imp = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_imp, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_imp, function Trig_imp_Actions )
endfunction




And this

  • Init Improv Spell
    • Events
      • Time - Elapsed game time is 0.05 seconds
    • Conditions
    • Actions
      • Set unit = Testazor 0000 <gen>
      • Custom script: call InitImpSpell()
      • Custom script: call AddSpell('A000',3,2,3,udg_unit)
Any suggestions are welcome, i am an amateur jasser and know nothing about the advanced ways
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
JASS:
function GetSpellCaster takes spell s returns unit
    local unit u = s.caster
    return u
endfunction

function GetSpellCasted takes spell s returns integer
    local integer i = s.casted
    return i
endfunction

function GetSpellMaxCasts takes spell s returns integer
    local integer m = s.levelupcount
    return m
endfunction

function GetSpellMaxLevel takes spell s returns integer
    local integer ml = s.maxlevel
    return ml
endfunction

function GetSpellAbilCode takes spell s returns integer
    local integer abl = s.spellid
    return abl
endfunction

function GetSpellID takes spell s returns integer
    local integer i = s.ID
    return i
endfunction

What? No. Never.

And if you're learning jass why don't u just do everything in jass?
 
I did, never got a message, guessing something else is wrong besides that



edit: I found the center of the problem, it is in
JASS:
function Trig_imp_Actions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local integer i = GetSpellAbilityId()
    local spell q = GetSpellID2(u,i)
    call BJDebugMsg("Registered")
    call IncreaseCasts(q)
    
endfunction

//===========================================================================
function InitTrig_imp takes nothing returns nothing
    set gg_trg_imp = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_imp, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_imp, function Trig_imp_Actions )
endfunction
Whenever i cast a spell i never get the debug message
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
JASS:
function GetSpellID2 takes unit c, integer a returns spell
    local integer i
    local integer ID
    local spell s
    local spell d
    loop
     exitwhen i > iscount
     set s = spells[i]
     if ( c == s.caster ) then
      if (a == s.spellid ) then
      set a = spells[i]
      endif
     endif
    endloop
    return d
endfunction
This is broken on so many levels. You don't increment i, and you don't initialize a bunch of variables that you try to use.

Also, why are you just randomly setting a to something you don't use? Also, use and.
 
Status
Not open for further replies.
Top