Add files via upload
commit
773394d47d
@ -0,0 +1,29 @@
|
||||
AddCSLuaFile()
|
||||
if SERVER then
|
||||
include("sv_init.lua")
|
||||
end
|
||||
DEFINE_BASECLASS( "base_anim" )
|
||||
ENT.Base = "base_anim"
|
||||
ENT.Type = "anim"
|
||||
|
||||
ENT.Spawnable = true
|
||||
ENT.AdminSpawnable = true
|
||||
ENT.PrintName = "Ferris Wheel"
|
||||
ENT.Category = "catSIXe"
|
||||
ENT.Author = ""
|
||||
|
||||
if CLIENT then
|
||||
function ENT:Initialize()
|
||||
|
||||
end
|
||||
function ENT:OnRemove()
|
||||
if self.CSoundLoop then self.CSoundLoop:Stop() end
|
||||
end
|
||||
function ENT:Think()
|
||||
if not self.CSoundLoop or self.CSoundLoop:IsPlaying() == false then
|
||||
self.CSoundLoop = CreateSound(self, "ambience/mechwhine.wav")
|
||||
self.CSoundLoop:Play()
|
||||
end
|
||||
self.CSoundLoop:ChangeVolume(0.2)
|
||||
end
|
||||
end
|
@ -0,0 +1,190 @@
|
||||
function ENT:CreatePhysicsProp(mdl)
|
||||
local ent = ents.Create("prop_physics")
|
||||
ent:SetModel(mdl)
|
||||
ent:Spawn()
|
||||
--ent.PhysgunDisabled = true
|
||||
self:DeleteOnRemove(ent)
|
||||
return ent
|
||||
end
|
||||
function ENT:CreateParentedProp(mdl)
|
||||
local ent = self:CreatePhysicsProp(mdl)
|
||||
ent:SetParent(self)
|
||||
ent:SetAngles(self:GetAngles())
|
||||
ent:SetLocalPos(Vector(0))
|
||||
return ent
|
||||
end
|
||||
function ENT:Initialize()
|
||||
self:SetModel("models/props_fairground/ferriswheel/base.mdl")
|
||||
self:PhysicsInit(SOLID_VPHYSICS)
|
||||
self:SetSolid(SOLID_VPHYSICS)
|
||||
self:SetMoveType(MOVETYPE_VPHYSICS)
|
||||
local phys = self:GetPhysicsObject()
|
||||
if IsValid(phys) then phys:SetMass(50000) end
|
||||
end
|
||||
function ENT:Populate()
|
||||
local selfAng = self:GetAngles()
|
||||
self:CreateParentedProp("models/props_fairground/ferriswheel/bg_wall.mdl")
|
||||
self:CreateParentedProp("models/props_fairground/ferriswheel/label.mdl")
|
||||
|
||||
self.Holder = self:CreatePhysicsProp("models/props_fairground/ferriswheel/holder.mdl")
|
||||
self.Holder:SetPos(self:GetPos()-Vector(0,0,25))
|
||||
self.Holder:GetPhysicsObject():SetMass(25000)
|
||||
--self.Holder:SetMoveType(MOVETYPE_VPHYSICS)
|
||||
self.Holder:GetPhysicsObject():EnableMotion(false)
|
||||
|
||||
self.Gondels = {} -- should be named Carrige
|
||||
self.Wheel = self:CreatePhysicsProp("models/props_fairground/ferriswheel/wheel.mdl")
|
||||
self.Wheel:SetPos(self:GetPos()-Vector(0,0,25))
|
||||
self.Wheel:GetPhysicsObject():SetMass(25000)
|
||||
local wheelAxis = constraint.AdvBallsocket(
|
||||
self.Holder, self.Wheel,
|
||||
0, 0,
|
||||
Vector(0, 62,665.247742),
|
||||
Vector(0, 62,665.247742),
|
||||
0, 0,
|
||||
0, -180,90,
|
||||
0, 180, 90,
|
||||
0, 2, 0,
|
||||
0, 0
|
||||
)
|
||||
|
||||
for i,k in pairs(self.Wheel:GetAttachments()) do
|
||||
local newGondel = #self.Gondels + 1
|
||||
local gondelAttachment = self.Wheel:GetAttachment( i )
|
||||
self.Gondels[ newGondel ] = self:CreatePhysicsProp("models/props_fairground/ferriswheel/gondel.mdl")
|
||||
self.Gondels[ newGondel ]:GetPhysicsObject():EnableMotion(false)
|
||||
self.Gondels[ newGondel ]:SetColor(HSVToColor(i*30, 1, 1))
|
||||
self.Gondels[ newGondel ]:SetPos(gondelAttachment.Pos)
|
||||
-- ( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, forcelimit, torquelimit, xmin, ymin, zmin, xmax, ymax, zmax, xfric, yfric, zfric, onlyrotation, nocollide )
|
||||
local gondelAxis = constraint.AdvBallsocket(
|
||||
self.Wheel, self.Gondels[ newGondel ],
|
||||
0, 0,
|
||||
self.Wheel:WorldToLocal(gondelAttachment.Pos), Vector(0,0,0),
|
||||
0, 0,
|
||||
0, -180, 90,
|
||||
0, 180, 90,
|
||||
0,0,0,
|
||||
0, 1
|
||||
)
|
||||
MsgN("gondelAxis="..tostring(gondelAxis))
|
||||
self.Gondels[ newGondel ]:GetPhysicsObject():EnableMotion(true)
|
||||
self.Gondels[ newGondel ]:GetPhysicsObject():SetMass(500)
|
||||
end
|
||||
self.Holder:SetAngles(selfAng)
|
||||
self.Wheel:SetAngles(selfAng)
|
||||
for i,k in pairs(self.Gondels) do k:SetAngles(selfAng) end
|
||||
constraint.Weld(self.Holder, self, 0, 0, 0, 1)
|
||||
end
|
||||
local targetSpeed = 8
|
||||
function ENT:Think()
|
||||
if not self.FirstThink then
|
||||
self.FirstThink = true
|
||||
self:Populate()
|
||||
end
|
||||
local phys = self.Wheel:GetPhysicsObject()
|
||||
local wheelSpeed = phys:GetAngleVelocity():Length()
|
||||
--MsgN(wheelSpeed)
|
||||
if wheelSpeed > targetSpeed*1.2 then
|
||||
phys:EnableMotion(false)
|
||||
for i,k in pairs(self.Gondels) do k:SetAngles(self:GetAngles()) end
|
||||
end
|
||||
if wheelSpeed < targetSpeed then
|
||||
phys:EnableMotion(true)
|
||||
end
|
||||
if self.ReasonToMove then
|
||||
phys:AddAngleVelocity(Vector(0,wheelSpeed - targetSpeed,0)*10)
|
||||
end
|
||||
local playerCount = 0
|
||||
for i, k in pairs(self.Gondels) do
|
||||
for j,l in pairs(k:GetChildren()) do
|
||||
if l:IsVehicle() && IsValid(l:GetDriver()) then
|
||||
playerCount = playerCount + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
self.ReasonToMove = playerCount > 0
|
||||
end
|
||||
function ENT:SpawnFunction(ply, trace)
|
||||
local ent = ents.Create("scripted_ferriswheel")
|
||||
local SpawnAng = ply:EyeAngles()
|
||||
SpawnAng.p = 0
|
||||
SpawnAng.y = SpawnAng.y + 90
|
||||
ent:SetAngles( SpawnAng )
|
||||
ent:SetPos( trace.HitPos )
|
||||
ent:Spawn()
|
||||
ent:Activate()
|
||||
return ent
|
||||
end
|
||||
-- Tries to find the lowest Gondel and if found, searches for a free seatLocation
|
||||
function ENT:FindLowestGondel()
|
||||
local lowestZ, lowestGondel = math.huge, nil
|
||||
for i, k in pairs(self.Gondels) do
|
||||
local gondelZ = k:GetPos().z
|
||||
if gondelZ < lowestZ then
|
||||
lowestZ = gondelZ
|
||||
lowestGondel = k
|
||||
end
|
||||
end
|
||||
return lowestGondel
|
||||
end
|
||||
function ENT:GetEntryGondel()
|
||||
local lowestGondel = self:FindLowestGondel()
|
||||
for i, k in pairs(lowestGondel:GetAttachments()) do
|
||||
local seatPos = lowestGondel:GetAttachment(i).Pos
|
||||
local seatAtPosCount = 0
|
||||
for i,k in pairs(ents.FindInSphere(seatPos, 5)) do
|
||||
if k:GetClass() == "prop_vehicle_prisoner_pod" then seatAtPosCount = seatAtPosCount + 1 end
|
||||
end
|
||||
if seatAtPosCount == 0 then
|
||||
return {
|
||||
status = true,
|
||||
gondelEntity = lowestGondel,
|
||||
gondelSeat = i
|
||||
}
|
||||
end
|
||||
end
|
||||
return {
|
||||
status = false
|
||||
}
|
||||
end
|
||||
function ENT:TeleportPlayerIntoFreeGondel(ply)
|
||||
local freeSeat = self:GetEntryGondel()
|
||||
if freeSeat.status == false then
|
||||
ply:PrintMessage(HUD_PRINTCENTER, "No seat")
|
||||
return
|
||||
end
|
||||
local gondel = freeSeat.gondelEntity
|
||||
local attachment = gondel:GetAttachment( freeSeat.gondelSeat )
|
||||
local vehicle = ents.Create("prop_vehicle_prisoner_pod")
|
||||
vehicle:SetPos(attachment.Pos)
|
||||
local ang = attachment.Ang
|
||||
ang:RotateAroundAxis(ang:Forward(), -90)
|
||||
vehicle:SetAngles(ang)
|
||||
vehicle:SetModel("models/nova/airboat_seat.mdl")
|
||||
vehicle:SetKeyValue("vehiclescript", "scripts/vehicles/prisoner_pod.txt")
|
||||
vehicle:SetKeyValue("limitview","0")
|
||||
vehicle:Spawn()
|
||||
vehicle:SetNoDraw(true)
|
||||
vehicle.PositionBeforeEnter = ply:GetPos()
|
||||
vehicle.IsGondelVehicle = true
|
||||
vehicle:SetParent(gondel, freeSeat.gondelSeat)
|
||||
vehicle:Activate()
|
||||
ply:EnterVehicle(vehicle)
|
||||
end
|
||||
function ENT:Use(ply)
|
||||
--MsgN(self:WorldToLocal(ply:EyePos()))
|
||||
if ply:KeyDown(IN_SPEED) then
|
||||
end
|
||||
if ply.FerrisWheelTimeout && ply.FerrisWheelTimeout > CurTime() then return end
|
||||
self:TeleportPlayerIntoFreeGondel(ply)
|
||||
end
|
||||
|
||||
|
||||
|
||||
hook.Add("PlayerLeaveVehicle", "ferrisWheelExit", function(ply, veh)
|
||||
if veh.IsGondelVehicle then
|
||||
SafeRemoveEntity(veh)
|
||||
ply:SetPos(veh.PositionBeforeEnter)
|
||||
ply.FerrisWheelTimeout = CurTime() + 2
|
||||
end
|
||||
end)
|
Loading…
Reference in New Issue