Working MP
This commit is contained in:
@@ -1,23 +1,49 @@
|
||||
if isClient() then return end
|
||||
|
||||
local TowingCommands = {}
|
||||
local Commands = {}
|
||||
local TowBarItemType = "TowBar.TowBar"
|
||||
|
||||
function Commands.attachConstraint(player, args)
|
||||
local vehicleA = args and getVehicleById(args.vehicleA)
|
||||
local vehicleB = args and getVehicleById(args.vehicleB)
|
||||
local attachmentA = args and args.attachmentA
|
||||
local attachmentB = args and args.attachmentB
|
||||
if not vehicleA or not vehicleB or not attachmentA or not attachmentB then return end
|
||||
TowingCommands.wantNoise = getDebug() or false
|
||||
|
||||
vehicleA:addPointConstraint(player, vehicleB, attachmentA, attachmentB)
|
||||
local noise = function(msg)
|
||||
if TowingCommands.wantNoise then
|
||||
print("TowBarCommands: " .. msg)
|
||||
end
|
||||
end
|
||||
|
||||
function Commands.detachConstraint(player, args)
|
||||
local vehicle = args and getVehicleById(args.vehicle)
|
||||
if not vehicle then return end
|
||||
function Commands.attachTowBar(player, args)
|
||||
local vehicleA = getVehicleById(args.vehicleA)
|
||||
local vehicleB = getVehicleById(args.vehicleB)
|
||||
if not vehicleA then
|
||||
noise("no such vehicle (A) id=" .. tostring(args.vehicleA))
|
||||
return
|
||||
end
|
||||
if not vehicleB then
|
||||
noise("no such vehicle (B) id=" .. tostring(args.vehicleB))
|
||||
return
|
||||
end
|
||||
|
||||
vehicle:breakConstraint(true, false)
|
||||
vehicleA:addPointConstraint(player, vehicleB, args.attachmentA, args.attachmentB)
|
||||
end
|
||||
|
||||
function Commands.detachTowBar(player, args)
|
||||
local towingVehicle = args.towingVehicle and getVehicleById(args.towingVehicle) or nil
|
||||
local towedVehicle = args.vehicle and getVehicleById(args.vehicle) or nil
|
||||
|
||||
if not towingVehicle and towedVehicle then
|
||||
towingVehicle = towedVehicle:getVehicleTowedBy()
|
||||
end
|
||||
if not towedVehicle and towingVehicle then
|
||||
towedVehicle = towingVehicle:getVehicleTowing()
|
||||
end
|
||||
|
||||
if towedVehicle then
|
||||
towedVehicle:breakConstraint(true, false)
|
||||
end
|
||||
if towingVehicle and towingVehicle ~= towedVehicle then
|
||||
towingVehicle:breakConstraint(true, false)
|
||||
end
|
||||
end
|
||||
|
||||
function Commands.consumeTowBar(player, args)
|
||||
@@ -61,13 +87,20 @@ function Commands.giveTowBar(player, args)
|
||||
end
|
||||
end
|
||||
|
||||
local function onClientCommand(module, command, player, args)
|
||||
if module ~= "towbar" then return end
|
||||
-- Compatibility aliases for older command names.
|
||||
Commands.attachConstraint = Commands.attachTowBar
|
||||
Commands.detachConstraint = Commands.detachTowBar
|
||||
|
||||
local fn = Commands[command]
|
||||
if fn then
|
||||
fn(player, args or {})
|
||||
TowingCommands.OnClientCommand = function(module, command, player, args)
|
||||
if module == "towbar" and Commands[command] then
|
||||
local argStr = ""
|
||||
args = args or {}
|
||||
for k, v in pairs(args) do
|
||||
argStr = argStr .. " " .. tostring(k) .. "=" .. tostring(v)
|
||||
end
|
||||
noise("received " .. module .. " " .. command .. " " .. tostring(player) .. argStr)
|
||||
Commands[command](player, args)
|
||||
end
|
||||
end
|
||||
|
||||
Events.OnClientCommand.Add(onClientCommand)
|
||||
Events.OnClientCommand.Add(TowingCommands.OnClientCommand)
|
||||
|
||||
Reference in New Issue
Block a user