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