--if you want to ski/skate on the terrain leave as --skate_surface_name = "" --otherwise set this to the name of the entity(s) you want to use as collision objects to skate on local skate_surface_name = "skate" --how far down the ray checks for the skate surface while you are already skating --this needs to be higher value for steeper slopes local rayDownWhileOn = 85 --this is how far down the ray checks for the skate surface local rayDownWhileJumping = 300 local skateSpeed = 10 local was_skating_delay = 2 skate_surface_e = skate_surface_e or {} skate_surface_obj = skate_surface_obj or {} local new_was_skating = 0 local newskateSpeed = 0 local skateX,skateY,skateZ = 0,0,0 local skatingE = 0 local state = "" U = U or require "scriptbank\\utillib" local rad = math.rad local ePressed = false local can_skate = false local tpe = nil local tpobj = nil function skating_init(e) state = "wait" end function skating_main(e) local frameTime = GetElapsedTime() if state == "wait" then if skate_surface_name == "" then Prompt("Skate (E)") if g_KeyPressE == 1 then if not ePressed then LoopSound(e,0) if tpe == nil then tpe = GetGamePlayerControlThirdpersonCharactere() if tpe ~= nil and tpe > 0 then tpobj = g_Entity[tpe]['obj'] end end state = "skate" end ePressed = true else ePressed = false end else if tpe == nil then tpe = GetGamePlayerControlThirdpersonCharactere() if tpe ~= nil and tpe > 0 then tpobj = g_Entity[tpe]['obj'] end end local x1,y1,z1 = g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ local ax1,ay1,az1 = g_PlayerAngX,g_PlayerAngY,g_PlayerAngZ local x2,y2,z2 = 0,0,0 local frameTime = GetElapsedTime() local ox,oy,oz = 0,0,0 local tray = 0 new_was_skating = new_was_skating - frameTime if new_was_skating > 0 then newskateSpeed = newskateSpeed - frameTime * skateSpeed ForcePlayer(ay1, newskateSpeed) end ox,oy,oz = U.Rotate3D(0,-rayDownWhileJumping,0, 0,rad(ay1),0) x2,y2,z2 = x1+ox,y1+oy,z1+oz tray = IntersectAll(x1,y1,z1, x2,y2,z2, tpobj) if tray == nil then tray = 0 end if tray > 0 then skateX,skateY,skateZ = GetIntersectCollisionX(),GetIntersectCollisionY()+50,GetIntersectCollisionZ() end if tray > 0 then can_skate = false for a,b in pairs (skate_surface_obj) do if b == tray then skatingE = a can_skate = true Prompt("Skate (E)") break end end if can_skate == true then if g_KeyPressE == 1 or new_was_skating > 0 then if not ePressed or new_was_skating > 0 then SetFreezePosition(skateX,g_PlayerPosY,skateZ) TransportToFreezePositionOnly() newskateSpeed = skateSpeed LoopSound(e,0) state = "skate" end ePressed = true else ePressed = false end end end end elseif state == "skate" then if g_KeyPressE == 1 then if not ePressed then StopSound(e,0) state = "wait" end ePressed = true else ePressed = false end if skate_surface_name == "" then ForcePlayer(g_PlayerAngY, skateSpeed) SetRotation(tpe,0,g_PlayerAngY+10,0) else local x1,y1,z1 = g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ local ax1,ay1,az1 = g_PlayerAngX,g_PlayerAngY,g_PlayerAngZ local x2,y2,z2 = 0,0,0 local frameTime = GetElapsedTime() local ox,oy,oz = 0,0,0 local tray = 0 ox,oy,oz = U.Rotate3D(0,-rayDownWhileOn,skateSpeed, 0,rad(ay1),0) x2,y2,z2 = x1+ox,y1+oy,z1+oz tray = IntersectAll(x1,y1,z1, x2,y2,z2, tpobj) if tray == nil then tray = 0 end if tray > 0 then skateX,skateY,skateZ = GetIntersectCollisionX(),GetIntersectCollisionY()+50,GetIntersectCollisionZ() end can_skate = false if tray > 0 then for a,b in pairs (skate_surface_obj) do if b == tray then skatingE = a can_skate = true break end end end if not can_skate then StopSound(e,0) new_was_skating = was_skating_delay state = "wait" end ForcePlayer(ay1, skateSpeed) SetRotation(tpe,0,ay1+10,0) end end end