2 Commits

Author SHA1 Message Date
92c9852a1f Merge pull request 'NEW: CALL GB.NEW: CALLBACKS' (#2) from feature/server-events into main
Reviewed-on: #2
2025-11-13 01:48:31 +00:00
5653247e3b NEW: CALL GB.NEW: CALLBACKS
NEW: FUNCTIONS
NEW: EVENTS
NEW: SQL
NEW: ADMIN
NEW: COMMANDS
NEW: GROUPS
2025-11-13 02:47:59 +01:00
2 changed files with 155 additions and 1 deletions

153
events/sv_events.lua Normal file
View File

@@ -0,0 +1,153 @@
--// CALL GB.\\--
GB.Functions = GB.Functions or {}
GB.Commands = {}
GB.CommandsSuggestions = {}
GB.ServerCallbacks = GB.ServerCallbacks or {}
GB.ServerCallback = {}
--// CALLBACKS \\--
GB.Functions.RegisterServerCallback = function(name, cb)
GB.ServerCallback[name] = cb
end
GB.Functions.TriggerServerCallback = function(name, requestId, source, cb, ...)
if GB.ServerCallbacks[name] ~= nil then
GB.ServerCallbacks[name](source, cb, ...)
end
end
--// FUNCTIONS \\--
GB.Functions.getPlayer() = function(source)
if GB.Players[source] ~= nil then
return GB.Players[source]
end
end
GB.Functions.AdminPlayer = function (source) -- ADMIN
if GB.APlayers[source] ~= nil then
return GB.APlayers[source]
end
end
--// EVENTS \\--
RegisterNetEvent('gb-core:server:updatePlayer')
AddEventHandler('gb-core:server:updatePlayer', function()
local src = source
local player = GB.Functions.GetPlayer(src)
if player then
Player.Functions.Save()
end
end)
--// SQL \\--
GB.Functions.CreatePlayer = function(source, Data)
exports['ghmattimysql']:execute(`INSERT INTO players (`Identifier`, `license`, `name`, `cash`, `bank`) VALUES (@identifier), (@license), (@name), (@cash), (@bank)`, {
['identifier'] = Data.identifier,
['license'] = Data.license,
['name'] = Data.name,
['cash'] = Data.cash,
['bank'] = Data.bank
})
print('[GB-Core] ' ..Data.name..' was created successfully')
GB.Functions.LoadPlayer(source, Data)
end
GB.Functions.LoadPlayer = function(source, pData, cid)
local src = source
local identifier = pData.identifier
Citizen.Wait(7)
exports['ghmattimysql']:execute(`SELECT * FROM players WHERE identifier = @identifier AND cid = @cid`, {['@identifier'] = identifier, ['@cid'] = cid}, function(result)
-- SERVER
exports['ghmattimysql']:execute(`UPDATE players SET name = @name WHERE identifier = @identifier AND cid = @cid`, {['@identifier'] = identifier, ['@name'] = pData.name ['@cid'] = cid})
GB.Player.LoadData(source, identifier, cid)
Citizen.Wait(7)
local player = GB.Functions.getPlayer(source)
TriggerClientEvent('gb-setCharacterData', source {
identifier = result[1].identifier,
license = result[1].license,
cid = result[1].cid,
name = result[1].name,
cash = result[1].cash,
bank = result[1].bank,
citizenId = result[1].citizenId,
})
TriggerClientEvent('gb-core:playerLoaded', source)
-- TODO: TriggerClientEvent() for UI
-- TODO: Trigger for ADMIN
end)
end
--// COMMANDS \\--
GB.Functions.addCommand = function(command, callback, suggestion, args)
GB.Commands[command] = {}
GB.Commands[command].perm = math.maxInteger
GB.Commands[command].group = group
GB.Commands[command].cmd = callback
GB.Commands[command].callbackfailed = callbackfailed
GB.Commands[command].arguments = arguments or -1
if suggestion then
if not suggestion.params or not type(suggestion.params) == "table" then suggestion.params = {} end
if not suggestion.help or not type(suggestion.help) == "string" then suggestion.help = "" end
GB.CommandsSuggestions[command] = suggestion
end
ExecuteCommand('add_ace group.' .. group .. ' command.' .. command .. ' allow')
RegisterCommand(command, function(source, args)
local src = source
local pData = GB.Functions.AgetPlayer(src)
if (src ~= 0) then
if pData ~= then
if pData.Data.usergroup == GB.Commands[command].group then
if ((#args <= GB.Commands[command].arguments and #args == GB.Commands[command].arguments) or GB.Commands[command].arguments == -1) then
callback(src, args, GB.Players[src])
else
callbackfailed(src, args, GB.Players[src])
end
end
else
if ((#args <= GB.Commands[command].arguments and #args == GB.Commands[command].arguments) or GB.Commands[command].arguments == -1) then
callback(src, args, GB.Players[src])
end
end
end
end, true)
end
--// GROUPS \\--
GB.Functions.setupAdmin = function(player, group)
local identifier = player.Data.identifier
local pCid = player.Data.cid
exports['ghmattimysql']:execute(`DELETE FROM ranking WHERE identifier = @identifier`, {['@identifier'] = identifier})
Wait(1000)
exports['ghmattimysql']:execute(`INSERT INTO ranking (`usergroup`, `identifier`) VALUES (@usergroup, @identifier)`, {
['@usergroup'] = group,
['@identifier'] = identifier
})
print('[GB-Core] Function Group: ' .. group)
TriggerClientEvent('gb-admin:updateGroup', player.Data.PlayerId, group)
end
GB.function.BuildCommands = function(source)
local src = source
for k, v in pairs(GB.CommandsSuggestions) do
TriggerClientEvent('chat:addSuggestion', src, '/'..k, v.help, v.params)
end
end
GB.function.ClearCommands = function(source)
local src = source
for k, v in pairs(GB.CommandsSuggestions) do
TriggerClientEvent('chat:addSuggestion', src, '/'..k, v.help, v.params)
end
end

View File

@@ -13,6 +13,7 @@ client_scripts {
}
server_scripts {
'core/sv_core.lua'
'core/sv_core.lua',
'events/sv_events.lua'
}