-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
local config = require 'config.client' | ||
|
||
---@type table<string, integer> | ||
local states = {} | ||
|
||
---Sets a boolean state. Runs its onSet function if the state is not previously set and the onSet function exists in config | ||
---@param name string | ||
---@return boolean firstSetter true if the state had not previously been set | ||
local function setState(name) | ||
if not states[name] then | ||
if config.states[name]?.onSet then | ||
config.states[name].onSet() | ||
end | ||
states[name] = 1 | ||
return true | ||
else | ||
states[name] += 1 | ||
return false | ||
end | ||
end | ||
|
||
---Releases a boolean state. Runs its onRelease function if this is the last call to release the state and the release function exists in config. | ||
---@param name string | ||
---@return boolean lastReleaser true if the state is fully released after this function | ||
local function releaseState(name) | ||
if not states[name] then states[name] = 0 end | ||
if states[name] <= 1 then | ||
states[name] = nil | ||
if config.states[name]?.onRelease() then | ||
config.states[name].onRelease() | ||
end | ||
return true | ||
else | ||
states[name] -= 1 | ||
return false | ||
end | ||
end | ||
|
||
exports('SetState', setState) | ||
exports('ReleaseState', releaseState) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
return { | ||
---@type table<string, State> | ||
states = {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
fx_version 'cerulean' | ||
game 'gta5' | ||
|
||
name 'qbx_playerstates' | ||
description 'Manage the state of the player' | ||
repository 'https://github.com/Qbox-project/qbx_playerstates' | ||
version '0.0.0' | ||
|
||
client_scripts { | ||
'client.lua', | ||
} | ||
|
||
files { | ||
'config/client.lua', | ||
} | ||
|
||
lua54 'yes' | ||
use_experimental_fxv2_oal 'yes' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
---@meta | ||
|
||
---@class State | ||
---@field onSet? function | ||
---@field onRelease? function |