Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalwk committed Oct 22, 2024
1 parent 88ee09e commit e2c2abc
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions SAPP SCRIPTS/UTILITY MODS/Custom Loadouts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ local loadouts = {
-----------------------------------

local players
local command_cooldown = {} -- Stores the cooldown state for each player
local command_cooldown = {}

api_version = '1.12.0.0'

Expand All @@ -304,7 +304,7 @@ end
function OnStart()
if get_var(0, '$gt') ~= 'n/a' then
players = {}
for i = 1,16 do
for i = 1, 16 do
if player_present(i) then
OnJoin(i)
end
Expand Down Expand Up @@ -365,7 +365,7 @@ end

function OnQuit(playerId)
players[playerId] = nil
command_cooldown[playerId] = nil -- Clear cooldown on player quit
command_cooldown[playerId] = nil
end

local function getLoadouts()
Expand All @@ -390,33 +390,51 @@ local function showLoadouts(playerId)
end
end

local function handleCooldown(playerId, current_time)
if command_cooldown[playerId] and current_time < command_cooldown[playerId] then
local remaining_time = command_cooldown[playerId] - current_time
rprint(playerId, "You must wait " .. remaining_time .. " seconds before using that command again.")
return true
end
return false
end

local function checkAndSetCooldown(playerId)
local current_time = os.time()
if handleCooldown(playerId, current_time) then
return false
end
command_cooldown[playerId] = current_time + cooldown_time
return true
end

function OnCommand(playerId, command)
local command_num = tonumber(command:match("^(%d+)"))
if command_num and playerId ~= 0 then
if playerId == 0 then return true end

local current_time = os.time()
if command_cooldown[playerId] and current_time < command_cooldown[playerId] then
local remaining_time = command_cooldown[playerId] - current_time
rprint(playerId, "You must wait " .. remaining_time .. " seconds before using that command again.")
local command_num = tonumber(command:match("^(%d+)"))
if command_num then
if not checkAndSetCooldown(playerId) then
return false
end

for loadout_name, loadout in pairs(loadouts) do
if loadout.id == command_num then
players[playerId] = loadout_name
rprint(playerId, "Loadout [" .. loadout_name .. "] selected! It will take effect upon respawn.")
command_cooldown[playerId] = current_time + cooldown_time
return false
end
end
rprint(playerId, "Invalid loadout number!")

elseif command:lower() == "loadouts" then
if not checkAndSetCooldown(playerId) then
return false
end
showLoadouts(playerId)
return false
end
end


function OnDeath(playerId)
showLoadouts(playerId)
end
Expand Down

0 comments on commit e2c2abc

Please sign in to comment.