require('o_mis') -- For faction checks function onStartup(self) self:SetVar("NodeClaimed", false) end function onCollisionPhantom(self, msg) local target = msg.senderID -- Make sure the target is a tame pet (wild pets don't care about treasure) local isPet = target:GetIsPet() if (self:IsDead().bDead ~= true and isPet.bIsPet == true and isPet.bIsWild == false) then --print("COLLISION: " .. target:GetName().name) -- Make sure the chest hasn't already been claimed by another pet local claimed = self:GetVar("NodeClaimed") --print("claimed=" .. tostring(claimed)) if (claimed == false or claimed == target) then -- If pet is not using an ability already if ( target:GetPetAbilityObject{}.bHasAbilityObj == false ) then --print("NODE CLAIMED by " .. target:GetName().name) -- Pet marks chest as claimed so another pet cannot grab it self:SetVar("NodeClaimed", target) -- Let pet know they're at a dig location target:NotifyPet{ ObjIDSource = target , ObjToNotifyPetAbout = self , iPetNotificationType = 6 } -- Store the ID of the pet that has found the treasure storeObjectByName(self, "activator", target) end end end end function onOffCollisionPhantom(self, msg) local target = msg.senderID -- Make sure the target is a tame pet (wild pets don't care about treasure) local isPet = target:GetIsPet() if (isPet.bIsPet == true and isPet.bIsWild == false) then --print("OFF COLLISION" .. target:GetName().name) local activator = getObjectByName(self, "activator") if ( activator and ( target:GetID() == getObjectByName(self, "activator"):GetID() ) ) then --print("NODE UNCLAIMED by " .. target:GetName().name) self:SetVar("NodeClaimed", false) -- Notify pet they've left the pet switch target:NotifyPet{ ObjIDSource = target, ObjToNotifyPetAbout = self, iPetNotificationType = 7 } end end end function onNotifyObject(self, msg) -- If treasure node receives notification a pet is digging it up if ( msg.name == "petdughere" ) then self:SetNetworkVar("treasure_dug", true) local petOwner = msg.ObjIDSender:GetParentObj().objIDParent --print(petOwner) self:Die{ killType = "VIOLENT" , killerID = petOwner } -- Ability is done being used, remove using-ability state from pet msg.ObjIDSender:RemovePetState{iStateType = 9} end end --function onTimerDone(self, msg) -- -- if ( msg.name == "KillChest" ) then -- -- local activator = getObjectByName(self, "activator") -- local petOwner = activator:GetParentObj().objIDParent -- -- -- Pet 'kills' the treasure node, causing it to spawn a treasure chest -- self:Die{ killType = "VIOLENT" , killerID = petOwner } -- -- end -- --end function onDie(self,msg) local myParent = getParent(self) if ( self:GetVar("I_Have_A_Parent") ) then myParent:SetVar( self:GetVar("SpawnedVar") , "NotSpawned") end -- Let the scene's treasure node spawner know this treasure has died, so it can spawn another one later. getParent(self):NotifyObject{name = "died"} end