-- Script to handle a Cancun Bolwing Pin -- -- This object will -- o Update every 1/4 second -- o Sends a 'destroy' message when it is first hit -- o Become 'collected' when the object tips over by more than 45 degrees -- o If it receives a DEACTIVATE message then pins that have fallen over are made to vanish, and -- pins that haven't fallen over will be reset so that they stand upright again function InitCancunBowlingPin() -- Load up a copy of the model to protect the textures from being deleted when the -- scripted object shuts down and deletes it's model. This will get loaded up once -- only when the first pin is spawned, and removed when the mission exits Object.LoadModel("Levels\\Cancun\\Can_Grl\\Models\\BowlingPin.rom") CancunBowlingPinModelLoaded = false end function CreateCancunBowlingPin(myID) if CancunBowlingPinModelLoaded == false then CancunBowlingPinModel = Object.LoadModel("Levels\\Cancun\\Can_Grl\\Models\\BowlingPin.rom") CancunBowlingPinModelLoaded = true end Object.CreatePhysicalBody(myID,"Levels\\Cancun\\Can_Grl\\Models\\BowlingPin.hsc"); Object.SetMass(myID,0.5) Object.SetCollisionSound(myID,"bowling_pin_hit") Object.SetNoMovementDeactivationTime(myID,2) return coroutine.create(UpdateCancunBowlingPin) end function UpdateCancunBowlingPin(myID) local dt=0 local reason local ux,uy,uz local hasFallen=false Object.SetModel(myID,CancunBowlingPinModel) Object.DeactivatePhysics(myID) Object.SetUpdateRate(myID,0.1) Object.UpdateOnReceiveMessage(myID,true) Object.UpdateOnCollision(myID,true) while true do dt,reason = coroutine.yield() -- DEACTIVATE message update? if reason == 5 then if hasFallen == false then -- Reset the pin Object.ResetPhysicalBodyPosition(myID) Object.SetUpdateRate(myID,0.1) Object.DeactivatePhysics(myID) Object.UpdateOnCollision(myID,true) else Object.DestroyPhysicalBody(myID) end end -- COLLISION update? if reason == 3 then -- Send destroy message Object.SetDestroyed(myID,0) Object.UpdateOnCollision(myID,false) end -- TICK update? if reason == 0 then -- Is the pin at more than 45degrees? ux,uy,uz = Object.GetUpVector(myID) if uy < 0.5 then -- Yup, it's fallen over -- Send collect message Object.SetCollected(myID,0) hasFallen=true -- Stop the pin ticking over Object.SetUpdateRate(myID,0) end end end end