-- Rio Pedro script -- o Create a Pedro character -- o Send a COLLECT message when the player hits Pedro -- o Attach pedro to the back of the bike -- o Go back to the original position when it receives a DEACTIVATE message function InitRioPedro () print("initing RioPedro") Pedro_Clip3 = Anim.LoadAnimation("Animations/Pedestrians/man_idle.bac") Pedro_Clip4 = Anim.LoadAnimation("Animations/Pedestrians/man_idle2.bac") Pedro_RagDoll = Anim.LoadAnimation("Animations/Ragdoll/maleped_ragdoll.bac") end function CreateRioPedro (myId) Object.CreateRagdoll(myId) Object.CreateRopeForRagdoll(myId) Object.CreateRagdollAnimationManager(myId,3) return coroutine.create(UpdateRioPedro) end function UpdateRioPedro(myID) local dt=0 local reason=0 local time=0 local collected = false local RioPedroCharacter = Object.LoadCharacter("Rio/Rio6") Object.SetCharacterSwitchOffDistance(RioPedroCharacter,50) Object.SetCharacter(myID,RioPedroCharacter) Object.PlayAnimation(myID,Pedro_Clip4,false,1.0) Object.CreateSphereTouchfield(myID,0,0,0,1) Object.UpdateOnSphereTouchfield(myID,true) Object.UpdateOnPlayerRespot(myID,0,true) -- hardcoding to driver 0 -- Update now... Object.SetUpdateRate(myID,0.001) dt,reason = coroutine.yield() Object.SetUpdateRate(myID,0) print("Loaded") Object.UpdateOnAnimFinished(myID,true) while true do dt,reason = coroutine.yield() if reason == 1 then -- Blimey, that bike is a bit close eh? -- Stop what I'm doing Sound.PlayLua2DSoundOneShot("Rio_Pedro") Object.UpdateOnAnimFinished(myID,false) Object.StopMovingToTarget(myID) Object.UpdateOnSphereTouchfield(myID,false) Object.StopAnimation(myID) -- Ragdoll Object.AttachRagdollWithRope(myID,Pedro_RagDoll) Object.SetCollected(myID,Object.GetLastTouchfieldDriver(myID)) Camera.SetFollowCameraExtraOffset(0, 0, 0, -6) Pedestrian.AllowPedestrialRagdoll(false) -- Wait for a DEACTIVATE or SMASHERDESTROYEDBYRAGDOLL message Object.UpdateOnReceiveMessage(myID,true) reason = 0 while ( reason ~= 5 and reason ~= 14 ) do dt,reason = coroutine.yield() if reason == 12 then -- hit by a ragdoll - if not crashing then tell the spawner and it can decide what to do driver = GetViewportDriver(0) if IsDriverCrashing(driver) == false then Object.SetDestroyed(myID,Object.GetLastTouchfieldDriver(myID)) Sound.PlayLua2DSoundOneShot("Rio_Pedro") end end end -- Respawn Object.DetachRagdoll(myID) Camera.SetFollowCameraExtraOffset(0, 0, 0, 0) Object.UpdateOnReceiveMessage(myID,false) Object.UpdateOnAnimFinished(myID,true) Object.UpdateOnSphereTouchfield(myID,true) Object.PlayAnimation(myID,Pedro_Clip4,false,1.0) Pedestrian.AllowPedestrialRagdoll(true) elseif reason == 2 then -- Lets hang around a bit more... if math.random(3)~=1 then Object.PlayAnimation(myID,Pedro_Clip3,false,0.2) else Object.PlayAnimation(myID,Pedro_Clip4,false,1.0) end end end end