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

Fixing some code for the new Wc3 Version

Status
Not open for further replies.
Level 8
Joined
Jul 17, 2007
Messages
143
JASS:
function InitQuestSystem takes nothing returns nothing
     call FlushGameCache(InitGameCache("handlevars.w3v"))
     set udg_hash = InitGameCache("handlevars.w3v")
     call FlushGameCache(InitGameCache("questsys.w3v"))
     set udg_questsys = InitGameCache("questsys.w3v")
endfunction

function SetPlayerQuestFX takes integer id, player whichPlayer, effect fx returns nothing
    call StoreInteger(udg_questsys, I2S(id),"effect"+I2S(GetPlayerId(whichPlayer)), H2L(fx))
endfunction
function GetPlayerQuestFX takes integer id, player whichPlayer returns effect
    return GetStoredInteger(udg_questsys, I2S(id),"effect"+I2S(GetPlayerId(whichPlayer)))
    return null
endfunction
function GetQuestGiver takes integer id returns unit
    return GetStoredInteger(udg_questsys,I2S(id),"questgiver")
    return null
endfunction
function GetReqState takes unit whichUnit, integer id, integer req returns integer
    return GetHandleInt(whichUnit,"reqstate"+I2S(id)+I2S(req))
endfunction
function SetReqState takes unit whichUnit, integer id, integer req, integer newstate returns nothing
    call SetHandleInt(whichUnit,"reqstate"+I2S(id)+I2S(req),newstate)
endfunction
function GetQuestReqById takes integer id,integer req returns questitem
     return GetStoredInteger( udg_questsys, I2S(id), "questitem"+I2S(req))
     return null
endfunction
function GetQuestById takes integer id returns quest
     return GetStoredInteger( udg_questsys, I2S(id), "quest")
     return null
endfunction
function SetQuestById takes integer id, quest whichQuest returns nothing
    call StoreInteger( udg_questsys, I2S(id), "quest", H2L(whichQuest))
endfunction
function SetPlayerReqName takes integer id, integer req, player p, string storewhat returns nothing
    call StoreString( udg_questsys, I2S(id), "req"+I2S(req)+I2S(GetPlayerId(p)), storewhat)
endfunction
function GetPlayerReqName takes integer id, integer req, player p returns string
    local string reqname = GetStoredString( udg_questsys, I2S(id), "req"+I2S(req)+I2S(GetPlayerId(p)))
    if reqname == null then
        set reqname = GetStoredString(udg_questsys,I2S(id),"req"+I2S(req))
    endif
    return reqname
endfunction
function GetQuestState takes unit whichUnit, integer id returns integer
    return GetHandleInt( whichUnit, "queststate"+I2S(id))
endfunction
function CreateQuestEffectUnit takes unit whichUnit, player viewer returns effect
    local string path = ""
    if GetLocalPlayer() == viewer then
        set path = "Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdx"
    endif
    return AddSpecialEffectTarget(path, whichUnit, "overhead")
endfunction

function CreateQuestEffect takes player whichPlayer, integer id returns nothing
    call SetPlayerQuestFX(id,whichPlayer,CreateQuestEffectUnit(GetQuestGiver(id), whichPlayer))
endfunction
function ChangeQuestReqNamePlayer takes player p, string s, integer id, integer req returns nothing
    local string s2
    local questitem it = GetQuestReqById(id,req)
    local integer x = 0
    loop
        exitwhen x > 12
        set udg_ArrayVar[x] = GetPlayerReqName(id,req,Player(x))
        set x = x + 1
    endloop
    set udg_ArrayVar[GetPlayerId(p)] = s
    call SetPlayerReqName(id,req,p, s)
    set s = udg_ArrayVar[GetPlayerId(GetLocalPlayer())]
    call QuestItemSetDescription(it,s)
    set it = null
endfunction
function SetQuestReqComplete takes integer id, integer req, player p, boolean finished returns nothing
    local questitem it = GetQuestReqById(id,req)
    call StoreBoolean( udg_questsys, I2S(id), "reqcomplete"+I2S(req)+I2S(GetPlayerId(p)), finished)
    call ChangeQuestReqNamePlayer(p, GetStoredString(udg_questsys,I2S(id),"req"+I2S(req)), id, req)
    if GetLocalPlayer() == p then
        call QuestItemSetCompleted( it, finished )
    endif
    set it = null
