Skip to content

Instantly share code, notes, and snippets.

@cm8263
Created May 1, 2020 15:57
Show Gist options
  • Save cm8263/f1162fce1008d9c5718c4dc04968626d to your computer and use it in GitHub Desktop.
Save cm8263/f1162fce1008d9c5718c4dc04968626d to your computer and use it in GitHub Desktop.
-- Matrix Board Version 1.0
--
-- Copyright (c) 2019-2020, Christopher M. All rights reserved.
--
-- This project is licensed under the following:
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to use, copy, modify, and merge the software, under the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE MAY NOT BE SOLD.
--
-- All vehicles and their respective extras
local Vehicles = {
-- Vehicle mode name
police = {
-- ID of the extras
{5, 6},
{11, 12}
}
}
--
-- Nothing past this point needs to be edited, all the settings for the resource are found ABOVE this line.
-- Do not make changes below this line unless you know what you are doing!
--
local ActiveMatrix = false
local LastExtra = false
RegisterCommand("matrix", function(_, args)
local PlayerPed = PlayerPedId()
if ActiveMatrix and not args[1] then
for _, extras in pairs(ActiveMatrix.Extras) do
for _, extra in pairs(extras) do
-- 0 = On, 1 = Off
SetVehicleExtra(ActiveMatrix.Vehicle, extra, 1)
end
end
ActiveMatrix = false
LastExtra = false
NewNoti('~g~Matrix disabled.', false)
return
end
if IsPedInAnyVehicle(PlayerPed, true) then
local Car = GetVehiclePedIsIn(PlayerPed, false)
local HasMatrix = false
for Vehicle, Extras in pairs(Vehicles) do
if GetHashKey(Vehicle) == GetEntityModel(Car) then HasMatrix = {Vehicle, Extras} end
end
if HasMatrix then
local MatrixNumber = tonumber(args[1])
if MatrixNumber then
if MatrixNumber > 0 and MatrixNumber <= #Vehicles[HasMatrix[1]] then
ActiveMatrix = {
Vehicle = Car,
Extras = HasMatrix[2],
Matrix = MatrixNumber
}
LastExtra = false
else
NewNoti('~r~' .. MatrixNumber .. ' is not a valid matrix for this car. This car has ' .. #Vehicles[HasMatrix[1]] .. ' matrix numbers.')
end
else
NewNoti('~r~' .. (args[1] or 'Nothing') .. ' is not a valid number. This car has ' .. #Vehicles[HasMatrix[1]] .. ' matrix numbers.')
end
else
NewNoti('~r~This vehicle does not support that command!', true)
end
else
NewNoti('~r~This command only works in vehicles!', true)
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if ActiveMatrix then
local PlayerPed = PlayerPedId()
if IsPedInAnyVehicle(PlayerPed, true) then
local Car = GetVehiclePedIsIn(PlayerPed, false)
local HasMatrix = false
for Vehicle, Extras in pairs(Vehicles) do
if GetHashKey(Vehicle) == GetEntityModel(Car) then HasMatrix = {Vehicle, Extras} end
end
end
if not LastExtra then
for _, extras in pairs(ActiveMatrix.Extras) do
for _, extra in pairs(extras) do
-- 0 = On, 1 = Off
SetVehicleExtra(ActiveMatrix.Vehicle, extra, 1)
end
end
SetVehicleExtra(ActiveMatrix.Vehicle, ActiveMatrix.Extras[ActiveMatrix.Matrix][1], 0)
Citizen.Wait(1000)
LastExtra = 1
else
if LastExtra == 1 then
SetVehicleExtra(ActiveMatrix.Vehicle, ActiveMatrix.Extras[ActiveMatrix.Matrix][1], 1)
SetVehicleExtra(ActiveMatrix.Vehicle, ActiveMatrix.Extras[ActiveMatrix.Matrix][2], 0)
LastExtra = 2
elseif LastExtra == 2 then
SetVehicleExtra(ActiveMatrix.Vehicle, ActiveMatrix.Extras[ActiveMatrix.Matrix][1], 0)
SetVehicleExtra(ActiveMatrix.Vehicle, ActiveMatrix.Extras[ActiveMatrix.Matrix][2], 1)
LastExtra = 1
end
Citizen.Wait(1000)
end
end
end
end)
function NewNoti(Text, Flash)
SetNotificationTextEntry("STRING")
AddTextComponentString(Text)
DrawNotification(Flash, true)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment