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") -- get the player's id local localCharacterID = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()) -- terminate the player's interaction (could be this treasure or the pet) 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 self:RequestPickTypeUpdate{} GAMEOBJ:GetTimer():CancelTimer("UpdateIcons", self); 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 localCharacterID = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()) local pet = localCharacterID: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) --print("NetworkVarUpdate: " .. tostring(#msg.tableOfVars)) local treasure_dug = self:GetNetworkVar("treasure_dug") if treasure_dug == true then --print("treasure_dug is true!!!") self:PlayFXEffect{effectType = "dug_up"} self:SetTransparency{fAlphaValue = 0.0} 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) local user = msg.user -- 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 user:DisplayTooltip{ bShow = true, strText = Localize("PR_DIG_TUTORIAL_04"), iTime = 3000 } end