1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] Handling Help

Discussion in 'Triggers & Scripts' started by ZlatniLav, Jan 4, 2009.

  1. ZlatniLav

    ZlatniLav

    Joined:
    Dec 13, 2008
    Messages:
    196
    Resources:
    0
    Resources:
    0
    I want to make MUI knockback ability, so i looked at some tutorials and copied this into my map script, and made init trigger for game cache udg_g (create cache, save, set variable):

    Code (vJASS):
    // ===========================
    function H2I takes handle h returns integer
        return h
        return 0
    endfunction

    // ===========================
    function LocalVars takes nothing returns gamecache
        return udg_g
    endfunction

    function SetHandleHandle takes handle subject, string name, handle value returns nothing
        if value==null then
            call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
        else
            call StoreInteger(LocalVars(), I2S(H2I(subject)), name, H2I(value))
        endif
    endfunction

    function SetHandleInt takes handle subject, string name, integer value returns nothing
        if value==0 then
            call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
        else
            call StoreInteger(LocalVars(), I2S(H2I(subject)), name, value)
        endif
    endfunction

    function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
        if value==false then
            call FlushStoredBoolean(LocalVars(),I2S(H2I(subject)),name)
        else
            call StoreBoolean(LocalVars(), I2S(H2I(subject)), name, value)
        endif
    endfunction

    function SetHandleReal takes handle subject, string name, real value returns nothing
        if value==0 then
            call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
        else
            call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
        endif
    endfunction

    function SetHandleString takes handle subject, string name, string value returns nothing
        if value==null then
            call FlushStoredString(LocalVars(), I2S(H2I(subject)), name)
        else
            call StoreString(LocalVars(), I2S(H2I(subject)), name, value)
        endif
    endfunction

    function GetHandleHandle takes handle subject, string name returns handle
        return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
        return null
    endfunction
    function GetHandleInt takes handle subject, string name returns integer
        return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    endfunction
    function GetHandleBoolean takes handle subject, string name returns boolean
        return GetStoredBoolean(LocalVars(), I2S(H2I(subject)), name)
    endfunction
    function GetHandleReal takes handle subject, string name returns real
        return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
    endfunction
    function GetHandleString takes handle subject, string name returns string
        return GetStoredString(LocalVars(), I2S(H2I(subject)), name)
    endfunction

    function GetHandleUnit takes handle subject, string name returns unit
        return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
        return null
    endfunction
    function GetHandleTimer takes handle subject, string name returns timer
        return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
        return null
    endfunction
    function GetHandleTrigger takes handle subject, string name returns trigger
        return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
        return null
    endfunction
    function GetHandleEffect takes handle subject, string name returns effect
        return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
        return null
    endfunction
    function GetHandleGroup takes handle subject, string name returns group
        return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
        return null
    endfunction
    function GetHandleLightning takes handle subject, string name returns lightning
        return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
        return null
    endfunction
    function GetHandleWidget takes handle subject, string name returns widget
        return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
        return null
    endfunction

    function FlushHandleLocals takes handle subject returns nothing
        call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
    endfunction


    Then, I just copied some example trigger into my map and changed it a bit. But now, there is a problem... Whenever unit is attacked, game crashes :SS

    Code (vJASS):
    function PoisonUnit_Update takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local unit victim = GetHandleUnit(t, "victim")
        local unit source = GetHandleUnit(t, "source")
        local integer steps = GetHandleInt(t, "steps")
        local real angle = GetHandleReal(t, "angle")

    call SetUnitPositionLoc( victim, PolarProjectionBJ(GetUnitLoc(victim), 20.00, angle) )  
     
        if ( steps <= 1 ) then
            call FlushHandleLocals(t)
            call DestroyTimer(t)
            endif
        call SetHandleInt(t, "steps", steps-1)
    endfunction

    function PoisonUnit takes unit source, unit victim, real angle returns nothing
    local timer t = CreateTimer()
    local real update = 0.03
    local unit source = GetAttacker()
    local unit victim = GetAttackedUnitBJ()
    local real angle = GetUnitFacing(GetAttacker())
    local integer steps = 10
        call SetHandleInt(t, "steps", steps)
        call SetHandleHandle(t, "victim", victim)
        call SetHandleHandle(t, "source", source)
        call SetHandleReal(t, "angle", angle)
        call TimerStart(t, update, true, function PoisonUnit_Update)
    endfunction

    //===========================================================================
    function InitTrig_Bash takes nothing returns nothing
        set gg_trg_Bash = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_Bash, EVENT_PLAYER_UNIT_ATTACKED )
        call TriggerAddAction( gg_trg_Bash, function PoisonUnit )
    endfunction


    Please help me correct this trigger.
     
  2. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,840
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    Did you initialize the cache?
     
  3. RolePlaynGamer

    RolePlaynGamer

    Joined:
    Apr 5, 2008
    Messages:
    473
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Functions used as actions can't take parameters as far as I know. Just remove all the "takes <something>" from your PoisonUnit function
     
  4. ZlatniLav

    ZlatniLav

    Joined:
    Dec 13, 2008
    Messages:
    196
    Resources:
    0
    Resources:
    0
    it works for me now... +rep ty :)