require('o_mis') -- used for getObjectByName function onStartup(self) --self:SetVar("NodeClaimed", false) --pet treasure chest is spawned in on quickbuild of X, this kills if after 45 seconds if unused GAMEOBJ:GetTimer():AddTimerWithCancel( 45, "KillChest", self ) end function onCollisionPhantom(self, msg) --gets the pet that collided with the pet treause local target = msg.senderID --print(target:GetID()) -- 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) --print("COLLISION" .. target:GetName().name) --gets the player that built the X, and was stored on the pet treasure box local player = self:GetVar("builder") --print(player) --sets the pet owner based on the pet that collided with the pet treasure node local petOwner = target:GetParentObj().objIDParent:GetID() --print(petOwner) --checks to see if the pet that collided with the treasure if the pet of the player who built the X if (player == petOwner) then -- If chest hasn't already been claimed by another pet -- 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 in the process of using an ability already if ( target:GetPetAbilityObject().bHasAbilityObj == false ) then storeObjectByName(self, "Pet", target) --print("NODE NOW CLAIMED") -- 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 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() )and (target:GetID() == self:GetVar("builder") ) )then --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 local player = GAMEOBJ:GetObjectByID(self:GetVar("builder")) --print("petOwner is "..petOwner:GetID().." and player is "..player:GetID()) --:GetName().name -- check to make sure the pet owner is still the player who built the X, just another check if (petOwner:GetID() == player:GetID()) then --print("in petowner = player") local PlayerFlagNum = 0 --set the flag number to check/set on the player based on which flag in GF it is. --player flag number set in the database if (self:GetVar("groupID") == "Flag1") then PlayerFlagNum = 61 elseif (self:GetVar("groupID") == "Flag2") then PlayerFlagNum = 62 elseif (self:GetVar("groupID") == "Flag3") then PlayerFlagNum = 63 end --check to see if they player as dug the flag up before if not player:GetFlag{iFlagID = PlayerFlagNum}.bFlag then -- Ability is done being used, remove using-ability state from pet msg.ObjIDSender:RemovePetState{iStateType = 9} --get the flag based on the group, to change the collision group and visiblity on those scripts --assume only one object in group local flag = self:GetObjectsInGroup{ group = self:GetVar("groupID"), ignoreSpawners = true }.objects[1] --local player = petOwner --notifies script on the flag L_GF_DUG_FLAG_CLIENT flag:NotifyClientObject{ name = "changePhysics" , paramObj = GAMEOBJ:GetObjectByID(msg.param1) , rerouteID = player }--NotifyObject{ name = "flagDugUp", paramObj = petOwner } --set the player flag for this collectible flag so next time the player digs it, he'll get generic pet loot instead petOwner:SetFlag{iFlagID = PlayerFlagNum, bFlag = true} GAMEOBJ:DeleteObject(self) else --remove the dig state from the pet msg.ObjIDSender:RemovePetState{iStateType = 9} self:Die{ killType = "VIOLENT" , killerID = petOwner } --GAMEOBJ:DeleteObject(self) end --cancel the timer to kill the treasure chest, and kill it early GAMEOBJ:GetTimer():CancelTimer("KillChest", self); --smash the built X if it is still built GAMEOBJ:GetObjectByID(self:GetVar("X")):Die{ killType = "VIOLENT" } end end end function onTimerDone(self, msg) if ( msg.name == "KillChest" ) then local target = getObjectByName(self, "Pet") -- Pet 'kills' the treasure node, causing it to spawn a treasure chest target:RemovePetState{iStateType = 9} target:NotifyPet{ ObjIDSource = target, ObjToNotifyPetAbout = self, iPetNotificationType = 7 } GAMEOBJ:DeleteObject(self) 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