endfunction
function IsQuestReqComplete takes unit whichUnit, integer id, integer req returns boolean
    return GetStoredBoolean( udg_questsys, I2S(id), "reqcomplete"+I2S(req)+I2S(GetPlayerId(GetOwningPlayer(whichUnit))))
endfunction
function CreateQuestAtId takes integer id, unit whichUnit returns nothing
     local quest q = CreateQuest()
     local integer x = 1
     local questitem it
     local integer max
     call QuestSetTitle( q, GetStoredString( udg_questsys, I2S(id), "name") )
     call QuestSetDescription( q, GetStoredString( udg_questsys, I2S(id), "description") )
     call QuestSetRequired( q, true)
     call QuestSetDiscovered( q, true)
     call QuestSetIconPath(q, GetStoredString( udg_questsys, I2S(id), "icon"))
     //initilize quest
     call QuestSetEnabled( q , false)
     
     if GetLocalPlayer() == GetOwningPlayer(whichUnit) then
         call QuestSetEnabled( q , true)
     endif
     // shown only to user
     loop
          exitwhen x > GetStoredInteger( udg_questsys, I2S(id), "reqcount" )
          set max = GetStoredInteger(udg_questsys, I2S(id),"max"+I2S(x))
          set it = QuestCreateItem(q)
          call StoreInteger( udg_questsys, I2S(id), "questitem"+I2S(x),H2L(it))
          if (max > 0) then
               call SetPlayerReqName(id, x, GetOwningPlayer(whichUnit), GetStoredString( udg_questsys, I2S(id), "req"+I2S(x))+" (0 / "+I2S(max)+")" )
               call ChangeQuestReqNamePlayer( GetOwningPlayer(whichUnit),GetStoredString( udg_questsys, I2S(id), "req"+I2S(x))+" (0 / "+I2S(max)+")",id,x)
          else
               call QuestItemSetDescription(it, GetStoredString( udg_questsys, I2S(id), "req"+I2S(x)) )
          endif
          set x = x + 1
     endloop
     //set the state for the unit and store the quest
     
     call StoreInteger( udg_questsys, I2S(id), "quest",H2L(q))
     call StoreInteger( udg_questsys, I2S(id), "used",1)

     set q = null
     set it = null
endfunction
function ShareQuestById takes unit whichUnit, integer id returns nothing
    //this function will re-use an already existing quest for that user
    local integer x = 1
    local integer max
    local questitem it
    local quest q = GetQuestById(id)
    local integer times = GetStoredInteger(udg_questsys, I2S(id), "used")
    if GetLocalPlayer() == GetOwningPlayer(whichUnit) then
         call QuestSetEnabled( q , true)
    endif
    loop
          exitwhen x > GetStoredInteger( udg_questsys, I2S(id), "reqcount" )
          set max = GetStoredInteger(udg_questsys, I2S(id),"max"+I2S(x))
          set it = GetQuestReqById( id,x)
          call SetQuestReqComplete(id,x,GetOwningPlayer(whichUnit),false)
          if (max > 0) then
               call SetPlayerReqName(id, x, GetOwningPlayer(whichUnit), GetStoredString( udg_questsys, I2S(id), "req"+I2S(x))+" (0 / "+I2S(max)+")" )
               call QuestItemSetDescription(it, GetStoredString( udg_questsys, I2S(id), "req"+I2S(x))+" (0 / "+I2S(max)+")" )
          else
               call ChangeQuestReqNamePlayer( GetOwningPlayer(whichUnit), GetStoredString( udg_questsys, I2S(id), "req"+I2S(x)),id,x)
          endif
          set x = x + 1
     endloop
    //someone else is viewing the quest, so increase the viewer size
    call StoreInteger( udg_questsys, I2S(id), "used",times+1)

    set q = null
    set it = null
endfunction
function RemoveQuest takes integer id, unit whichUnit returns nothing
    local quest q = GetQuestById(id)
    local integer times = GetStoredInteger(udg_questsys, I2S(id), "used")
    call StoreInteger( udg_questsys, I2S(id), "used",times-1)
    if GetLocalPlayer() == GetOwningPlayer(whichUnit) then
        call QuestSetEnabled( q , false)
    endif
    set times = times - 1
    if times == 0 then
        //no-one is viewing it... so just get rid of it
        call DestroyQuest(q)
        call FlushHandleLocals(q)
        call FlushStoredInteger( udg_questsys, I2S(id), "quest")
    endif
    set q = null
