mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 05:43:46 +03:00
Upload
This commit is contained in:
218
lua/simfphys/server/joystick.lua
Normal file
218
lua/simfphys/server/joystick.lua
Normal file
@@ -0,0 +1,218 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
simfphys.jcon = {}
|
||||
|
||||
hook.Add("JoystickInitialize", "simfphys_joystick", function()
|
||||
simfphys.jcon.steer_left = jcon.register{
|
||||
uid = "joystick_steer_left",
|
||||
type = "analog",
|
||||
description = "Steer Left",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.steer_right = jcon.register{
|
||||
uid = "joystick_steer_right",
|
||||
type = "analog",
|
||||
description = "Steer Right",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.throttle = jcon.register{
|
||||
uid = "joystick_throttle",
|
||||
type = "analog",
|
||||
description = "Throttle",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.brake = jcon.register{
|
||||
uid = "joystick_brake",
|
||||
type = "analog",
|
||||
description = "Brake",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.gearup = jcon.register{
|
||||
uid = "joystick_gearup",
|
||||
type = "digital",
|
||||
description = "Gear Up",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.geardown = jcon.register{
|
||||
uid = "joystick_geardown",
|
||||
type = "digital",
|
||||
description = "Gear Down",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.handbrake = jcon.register{
|
||||
uid = "joystick_handbrake",
|
||||
type = "digital",
|
||||
description = "Handbrake",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.clutch = jcon.register{
|
||||
uid = "joystick_clutch",
|
||||
type = "analog",
|
||||
description = "Clutch",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.air_forward = jcon.register{
|
||||
uid = "joystick_air_w",
|
||||
type = "analog",
|
||||
description = "Air (forward)",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.air_reverse = jcon.register{
|
||||
uid = "joystick_air_s",
|
||||
type = "analog",
|
||||
description = "Air (backward)",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.air_left = jcon.register{
|
||||
uid = "joystick_air_a",
|
||||
type = "analog",
|
||||
description = "Air (left)",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.air_right = jcon.register{
|
||||
uid = "joystick_air_d",
|
||||
type = "analog",
|
||||
description = "Air (right)",
|
||||
category = "Simfphys",
|
||||
}
|
||||
|
||||
simfphys.jcon.gear_n = jcon.register{
|
||||
uid = "joystick_gear_n",
|
||||
type = "digital",
|
||||
description = "Gear Neutral",
|
||||
category = "Simfphys (Gears)",
|
||||
}
|
||||
|
||||
simfphys.jcon.gear_1 = jcon.register{
|
||||
uid = "joystick_gear_1",
|
||||
type = "digital",
|
||||
description = "Gear 1",
|
||||
category = "Simfphys (Gears)",
|
||||
}
|
||||
|
||||
simfphys.jcon.gear_2 = jcon.register{
|
||||
uid = "joystick_gear_2",
|
||||
type = "digital",
|
||||
description = "Gear 2",
|
||||
category = "Simfphys (Gears)",
|
||||
}
|
||||
|
||||
simfphys.jcon.gear_3 = jcon.register{
|
||||
uid = "joystick_gear_3",
|
||||
type = "digital",
|
||||
description = "Gear 3",
|
||||
category = "Simfphys (Gears)",
|
||||
}
|
||||
|
||||
simfphys.jcon.gear_4 = jcon.register{
|
||||
uid = "joystick_gear_4",
|
||||
type = "digital",
|
||||
description = "Gear 4",
|
||||
category = "Simfphys (Gears)",
|
||||
}
|
||||
|
||||
simfphys.jcon.gear_5 = jcon.register{
|
||||
uid = "joystick_gear_5",
|
||||
type = "digital",
|
||||
description = "Gear 5",
|
||||
category = "Simfphys (Gears)",
|
||||
}
|
||||
|
||||
simfphys.jcon.gear_6 = jcon.register{
|
||||
uid = "joystick_gear_6",
|
||||
type = "digital",
|
||||
description = "Gear 6",
|
||||
category = "Simfphys (Gears)",
|
||||
}
|
||||
|
||||
simfphys.jcon.gear_7 = jcon.register{
|
||||
uid = "joystick_gear_7",
|
||||
type = "digital",
|
||||
description = "Gear 7",
|
||||
category = "Simfphys (Gears)",
|
||||
}
|
||||
|
||||
simfphys.jcon.gear_8 = jcon.register{
|
||||
uid = "joystick_gear_8",
|
||||
type = "digital",
|
||||
description = "Gear 8",
|
||||
category = "Simfphys (Gears)",
|
||||
}
|
||||
|
||||
simfphys.jcon.gear_r = jcon.register{
|
||||
uid = "joystick_gear_r",
|
||||
type = "digital",
|
||||
description = "Gear Reverse",
|
||||
category = "Simfphys (Gears)",
|
||||
}
|
||||
|
||||
hook.Add("Think","simfphys_joystickhandler",function()
|
||||
|
||||
for i,ply in pairs( player.GetAll() ) do
|
||||
|
||||
if ply:IsConnected() then
|
||||
local vehicle = ply:GetVehicle()
|
||||
|
||||
if not IsValid( vehicle ) then return end
|
||||
|
||||
if not vehicle.fphysSeat then return end
|
||||
|
||||
if vehicle.base:GetDriverSeat() ~= vehicle then return end
|
||||
|
||||
for k,v in pairs( simfphys.jcon ) do
|
||||
if istable(v) and v.IsJoystickReg then
|
||||
local val = joystick.Get( ply, v.uid )
|
||||
|
||||
if v.type == "analog" then
|
||||
vehicle.base.PressedKeys[v.uid] = val and val / 255 or 0
|
||||
else
|
||||
if string.StartWith( v.uid, "joystick_gear_" ) then
|
||||
if v.uid == "joystick_gear_r" then
|
||||
if val then
|
||||
vehicle.base:ForceGear( 1 )
|
||||
end
|
||||
|
||||
elseif v.uid == "joystick_gear_n" then
|
||||
if val then
|
||||
vehicle.base:ForceGear( 2 )
|
||||
end
|
||||
|
||||
else
|
||||
for i = 1, 8 do
|
||||
if v.uid == ("joystick_gear_"..i) then
|
||||
if val then
|
||||
vehicle.base:ForceGear( i + 2 )
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
vehicle.base.PressedKeys[v.uid] = val and 1 or 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
43
lua/simfphys/server/poseparameter.lua
Normal file
43
lua/simfphys/server/poseparameter.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
util.AddNetworkString( "simfphys_request_ppdata" )
|
||||
util.AddNetworkString( "simfphys_send_ppdata" )
|
||||
|
||||
local function sendppdata( length, ply )
|
||||
local ent = net.ReadEntity()
|
||||
|
||||
if not IsValid( ent ) then return end
|
||||
|
||||
if ent.IsInitialized and not ent:IsInitialized() then return end
|
||||
if not istable( ent.Wheels ) then return end
|
||||
|
||||
net.Start( "simfphys_send_ppdata", true )
|
||||
net.WriteEntity( ent )
|
||||
net.WriteBool( ent.CustomWheels )
|
||||
|
||||
net.WriteEntity( ent.Wheels[1] )
|
||||
net.WriteFloat( ent.posepositions.PoseL_Pos_FL.z )
|
||||
net.WriteFloat( ent.VehicleData.suspensiontravel_fl )
|
||||
|
||||
net.WriteEntity( ent.Wheels[2] )
|
||||
net.WriteFloat( ent.posepositions.PoseL_Pos_FR.z )
|
||||
net.WriteFloat( ent.VehicleData.suspensiontravel_fr )
|
||||
|
||||
net.WriteEntity( ent.Wheels[3] )
|
||||
net.WriteFloat( ent.posepositions.PoseL_Pos_RL.z )
|
||||
net.WriteFloat( ent.VehicleData.suspensiontravel_rl )
|
||||
|
||||
net.WriteEntity( ent.Wheels[4] )
|
||||
net.WriteFloat( ent.posepositions.PoseL_Pos_RR.z )
|
||||
net.WriteFloat( ent.VehicleData.suspensiontravel_rr )
|
||||
net.Send( ply )
|
||||
end
|
||||
net.Receive("simfphys_request_ppdata", sendppdata)
|
||||
61
lua/simfphys/server/spawner.lua
Normal file
61
lua/simfphys/server/spawner.lua
Normal file
@@ -0,0 +1,61 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
function SpawnSimfphysVehicle( Player, vname, tr )
|
||||
if not vname then return end
|
||||
|
||||
local Tickrate = 1 / engine.TickInterval()
|
||||
|
||||
if ( Tickrate <= 25 ) and not Player.IsInformedAboutTheServersLowTickrate then
|
||||
Player:PrintMessage( HUD_PRINTTALK, "(SIMFPHYS) WARNING! Server tickrate is "..Tickrate.." we recommend 33 or greater for this addon to work properly!")
|
||||
Player:PrintMessage( HUD_PRINTTALK, "Known problems caused by a too low tickrate:")
|
||||
Player:PrintMessage( HUD_PRINTTALK, "- Wobbly suspension")
|
||||
Player:PrintMessage( HUD_PRINTTALK, "- Wheelspazz or shaking after an crash on bumps or while drifting")
|
||||
Player:PrintMessage( HUD_PRINTTALK, "- Moondrive (wheels turning slower than they should)")
|
||||
Player:PrintMessage( HUD_PRINTTALK, "- Worse vehicle performance (less grip, slower accelerating)")
|
||||
|
||||
Player.IsInformedAboutTheServersLowTickrate = true
|
||||
end
|
||||
|
||||
local VehicleList = list.Get( "simfphys_vehicles" )
|
||||
local vehicle = VehicleList[ vname ]
|
||||
|
||||
if not vehicle then return end
|
||||
|
||||
if not tr then
|
||||
tr = Player:GetEyeTraceNoCursor()
|
||||
end
|
||||
|
||||
local Angles = Player:GetAngles()
|
||||
Angles.pitch = 0
|
||||
Angles.roll = 0
|
||||
Angles.yaw = Angles.yaw + 180 + (vehicle.SpawnAngleOffset and vehicle.SpawnAngleOffset or 0)
|
||||
|
||||
local pos = tr.HitPos + Vector(0,0,25) + (vehicle.SpawnOffset or Vector(0,0,0))
|
||||
|
||||
local Ent = simfphys.SpawnVehicle( Player, pos, Angles, vehicle.Model, vehicle.Class, vname, vehicle )
|
||||
|
||||
if not IsValid( Ent ) then return end
|
||||
|
||||
undo.Create( "Vehicle" )
|
||||
undo.SetPlayer( Player )
|
||||
undo.AddEntity( Ent )
|
||||
undo.SetCustomUndoText( "Undone " .. vehicle.Name )
|
||||
undo.Finish( "Vehicle (" .. tostring( vehicle.Name ) .. ")" )
|
||||
|
||||
Player:AddCleanup( "vehicles", Ent )
|
||||
end
|
||||
concommand.Add( "simfphys_spawnvehicle", function( ply, cmd, args ) SpawnSimfphysVehicle( ply, args[1] ) end )
|
||||
|
||||
local function VehicleMemDupe( Player, Entity, Data )
|
||||
table.Merge( Entity, Data )
|
||||
end
|
||||
duplicator.RegisterEntityModifier( "VehicleMemDupe", VehicleMemDupe )
|
||||
Reference in New Issue
Block a user