Kilgam
New Member
- Reaction score
- 2
How do i fix this so it works for 1.24 again?
I use Faux handle vars
And heres the code that doesnt work...
I use Faux handle vars
JASS:
//==========================================================================================
library HandleVars initializer init
globals
private hashtable ht
endglobals
// too bad the Handle vars' old functionality forces me to make these things
// inline-unfriendly
function SetHandleHandle takes agent subject, string label, agent value returns nothing
if(value==null) then
call RemoveSavedHandle( ht, GetHandleId(subject), StringHash(label))
else
call SaveAgentHandle( ht, GetHandleId(subject), StringHash(label), value)
endif
endfunction
function SetHandleInt takes agent subject, string label, integer value returns nothing
if value==0 then
call RemoveSavedInteger(ht, GetHandleId(subject), StringHash(label))
else
call SaveInteger(ht, GetHandleId(subject), StringHash(label), value)
endif
endfunction
function SetHandleBoolean takes agent subject, string label, boolean value returns nothing
if (value == false) then
call RemoveSavedBoolean(ht, GetHandleId(subject), StringHash(label))
else
call SaveBoolean(ht, GetHandleId(subject), StringHash(label), value)
endif
endfunction
function SetHandleReal takes agent subject, string label, real value returns nothing
if (value == 0.0) then
call RemoveSavedReal(ht, GetHandleId(subject), StringHash(label))
else
call SaveReal(ht, GetHandleId(subject), StringHash(label), value)
endif
endfunction
function SetHandleString takes agent subject, string label, string value returns nothing
if ((value=="") or (value==null)) then
call RemoveSavedString(ht, GetHandleId(subject), StringHash(label))
else
call SaveStr(ht, GetHandleId(subject), StringHash(label), value) //yay for blizz' consistent naming scheme...
endif
endfunction
function GetHandleHandle takes agent subject, string label returns agent
debug call BJDebugMsg("[debug] What the heck? Why would you call HandleHandle I guess this was caused by a search and replace mistake")
return null
endfunction
// these are inline friendly, ok, maybe they aren't because jasshelper does not recognize
// GetHandleId as non-state changing. But they will be once I fix jasshelper...
function GetHandleInt takes agent subject, string label returns integer
return LoadInteger(ht, GetHandleId(subject), StringHash(label))
endfunction
function GetHandleBoolean takes agent subject, string label returns boolean
return LoadBoolean(ht, GetHandleId(subject), StringHash(label))
endfunction
function GetHandleString takes agent subject, string label returns string
return LoadStr(ht, GetHandleId(subject), StringHash(label))
endfunction
function GetHandleReal takes agent subject, string label returns real
return LoadReal(ht, GetHandleId(subject), StringHash(label))
endfunction
// got bored so I now use a textmacro...
//! textmacro FAUX_HANDLE_VARS_GetHandleHandle takes NAME, TYPE
function SetHandle$NAME$ takes agent subject, string label, $TYPE$ value returns nothing
if(value==null) then
call RemoveSavedHandle( ht, GetHandleId(subject), StringHash(label))
else
call Save$NAME$Handle( ht, GetHandleId(subject), StringHash(label), value)
endif
endfunction
function GetHandle$NAME$ takes agent subject, string label returns $TYPE$
return Load$NAME$Handle( ht, GetHandleId(subject), StringHash(label))
endfunction
//! endtextmacro
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Player","player")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Widget","widget")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Destructable","destructable")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Item","item")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Unit","unit")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Ability","ability")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Timer","timer")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Trigger","trigger")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TriggerCondition","triggercondition")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TriggerAction","triggeraction")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TriggerEvent","event")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Force","force")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Group","group")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Location","location")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Rect","rect")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("BooleanExpr","boolexpr")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Sound","sound")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Effect","effect")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("UnitPool","unitpool")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("ItemPool","itempool")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Quest","quest")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("QuestItem","questitem")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("DefeatCondition","defeatcondition")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TimerDialog","timerdialog")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Leaderboard","leaderboard")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Multiboard","multiboard")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("MultiboardItem","multiboarditem")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Trackable","trackable")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Dialog","dialog")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Button","button")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("TextTag","texttag")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Lightning","lightning")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Image","image")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Ubersplat","ubersplat")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Region","region")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("FogState","fogstate")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("FogModifier","fogmodifier")
//! runtextmacro FAUX_HANDLE_VARS_GetHandleHandle("Hashtable","hashtable")
function FlushHandleVars takes agent subject returns nothing
call FlushChildHashtable(ht, GetHandleId(subject))
endfunction
function FlushHandleLocals takes agent subject returns nothing
call FlushHandleVars(subject)
endfunction
private function init takes nothing returns nothing
set ht=InitHashtable()
endfunction
endlibrary
And heres the code that doesnt work...
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)), GetHandleId(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", GetHandleId(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 RemoveQuestEffect takes integer id, player whichPlayer returns nothing
local effect fx = GetPlayerQuestFX(id,whichPlayer)
if (fx == null) then
call BJDebugMsg( "QuestSys: Effect destruction error")
endif
call DestroyEffect( fx )
set fx = null
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),GetHandleId(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",GetHandleId(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