endfunction

// =========================================
function StartQuest takes unit whichUnit, integer id returns nothing
    local integer x = 1
    local string s = "notnull"
    local integer req
    local integer max
    if GetQuestById(id) == null then
        //the quest does not exist, so create it and put it in the table
        call CreateQuestAtId(id,whichUnit)
    else
        call ShareQuestById( whichUnit, id)
    endif
    call RemoveQuestEffect(id, GetOwningPlayer(whichUnit))
    //call SetHandleInt(whichUnit, "reqcomplete"+I2S(id)+I2S(req), 1)
    call SetHandleInt(whichUnit, "queststate"+I2S(id), 1)
    if GetLocalPlayer()==GetOwningPlayer(whichUnit) then
        call ClearTextMessages()
    endif
    call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "|c0000e500QUEST DISCOVERED|r")
    call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "   "+GetStoredString( udg_questsys, I2S(id), "name"))
    loop
        exitwhen x > GetStoredInteger( udg_questsys, I2S(id), "reqcount" )
        set s = GetStoredString( udg_questsys, I2S(id), "req"+I2S(x))
        call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "     - "+s)
        set x = x + 1
    endloop
endfunction

function CompleteReq takes unit whichUnit, integer id, integer req returns nothing
    local string s
    local integer x = 1
    
    local integer max
    local integer current
    call SetHandleInt(whichUnit, "queststate"+I2S(id), GetQuestState(whichUnit,id)+1)
    //set s = = GetStoredInteger(udg_questsys, I2S(id),"max")
    call SetQuestReqComplete(id,req,GetOwningPlayer(whichUnit),true)
    if GetLocalPlayer()==GetOwningPlayer(whichUnit) then
        call ClearTextMessages()
    endif
    call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "|c0000e500QUEST UPDATE|r")
    call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "   "+GetStoredString( udg_questsys, I2S(id), "name"))
    loop
        exitwhen x > GetStoredInteger( udg_questsys, I2S(id), "reqcount" )
        set s = GetStoredString(udg_questsys,I2S(id),"req"+I2S(x))
        set max = GetStoredInteger(udg_questsys, I2S(id),"max"+I2S(x))
        set current = GetReqState(whichUnit,id,x)
        
        if GetStoredBoolean( udg_questsys, I2S(id), "reqcomplete"+I2S(x)+I2S(GetPlayerId(GetOwningPlayer(whichUnit)))) then
            call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "     - |c007f7f7f"+s+" ( Completed )|r")
        else
            if max > 0 then
                call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "     - "+s+" ("+I2S(current)+" / "+I2S(max)+")")
            else
                call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "     - "+s)
            endif
        endif
        set x = x + 1
    endloop
    
endfunction
function FinishQuest takes unit whichUnit, integer id returns nothing
    call RemoveQuestEffect(id, GetOwningPlayer(whichUnit))
    call RemoveQuest(id,whichUnit)
    call SetHandleInt( whichUnit, "queststate"+I2S(id), -1)
    if GetLocalPlayer()==GetOwningPlayer(whichUnit) then
        call ClearTextMessages()
    endif
    call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "|c0000e500QUEST COMPLETED|r")
    call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "   "+GetStoredString( udg_questsys, I2S(id), "name"))
    // you can give some expirience based on the quest level here
    // call GiveLevelExp(whichUnit, GetStoredInteger( udg_questsys, I2S(id), "level"))
endfunction
function FailQuest takes unit whichUnit, integer id returns nothing
    call RemoveQuest(id,whichUnit)
    call SetHandleInt( whichUnit, "queststate"+I2S(id), 0)
    if GetLocalPlayer()==GetOwningPlayer(whichUnit) then
        call ClearTextMessages()
    endif
    call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "|c0000e500QUEST FAILED|r")
    call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "   "+GetStoredString( udg_questsys, I2S(id), "name"))
endfunction
function AdvanceReq takes unit whichUnit, integer id, integer req returns nothing
    local string s
    local integer x = 1
    local integer max = GetStoredInteger(udg_questsys, I2S(id), "max"+I2S(req))
    local integer current = GetReqState(whichUnit,id,req)
    local string newdisplay = GetStoredString(udg_questsys,I2S(id),"req"+I2S(req))+" ("+I2S(current+1)+" / "+I2S(max)+")"
    
    call SetReqState(whichUnit, id, req, current+1)

    if (current+1)==max then
        call CompleteReq(whichUnit,id,req)
        return    
    endif

    call ChangeQuestReqNamePlayer(GetOwningPlayer(whichUnit),newdisplay,id,req )

    if GetLocalPlayer()==GetOwningPlayer(whichUnit) then
        call ClearTextMessages()
    endif
    call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "|c0000e500QUEST UPDATE|r")
    call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "   "+GetStoredString( udg_questsys, I2S(id), "name"))
    loop
        exitwhen x > GetStoredInteger( udg_questsys, I2S(id), "reqcount" )
        set s = GetStoredString(udg_questsys,I2S(id),"req"+I2S(x))
        set max = GetStoredInteger(udg_questsys, I2S(id),"max"+I2S(x))
        set current = GetReqState(whichUnit,id,x)
        if GetStoredBoolean( udg_questsys, I2S(id), "reqcomplete"+I2S(x)+I2S(GetPlayerId(GetOwningPlayer(whichUnit)))) then
            call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "     - |c007f7f7f"+s+" ( Completed )|r")
        else
            if max > 0 then
                set s = GetStoredString(udg_questsys,I2S(id),"req"+I2S(x))+" ("+I2S(current)+" / "+I2S(max)+")"
            endif
            call DisplayTimedTextToPlayer( GetOwningPlayer(whichUnit), 0, 0, 10, "     - "+s)
        endif
        set x = x + 1
    endloop
endfunction
function PlayerOnQuest takes unit whichUnit, integer id returns boolean
    return GetQuestState(whichUnit,id)>0
endfunction

Can someone please fix this script to work with the new version of Wc3? Then just post the new script here. It would be greatly appreciated!!
 
Level 6
Joined
Jan 17, 2010
Messages
149
The problem is probably in the piece of code you didn't provide.

Functions such as "SetHandleInt()" (you didnt provide us the code for those) are probably using the old H2I system. You'll need to replace those with a hashtable based storage functions.

Remove all gamecache instances in your map and replace them with hashtables and replace the code inside the "SetHandleInt()" and similar functions with hashtable functions

for example:
JASS:
function SetHandleInt takes handle key_handle, string string_handle, integer value returns nothing
call SaveIntegerBJ(value, GetHandleId(key_handle), StringHash(string_handle), udg_HASHTABLE )
endfunction 

function GetHandleInt takes handle key_handle, string string_handle returns integer
return LoadIntegerBJ(GetHandleId(key_handle), StringHash(string_handle), udg_HASHTABLE )
endfunction

functions like "SetHandleHandle()" are to be replaced with a more specific variant like "SetHandleUnit()" or "SetHandleLocation()" look into the GUI version of hashtable functions for more information.

Also, remember to initialize your hashtable at map initialization or your map will crash and burn. Example:
JASS:
function Trig_Create_Game_Cache_Actions takes nothing returns nothing
    call InitHashtableBJ(  )
    set udg_HASHTABLE = GetLastCreatedHashtableBJ()
endfunction

function InitTrig_Create_Game_Cache takes nothing returns nothing
    set gg_trg_Create_Game_Cache = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Create_Game_Cache, 0.00 )
    call TriggerAddAction( gg_trg_Create_Game_Cache, function Trig_Create_Game_Cache_Actions )
endfunction

Lastly, replace the "FlushHandleLocales()" with a sub-table clean function (also found in the GUI)

Oh yeah, avoid the BJ functions if you want slightly faster performance.

I also noticed you use some kind of return bug based function ("H2L()") (I think it means H2I()?)
Replace all instances of H2I() with "GetHandleId()" and remove all return bug functions in your map


BAD
JASS:
Function H2L takes handle h returns location 
        return h
        return null
endfunction



For the future, post the functions the world editor complains about rather than the whole script.
 
Last edited:
Status
Not open for further replies.
Top