local pickPriority = 0.8 local pickType = 0 function onStartup(self, msg) --print("Treasure startup") pickType = 0 self:SetVar("isCharacterNearby", false) end function onDie(self, msg) --print("Treasure died") -- terminate the player's interaction (could be this treasure or the pet) local localCharacterID = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()) localCharacterID:TerminateInteraction{ ETerminateType="user", ObjIDTerminator=localCharacterID } pickType = -1 self:RequestPickTypeUpdate{} end function onCollisionPhantom(self, msg) --print("CollisionPhantom: sender=" .. msg.senderID:GetName().name) --print("CollisionPhantom: self=" .. self:GetName().name) if (msg.senderID:IsCharacter{}.isChar and msg.senderID:GetID() == GAMEOBJ:GetLocalCharID()) then self:SetVar("isCharacterNearby", true) -- start a timer to check if the player is in proximity with a pet GAMEOBJ:GetTimer():AddTimerWithCancel(0.5, "UpdateIcons", self ) end end function onOffCollisionPhantom(self, msg) --print("OffCollisionPhantom: sender=" .. msg.senderID:GetName().name) if (msg.senderID:IsCharacter{}.isChar and msg.senderID:GetID() == GAMEOBJ:GetLocalCharID()) then self:SetVar("isCharacterNearby", false) pickType = -1 GAMEOBJ:GetTimer():CancelTimer("UpdateIcons", self); self:RequestPickTypeUpdate{} end end function onTimerDone(self, msg) --print(self:GetName().name .. ".TimerDone: " .. msg.name) if ( msg.name == "UpdateIcons" ) then if ( self:GetVar("isCharacterNearby") == true) then local oldPickType = pickType pickType = -1 local pet = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()):GetPetID().objID if (self:IsDead{}.bDead == true) then -- chest is dead, hide the icon pickType = -1 elseif (pet:Exists() == false) then -- no pet, show the icon pickType = 14 elseif (pet:IsPetUsingAbility().bIsUsingAbility == false) then -- pet not signaling, show the icon pickType = 14 end --print("PickType=" .. tostring(pickType) .. ", oldPickType=" ..tostring(oldPickType)) if (pickType ~= oldPickType) then self:RequestPickTypeUpdate{} end -- start the timer again --GAMEOBJ:GetTimer():AddTimerWithCancel(0.5, "UpdateIcons", self ) end end end function onScriptNetworkVarUpdate(self,msg) local i = 1 while i <= #msg.tableOfVars do local tableVar = msg.tableOfVars[i][1] if ( tableVar == "treasure_dug" ) then if ( msg.tableOfVars[i][2] == true ) then self:PlayFXEffect{effectType = "dug_up"} self:SetTransparency{fAlphaValue = 0.2} return end end i = i + 1 end end function onGetPriorityPickListType(self, msg) if ( pickPriority >= msg.fCurrentPickTypePriority ) then if (pickType ~= 0) then --print("Set pickType=" .. tostring(pickType)) msg.ePickType = pickType end msg.fCurrentPickTypePriority = pickPriority end return msg end function onClientUse(self, msg) -- the only way for a player to use this item is by hitting their interact button -- the only time the interact button is available here is when the pick type is 14 -- the only time the pick type is 14 is when the player doesn't have a pet or the digging ability -- therefore, show the tooltip indicating they need a pet msg.user:DisplayTooltip{ bShow = true, strText = Localize("PR_DIG_TUTORIAL_04"), iTime = 3000 } end