Add WIP files

This commit is contained in:
SticksDev
2022-09-24 20:39:52 -04:00
commit 77c57ece72
5 changed files with 306 additions and 0 deletions

128
client/main.lua Normal file
View File

@ -0,0 +1,128 @@
if (clientConfig.showLogos) then
print(clientLogo)
end
local status = {
coreLoaded = false,
eventsEnabled = false,
eventCurrentlyRunning = false
}
local vehs = {"adder", "banshee", "bullet", "cheetah", "cyclone", "entityxf", "fmj", "gp1", "infernus", "italigtb",
"italigtb2", "nero", "nero2", "osiris", "penetrator", "pfister811", "reaper", "sc1", "sultanrs", "t20",
"tempesta", "turismor", "tyrus", "vacca", "vagner", "visione", "voltic", "xa21", "zentorno", "zorrusso"}
local clientEvents = {{
name = "chaosMod:SendStatus",
callback = function(data)
if (data.eventsEnabled ~= status.eventsEnabled) then
if (data.eventsEnabled) then
print("^1[ChaosMod Server ]^7: Events enabled")
else
print("^1[ChaosMod Server]^7: Events disabled")
end
end
if (data.eventCurrentlyRunning ~= status.eventCurrentlyRunning) then
if (data.eventCurrentlyRunning) then
print("^1[ChaosMod Server]^7: Event started")
else
print("^1[ChaosMod Server]^7: Event ended")
end
end
status.coreLoaded = data.coreLoaded
status.eventsEnabled = data.eventsEnabled
status.eventCurrentlyRunning = data.eventCurrentlyRunning
end
}, {
name = "chaosMod:RandomHealthDesc",
callback = function()
-- Descreese health by a random amount
local health = GetEntityHealth(PlayerPedId())
-- Make sure random health does not kill the player, so we set the minimum to 1
local randomHealth = math.random(1, health)
-- Set the new health
SetEntityHealth(PlayerPedId(), randomHealth)
end
}, {
name = "chaosMod:RandomHealthInc",
callback = function()
-- Increase health by a random amount
local health = GetEntityHealth(PlayerPedId())
local randomHealth = math.random(1, health)
-- Set the new health
SetEntityHealth(PlayerPedId(), randomHealth)
end
}, {
name = "chaosMod:SpawnRandomVehicles",
callback = function()
-- Check if the event is still running
if not status.eventCurrentlyRunning then
return
end
-- Get a random vehicle
local veh = vehs[math.random(1, #vehs)]
local ped = GetPlayerPed(source)
local playerCoords = GetEntityCoords(ped)
local playerHeading = GetEntityHeading(ped)
print(("^1[ChaosMod]^7: Spawning vehicle: %s (playerCords: %s)"):format(veh, playerCoords))
-- Spawn the vehicle
local veh = CreateVehicle(GetHashKey(veh), playerCoords.x, playerCoords.y, 50, playerHeading, true, false)
-- Set the vehicle to be invincible
SetEntityInvincible(veh, true)
SetTimeout(1000, function()
-- Delete
DeleteEntity(veh)
end)
Wait(500)
end
}}
local commands = {{
name = "eventtoggle",
desc = "Toggles the chaos events.",
func = function(source, args)
local enabled = args[1] == "true" and true or false
if args[1] == "true" or args[1] == "false" then
TriggerServerEvent('chaosMod:ToggleEvents', enabled)
TriggerEvent('chat:addMessage', {
color = {255, 0, 0},
multiline = true,
args = {"^1[ChaosMod]^7 ", ("Toggled events to be %s"):format(enabled and "^2enabled" or "^2disabled")}
})
else
-- Chat incorrect usage
TriggerEvent('chat:addMessage', {
color = {255, 0, 0},
multiline = true,
args = {"^1[ChaosMod]^7 Incorrect usage. Usage: /eventtoggle <true/false>"}
})
end
end
}}
-- Register client events
for _, event in pairs(clientEvents) do
print("^1[ChaosMod Client]^7: Registering client event: " .. event.name)
RegisterNetEvent(event.name)
AddEventHandler(event.name, event.callback)
end
-- Register commands
for _, command in pairs(commands) do
print("^1[ChaosMod Client]^7: Registering command: " .. command.name)
RegisterCommand(command.name, command.func)
end
-- Call for intial status when client is loaded
TriggerServerEvent('chaosMod:GetStatus')

8
config/config.lua Normal file
View File

@ -0,0 +1,8 @@
clientConfig = {
showLogos = true, -- Show logos on server/client start
}
serverConfig = {
showLogos = true, -- Show logos on server/client start
eventsEnabled = false, -- Enable events on server start
}

21
fxmanifest.lua Normal file
View File

@ -0,0 +1,21 @@
-- Resource Metadata
fx_version 'cerulean'
games { 'gta5' }
author 'SticksDev (sticks#2701)'
description 'A chaos mod for your FiveM server.'
version '1.0.0'
-- Load server scripts
server_script {
'config/*.lua',
'utils/*.lua',
'server/*.lua',
}
-- Load client scripts
client_scripts {
'config/*.lua',
'utils/*.lua',
'client/*.lua',
}

125
server/main.lua Normal file
View File

@ -0,0 +1,125 @@
if(serverConfig.showLogos) then
print(serverLogo)
end
local status = {
eventsEnabled = false,
coreLoaded = false,
eventsAlreadyRunning = false,
eventCurrentlyRunning = false,
}
local serverEvents = {
{
name = "chaosMod:GetStatus",
callback = function()
TriggerClientEvent('chaosMod:SendStatus', source, status)
end
},
{
name = "chaosMod:ToggleEvents",
callback = function(arg)
status.eventsEnabled = arg
end
}
}
local events = {
{
name = "Random Health Decrease",
desc = "Decreases your health by a random amount",
time = 5,
func = function()
TriggerClientEvent('chaosMod:RandomHealthDesc', -1)
end
},
{
name = "Random Health Increase",
desc = "Increases your health by a random amount",
time = 5,
func = function()
TriggerClientEvent('chaosMod:RandomHealthInc', -1)
end
},
-- {
-- name = "Spawn Random Vehicles",
-- desc = "Spawns random vehicles around you",
-- time = 60,
-- func = function()
-- TriggerClientEvent('chaosMod:SpawnRandomVehicles', -1)
-- end
-- }
{
name = "Random Explosions",
desc = "Spawns random explosions around you",
time = 60,
func = function()
TriggerClientEvent('chaosMod:RandomExplosions', -1)
end
}
}
print("^1[ChaosMod]^7: Initializing...")
-- Regsiter server events
for _, event in pairs(serverEvents) do
print("^1[ChaosMod]^7: Registering server event: " .. event.name)
RegisterServerEvent(event.name)
AddEventHandler(event.name, event.callback)
end
print("^1[ChaosMod]^7: Server events registered. Initializing core thread...")
function eventMainHandler()
-- Choose a random event
local event = events[math.random(1, #events)]
-- Chat that the event is starting
TriggerClientEvent('chat:addMessage', -1, {
color = { 255, 0, 0},
multiline = true,
args = {"^1[ChaosMod]^7 ", "Starting event: " .. event.name}
})
-- Call the event
event.func()
-- Set that event is already running
status.eventsAlreadyRunning = true
status.eventCurrentlyRunning = true
-- Wait for the event to finish
Wait(event.time * 1000)
-- Chat that the event is finished
TriggerClientEvent('chat:addMessage', -1, {
color = { 255, 0, 0},
multiline = true,
args = {"^1[ChaosMod]^7 ", "Finished event: " .. event.name .. "! The next event will start in 30 seconds."}
})
-- Wait 30 seconds and then remove the already running status
-- SetTimeout(30000, function()
-- status.eventsAlreadyRunning = false
-- end)
status.eventsAlreadyRunning = false
end
-- Create a thread to handle events
Citizen.CreateThread(function()
while true do
Citizen.Wait(500)
if status.eventsEnabled and not status.eventsAlreadyRunning then
eventMainHandler()
end
-- Push an update to status
TriggerClientEvent('chaosMod:SendStatus', -1, status)
end
end)
print("^1[ChaosMod]^7: Core thread initialized. Ready!")
status.coreLoaded = true

24
utils/globals.lua Normal file
View File

@ -0,0 +1,24 @@
clientLogo = [[
_____ _ __ __ _
/ ____| | | \/ | | |
| | | |__ __ _ ___ ___| \ / | ___ __| |
| | | '_ \ / _` |/ _ \/ __| |\/| |/ _ \ / _` |
| |____| | | | (_| | (_) \__ \ | | | (_) | (_| |
\_____|_| |_|\__,_|\___/|___/_| |_|\___/ \__,_|
]]
serverLogo = [[
_____ _ __ __ _
/ ____| | | \/ | | |
| | | |__ __ _ ___ ___| \ / | ___ __| |
| | | '_ \ / _` |/ _ \/ __| |\/| |/ _ \ / _` |
| |____| | | | (_| | (_) \__ \ | | | (_) | (_| |
\_____|_| |_|\__,_|\___/|___/_| |_|\___/ \__,_|
"Wha'cha gonna do, stab me?"
]]