From 143ccd223989ecddb6a222e73a2a3ba3a4176563 Mon Sep 17 00:00:00 2001 From: Andrew Martin <10902965+AndrewR3K@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:47:40 -0700 Subject: [PATCH] cleanup --- bcc-posse/README.md | 35 ---- bcc-posse/client.lua | 276 ----------------------------- bcc-posse/fxmanifest.lua | 20 --- bcc-posse/server.lua | 187 ------------------- bcc-posse/sql.sql | 9 - client.lua | 16 +- bcc-posse/config.lua => config.lua | 0 fxmanifest.lua | 8 +- server.lua | 43 ++--- 9 files changed, 37 insertions(+), 557 deletions(-) delete mode 100644 bcc-posse/README.md delete mode 100644 bcc-posse/client.lua delete mode 100644 bcc-posse/fxmanifest.lua delete mode 100644 bcc-posse/server.lua delete mode 100644 bcc-posse/sql.sql rename bcc-posse/config.lua => config.lua (100%) diff --git a/bcc-posse/README.md b/bcc-posse/README.md deleted file mode 100644 index 1cc0d90..0000000 --- a/bcc-posse/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# bcc-posse -The bcc-posse RedM script offers exciting functionalities to create and manage posses in the wild west. With this script, players can form their own gangs, invite members, and embark on immersive multiplayer adventures together. - -## Installation -1. Ensure that you have RedM installed and running. -2. Download the bcc-posse script files. -3. Place the bcc-posse script folder into the resources directory of your RedM server. -4. Add ensure `bcc-posse` to your server.cfg file to start the script on server startup. -Usage - -## Posse Formation -To form a posse, players can use the in-game command /posse. This command will allow them to create a new posse and become the posse leader. - -## Posse Area Check -To check if any individuals within a specific area are part of your posse, you can utilize the following export function: - -```lua -local posseMembers, posseSize = exports['bcc-posse']:CheckPosseArea(coords, radius) -``` - -This export function will retrieve the server IDs of all posse members present within the designated radius. Additionally, it returns the length of the table containing the IDs, which can be useful for implementing reward systems. - -## Reward System Integration -The bcc-posse script supports the integration of reward systems based on posse size. You can customize rewards using the following code: - -```lua -Character.addCurrency(0, 100 * posseSize) -- Assuming 'vorp' is the currency system being used -``` - -By multiplying the base reward amount (100 in this example) with the posse size, you can dynamically adjust the rewards according to the number of posse members. - -Please note that the script is designed to work seamlessly with the VORP currency system, ensuring a smooth experience for your posse members. - -## Cotributing -Contributions to the bcc-posse script are welcome! If you have any bug fixes, improvements, or new feature suggestions, feel free to open a pull request on the GitHub repository. diff --git a/bcc-posse/client.lua b/bcc-posse/client.lua deleted file mode 100644 index 61cc31d..0000000 --- a/bcc-posse/client.lua +++ /dev/null @@ -1,276 +0,0 @@ -local VORPcore = {} -local posselist = {} -Possetable = {} -local possenumber -local playid -local isinvited = false -local invitedpossename -local possename = " " - -TriggerEvent("getCore", function(core) - VORPcore = core -end) - -TriggerEvent('chat:addSuggestion', '/posse', 'Posse Menu Command') - -RegisterCommand('posse', function() - PosseMenu() -end) - -RegisterNetEvent('bcc-posse:sendinfo') -AddEventHandler('bcc-posse:sendinfo', function(posseid, inposse, radius) - local closestPlayer, closestDistance = GetClosestPlayer() - local targetid = GetPlayerServerId(closestPlayer) - possenumber = posseid - if not inposse then - inposse = false - else - inposse = true - if closestPlayer ~= -1 and closestDistance <= radius then - TriggerServerEvent('bcc-posse:checkposse', tonumber(targetid), possenumber) - end - --local id = GetPlayerServerId(GetPlayerIndex()) - --table.insert(Possetable, id) - end - print(possenumber) -end) - -function CheckPosseArea(coords, radius) - Possetable = {} - local pedcoords = coords - local ptable = GetActivePlayers() - for _, i in pairs(ptable) do - local targetped = GetPlayerPed(i) - playid = GetPlayerServerId(i) - if (Vdist(GetEntityCoords(targetped), pedcoords.x, pedcoords.y, pedcoords.z) < radius) then - if contains(Possetable, playid) then - print('its the same') - break - else - TriggerServerEvent('bcc-posse:grabinfo', playid, radius) - end - end - end - Wait(750) - return Possetable, #Possetable -end - -function contains(table, val) - for i = 1, #table do - if table[i] == val then - return true - end - end - return false -end - -RegisterNetEvent('bcc-posse:possefound') -AddEventHandler('bcc-posse:possefound', function() - table.insert(Possetable, playid) -end) - -RegisterNetEvent('bcc-posse:sendposseinvites') -AddEventHandler('bcc-posse:sendposseinvites', function(posseid, posseinvites, invite) - isinvited = invite - invitedpossename = posseinvites - invitenumber = posseid - possenumber = invitenumber - print(possenumber) - -end) - -MenuData = {} -TriggerEvent("menuapi:getData", function(call) - MenuData = call -end) -function PosseMenu() -- Base Menu Logic - TriggerServerEvent('bcc-posse:grabinfo',source,Config.InviteDistance) - - MenuData.CloseAll() - local elements = {} - - if isinvited then - table.insert(elements, { label = "Create Posse", value = 'create' }) - table.insert(elements, { label = "Invite to posse", value = 'invite' }) - table.insert(elements, { label = "Accept Posse Invites", value = 'viewinvites' }) - table.insert(elements, { label = "View Members", value = 'view' }) - table.insert(elements, { label = "Leave Posse", value = 'leave' }) - else - table.insert(elements, { label = "Create Posse", value = 'create' }) - table.insert(elements, { label = "Invite to posse", value = 'invite' }) - table.insert(elements, { label = "View Members", value = 'view' }) - table.insert(elements, { label = "Leave Posse", value = 'leave' }) - end - - MenuData.Open('default', GetCurrentResourceName(), 'menuapi', - { - title = "Posse Menu", - align = 'left', - elements = elements, - }, - function(data, menu) - if (data.current.value == 'create') then - CreatePosseMenu() - end - if (data.current.value == 'view') then - Wait(250) - TriggerServerEvent('bcc-posse:posselist', possenumber) - end - if (data.current.value == 'leave') then - Wait(100) - TriggerServerEvent('bcc-posse:leaveposse') - menu.close() - end - - if (data.current.value == 'invite') then - local closestPlayer, closestDistance = GetClosestPlayer() - if closestPlayer ~= -1 and closestDistance <= 1.5 then - TriggerServerEvent('bcc-posse:beeninvitedsv', GetPlayerServerId(closestPlayer)) - else - VORPcore.NotifyBottomRight("Not close enough", 4000) - end - end - - if (data.current.value == 'viewinvites') then - Wait(250) - ViewPosseInvites() - end - end, - function(data, menu) - menu.close() - end) -end - -function CreatePosseMenu() -- Create Posse Menu logic - MenuData.CloseAll() - local button = "Confirm" - local placeholder = "Posse Name" - - local elements = { - { label = "Posse Name: " .. possename, value = 'name' }, - { label = "Confirm Posse Name", value = 'confirm' }, - - } - MenuData.Open('default', GetCurrentResourceName(), 'menuapi', - { - title = "Posse Menu", - align = 'left', - elements = elements, - lastmenu = "PosseMenu" - }, - function(data, menu) - if data.current == "backup" then - _G[data.trigger]() - end - if (data.current.value == 'name') then - TriggerEvent("vorpinputs:getInput", button, placeholder, function(result) - if result ~= "" or result then -- making sure its not empty or nil - possename = result - CreatePosseMenu() - else - print("its empty?") -- notify - end - end) - end - - if (data.current.value == 'confirm') then - TriggerServerEvent('bcc-posse:createposse', possename) - menu.close() - end - end, - function(data, menu) - menu.close() - end) -end - -function ViewPosseInvites() -- ViewInvite Logic - MenuData.CloseAll() - local elements = { - { label = invitenumber .. " : " .. invitedpossename, value = 'posse' }, - { label = "Accept", value = 'accept' }, - { label = "Deny", value = 'deny' }, - - - } - - MenuData.Open('default', GetCurrentResourceName(), 'menuapi', - { - title = "Posse Menu", - align = 'left', - elements = elements, - lastmenu = "PosseMenu" - }, - function(data, menu) - if data.current == "backup" then - _G[data.trigger]() - end - if data.current.value == "accept" then - TriggerServerEvent('bcc-posse:acceptinvite', invitenumber) - isinvited = false - menu.close() - end - if data.current.value == "deny" then - isinvited = false - menu.close() - end - end, - function(data, menu) - end) -end - -RegisterNetEvent('bcc-posse:ViewMembersMenu', function(result) - -- View Member Logic - MenuData.CloseAll() - local elements, elementindex = {}, 1 - for key, v in pairs(result) do - elements[elementindex] = { - label = v.firstname .. " " .. v.lastname, - value = "players" - } - elementindex = elementindex + 1 - end - - MenuData.Open('default', GetCurrentResourceName(), 'menuapi', - { - title = "Posse Menu", - align = 'left', - elements = elements, - lastmenu = "PosseMenu" - }, - function(data, menu) - if data.current == "backup" then - _G[data.trigger]() - end - end, - function(data, menu) - menu.close() - end) -end) - -function GetClosestPlayer() - local players, closestDistance, closestPlayer = GetActivePlayers(), -1, -1 - local playerPed, playerId = PlayerPedId(), PlayerId() - local coords, usePlayerPed = coords, false - - if coords then - coords = vector3(coords.x, coords.y, coords.z) - else - usePlayerPed = true - coords = GetEntityCoords(playerPed) - end - - for i = 1, #players, 1 do - local tgt = GetPlayerPed(players[i]) - - if not usePlayerPed or (usePlayerPed and players[i] ~= playerId) then - local targetCoords = GetEntityCoords(tgt) - local distance = #(coords - targetCoords) - - if closestDistance == -1 or closestDistance > distance then - closestPlayer = players[i] - closestDistance = distance - end - end - end - return closestPlayer, closestDistance -end diff --git a/bcc-posse/fxmanifest.lua b/bcc-posse/fxmanifest.lua deleted file mode 100644 index b6625cc..0000000 --- a/bcc-posse/fxmanifest.lua +++ /dev/null @@ -1,20 +0,0 @@ -fx_version "adamant" -games { "rdr3" } -rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aware my resources *will* become incompatible once RedM ships.' - -server_scripts { - 'server.lua', - '@oxmysql/lib/MySQL.lua' - -} - -shared_scripts { - 'config.lua' -} - -client_scripts { - 'client.lua' -} - - -export 'CheckPosseArea' diff --git a/bcc-posse/server.lua b/bcc-posse/server.lua deleted file mode 100644 index 9219239..0000000 --- a/bcc-posse/server.lua +++ /dev/null @@ -1,187 +0,0 @@ -local VORPcore = {} - -TriggerEvent("getCore", function(core) - VORPcore = core -end) - -local posseid -local possename -local number - -RegisterServerEvent("bcc-posse:grabinfo") -AddEventHandler("bcc-posse:grabinfo", function(id, radius) - local _source = id - if _source == nil then - _source = source - end - Wait(100) - local player = VORPcore.getUser(_source).getUsedCharacter - local charid = player.charIdentifier - local result = MySQL.query.await("SELECT posseid FROM characters WHERE charidentifier=@characterid", - { ["characterid"] = charid }) - if result ~= 0 then - posseid = result[1].posseid - else - TriggerClientEvent("vorp:TipBottom", _source, "not in posse", 3000) - end - local inposse = false - if posseid ~= 0 then - inposse = true - end - TriggerClientEvent('bcc-posse:sendinfo', _source, posseid, inposse, radius) -end) - -RegisterServerEvent("bcc-posse:checkposse") -AddEventHandler("bcc-posse:checkposse", function(targetid, id) - local _source = source - if _source == nil then - _source = source - end - local target = VORPcore.getUser(targetid).getUsedCharacter - local tarid = target.charIdentifier - - exports.ghmattimysql:execute("SELECT posseid FROM `characters` WHERE charidentifier = @characterid", - { ["@characterid"] = tarid }, - function(result) - if result[1].posseid == id then - id = result[1].posseid - TriggerClientEvent('bcc-posse:possefound', _source) - end - end) -end) - - -RegisterServerEvent("bcc-posse:leaveposse") -AddEventHandler("bcc-posse:leaveposse", function(posseid) - local _source = source - local player = VORPcore.getUser(_source).getUsedCharacter - local steamid = player.identifier - local charid = player.charIdentifier - exports.ghmattimysql:execute("SELECT id FROM `posse` WHERE characterid = @characterid", - { ["@characterid"] = charid }, - function(result) - if result[1] then - exports.ghmattimysql:execute( - 'UPDATE characters SET posseid=@newposseid WHERE posseid = posseid ', - { ['@newposseid'] = 0, ['posseid'] = posseid }) - - - exports.ghmattimysql:execute("SELECT * FROM `posse` WHERE characterid = @targetid", - { ["@targetid"] = charid }, - function(result) - possename = result[1].possename - end) - - exports.ghmattimysql:execute( - 'DELETE FROM posse WHERE identifier = @identifier AND characterid = @charid', { - ['@identifier'] = steamid, - ['@charid'] = charid, - }) - else - exports.ghmattimysql:execute( - 'UPDATE characters SET posseid=@newposseid WHERE posseid = posseid and charidentifier = @charid', - { ['@newposseid'] = 0, ['posseid'] = posseid, ['@charid'] = charid }) - end - end) -end) - -RegisterServerEvent("bcc-posse:beeninvitedsv") -AddEventHandler("bcc-posse:beeninvitedsv", function(targetid) - local _source = source - - local target = VORPcore.getUser(targetid).getUsedCharacter - local tarid = target.charIdentifier - local Character = VORPcore.getUser(_source).getUsedCharacter - local charid = Character.charIdentifier - - exports.ghmattimysql:execute("SELECT * FROM `characters` WHERE charidentifier = @targetid", - { ["@targetid"] = tarid }, - function(result) - posseid = result[1].posseid - - exports.ghmattimysql:execute("SELECT * FROM `posse` WHERE characterid = @characterid", - { ["@characterid"] = charid }, - function(result) - possename = result[1].possename - number = result[1].id - Wait(100) - if posseid == 0 then - TriggerClientEvent('bcc-posse:sendposseinvites', targetid, number, possename, true) - TriggerClientEvent("vorp:NotifyLeft", targetid, 'Posse Invite', 'You have been invited to a posse', - 'inventory_items', - 'folder_invitations', 5000) - else - TriggerClientEvent("vorp:TipBottom", targetid, "already in posse", 3000) - end - end) - end) - -end) - -RegisterServerEvent("bcc-posse:acceptinvite") -AddEventHandler("bcc-posse:acceptinvite", function(possenumber) - local _source = source - local Character = VORPcore.getUser(_source).getUsedCharacter - local steamid = Character.identifier - local charid = Character.charIdentifier - - exports.ghmattimysql:execute("SELECT * FROM `characters` WHERE charidentifier = @characterid", - { ["@characterid"] = charid }, - function(result) - posseid = result[1].posseid - - if posseid == 0 then - exports.ghmattimysql:execute( - 'UPDATE characters SET posseid=@posseid WHERE identifier=@identifier AND charidentifier=@charidentifier', - { ['posseid'] = possenumber, ['identifier'] = steamid, ['charidentifier'] = charid }) - TriggerClientEvent("vorp:TipBottom", _source, "joined posse", 3000) - else - TriggerClientEvent("vorp:TipBottom", _source, "already in posse", 3000) - end - end) -end) - -RegisterServerEvent("bcc-posse:createposse") -AddEventHandler("bcc-posse:createposse", function(possename) - local _source = source - local player = VORPcore.getUser(_source).getUsedCharacter - local steamid = player.identifier - local charid = player.charIdentifier - exports.ghmattimysql:execute("SELECT id FROM `posse` WHERE characterid = @characterid", - { ["@characterid"] = charid }, - function(result) - if result[1] then - TriggerClientEvent("vorp:TipBottom", _source, "Posse exists ", 3000) - else - exports.ghmattimysql:execute( - "INSERT INTO posse (identifier, characterid, possename) VALUES (@identifier, @characterid, @possename)" - , { ["@identifier"] = steamid, ["@characterid"] = charid, ["@possename"] = possename }) - TriggerClientEvent("vorp:TipBottom", _source, "Posse created ", 3000) - end - end) - Wait(200) - - exports.ghmattimysql:execute("SELECT * FROM `posse` WHERE characterid = @characterid", - { ["@characterid"] = charid }, - function(result) - posseid = result[1].id - exports.ghmattimysql:execute( - 'UPDATE characters SET posseid=@posseid WHERE identifier=@identifier AND charidentifier=@charidentifier', - { ['posseid'] = posseid, ['identifier'] = steamid, ['charidentifier'] = charid }) - end) -end) - -RegisterServerEvent("bcc-posse:posselist") -AddEventHandler("bcc-posse:posselist", function(possenumber) - print(possenumber) - local _source = source - - if possenumber > 0 then - exports.ghmattimysql:execute( - "SELECT firstname, lastname, charidentifier FROM characters WHERE posseid = @posseid", - { ["posseid"] = possenumber }, - function(result) - TriggerClientEvent('bcc-posse:ViewMembersMenu', _source, result) - end) - end -end) diff --git a/bcc-posse/sql.sql b/bcc-posse/sql.sql deleted file mode 100644 index 2553abc..0000000 --- a/bcc-posse/sql.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE IF NOT EXISTS `posse` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `identifier` varchar(50) NOT NULL DEFAULT '0', - `characterid` varchar(50) NOT NULL DEFAULT '0', - `possename` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; - -ALTER TABLE `characters` ADD COLUMN `posseid` INT(11) NULL DEFAULT 0; diff --git a/client.lua b/client.lua index 0c6fbe9..61cc31d 100644 --- a/client.lua +++ b/client.lua @@ -6,7 +6,6 @@ local playid local isinvited = false local invitedpossename local possename = " " -local InviteDistance = 50.0 --Change this to the distance players must be with in to be invited and accept invites TriggerEvent("getCore", function(core) VORPcore = core @@ -28,7 +27,7 @@ AddEventHandler('bcc-posse:sendinfo', function(posseid, inposse, radius) else inposse = true if closestPlayer ~= -1 and closestDistance <= radius then - TriggerServerEvent('bcc-posse:checkposse', tonumber(targetid), id) + TriggerServerEvent('bcc-posse:checkposse', tonumber(targetid), possenumber) end --local id = GetPlayerServerId(GetPlayerIndex()) --table.insert(Possetable, id) @@ -74,7 +73,10 @@ RegisterNetEvent('bcc-posse:sendposseinvites') AddEventHandler('bcc-posse:sendposseinvites', function(posseid, posseinvites, invite) isinvited = invite invitedpossename = posseinvites - possenumber = posseid + invitenumber = posseid + possenumber = invitenumber + print(possenumber) + end) MenuData = {} @@ -82,7 +84,7 @@ TriggerEvent("menuapi:getData", function(call) MenuData = call end) function PosseMenu() -- Base Menu Logic - TriggerServerEvent('bcc-posse:grabinfo',source,InviteDistance) + TriggerServerEvent('bcc-posse:grabinfo',source,Config.InviteDistance) MenuData.CloseAll() local elements = {} @@ -130,7 +132,7 @@ function PosseMenu() -- Base Menu Logic end if (data.current.value == 'viewinvites') then - Wait(100) + Wait(250) ViewPosseInvites() end end, @@ -184,7 +186,7 @@ end function ViewPosseInvites() -- ViewInvite Logic MenuData.CloseAll() local elements = { - { label = possenumber .. " : " .. invitedpossename, value = 'posse' }, + { label = invitenumber .. " : " .. invitedpossename, value = 'posse' }, { label = "Accept", value = 'accept' }, { label = "Deny", value = 'deny' }, @@ -203,7 +205,7 @@ function ViewPosseInvites() -- ViewInvite Logic _G[data.trigger]() end if data.current.value == "accept" then - TriggerServerEvent('bcc-posse:acceptinvite', possenumber) + TriggerServerEvent('bcc-posse:acceptinvite', invitenumber) isinvited = false menu.close() end diff --git a/bcc-posse/config.lua b/config.lua similarity index 100% rename from bcc-posse/config.lua rename to config.lua diff --git a/fxmanifest.lua b/fxmanifest.lua index 26cc013..c61299c 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,17 +1,19 @@ fx_version "adamant" games { "rdr3" } rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aware my resources *will* become incompatible once RedM ships.' - lua54 'yes' author 'Jannings' - server_scripts { 'server.lua', '@oxmysql/lib/MySQL.lua' } +shared_scripts { + 'config.lua' +} + client_scripts { 'client.lua' } @@ -19,4 +21,4 @@ client_scripts { export 'CheckPosseArea' -version '1.1.2' +version '1.1.2' \ No newline at end of file diff --git a/server.lua b/server.lua index 4c97265..9219239 100644 --- a/server.lua +++ b/server.lua @@ -6,6 +6,7 @@ end) local posseid local possename +local number RegisterServerEvent("bcc-posse:grabinfo") AddEventHandler("bcc-posse:grabinfo", function(id, radius) @@ -45,9 +46,6 @@ AddEventHandler("bcc-posse:checkposse", function(targetid, id) if result[1].posseid == id then id = result[1].posseid TriggerClientEvent('bcc-posse:possefound', _source) - TriggerClientEvent("vorp:NotifyLeft", _source, 'Posse Invite', 'You are in the same posse', - 'inventory_items', - 'folder_invitations', 5000) end end) end) @@ -100,23 +98,24 @@ AddEventHandler("bcc-posse:beeninvitedsv", function(targetid) { ["@targetid"] = tarid }, function(result) posseid = result[1].posseid - end) exports.ghmattimysql:execute("SELECT * FROM `posse` WHERE characterid = @characterid", { ["@characterid"] = charid }, function(result) possename = result[1].possename number = result[1].id + Wait(100) + if posseid == 0 then + TriggerClientEvent('bcc-posse:sendposseinvites', targetid, number, possename, true) + TriggerClientEvent("vorp:NotifyLeft", targetid, 'Posse Invite', 'You have been invited to a posse', + 'inventory_items', + 'folder_invitations', 5000) + else + TriggerClientEvent("vorp:TipBottom", targetid, "already in posse", 3000) + end end) - Wait(100) - if posseid == 0 then - TriggerClientEvent('bcc-posse:sendposseinvites', targetid, number, possename, true) - TriggerClientEvent("vorp:NotifyLeft", targetid, 'Posse Invite', 'You have been invited to a posse', - 'inventory_items', - 'folder_invitations', 5000) - else - TriggerClientEvent("vorp:TipBottom", targetid, "already in posse", 3000) - end + end) + end) RegisterServerEvent("bcc-posse:acceptinvite") @@ -173,12 +172,16 @@ AddEventHandler("bcc-posse:createposse", function(possename) end) RegisterServerEvent("bcc-posse:posselist") -AddEventHandler("bcc-posse:posselist", function(posseid) - +AddEventHandler("bcc-posse:posselist", function(possenumber) + print(possenumber) local _source = source - exports.ghmattimysql:execute("SELECT firstname, lastname, charidentifier FROM characters WHERE posseid = @posseid", - { ["posseid"] = posseid }, - function(result) - TriggerClientEvent('bcc-posse:ViewMembersMenu', _source, result) - end) + + if possenumber > 0 then + exports.ghmattimysql:execute( + "SELECT firstname, lastname, charidentifier FROM characters WHERE posseid = @posseid", + { ["posseid"] = possenumber }, + function(result) + TriggerClientEvent('bcc-posse:ViewMembersMenu', _source, result) + end) + end end)