Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
update player Identifier for multi character server
Browse files Browse the repository at this point in the history
  • Loading branch information
yeganehha committed Mar 9, 2021
1 parent 2e47bee commit bd28f24
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 195 deletions.
8 changes: 8 additions & 0 deletions BaseFunction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ function GetRealPlayerName(playerId)
-- Like: return Player.GetName()
end

function getPlayerIdentifier(playerId)
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
return v
break
end
-- return identifier of player
end

function GetOOCPlayerName(playerId)
return GetPlayerName(playerId)
end
Expand Down
11 changes: 11 additions & 0 deletions QBusFunction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Citizen.CreateThread(function()
end
end)

function getPlayerIdentifier(playerId)
local Player = ESX.Functions.GetPlayer(playerId)
if Player and Player.PlayerData then
return Player.PlayerData.citizenid
else
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
return v
break
end
end
end

function GetRealPlayerName(playerId)
local Player = ESX.Functions.GetPlayer(playerId)
Expand Down
11 changes: 11 additions & 0 deletions esxBaseFunction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Citizen.CreateThread(function()
end
end)

function getPlayerIdentifier(playerId)
local xPlayer = ESX.GetPlayerFromId(playerId)
if xPlayer then
return xPlayer.identifier
else
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
return v
break
end
end
end

function GetRealPlayerName(playerId)
local xPlayer = ESX.GetPlayerFromId(playerId)
Expand Down
8 changes: 1 addition & 7 deletions server/admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,7 @@ RegisterServerEvent('Erfan:gang:addPlayerToGang')
AddEventHandler('Erfan:gang:addPlayerToGang', function(gangId , playerId , gradeId)
local _Source = source
if IsPlayerAceAllowed(_Source, "gang.admin") then
local identifier = nil
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(playerId)
if identifier ~= nil then
executeOnDB("DELETE FROM `gangs_member` WHERE `playerIdentifiers` = @playerIdentifiers", {
['@playerIdentifiers'] = identifier
Expand Down
141 changes: 19 additions & 122 deletions server/gangData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ RegisterServerEvent('Erfan:gang:getActiveGang')
AddEventHandler('Erfan:gang:getActiveGang', function()
local _Source = source
local gangs = selectFromDB("SELECT * , DATE_FORMAT(expireTime, '%Y/%m/%d') as expireTimeFormat FROM gangs where expireTime > NOW()", {})

for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier then
TriggerClientEvent('Erfan:gang:setGangData',_Source,gangs , gang[1].gangId , gang[1].grade )
Expand Down Expand Up @@ -53,12 +47,7 @@ end)
RegisterCommand("sethook", function(src, args, rawCommand)
if rawCommand:sub(9) then
local _Source = src
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].grade == 0 then
executeOnDB('UPDATE `gangs` SET `discordHook` = @discordHook WHERE id = @gangId', {
Expand All @@ -80,12 +69,7 @@ RegisterServerEvent('Erfan:gang:depositMoney')
AddEventHandler('Erfan:gang:depositMoney', function(amount)
local _Source = source
amount = tonumber(amount)
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].grade == 0 then
local setMoney = setPlayerMoney(_Source,amount,'remove')
Expand Down Expand Up @@ -115,12 +99,7 @@ RegisterServerEvent('Erfan:gang:withdrawMoney')
AddEventHandler('Erfan:gang:withdrawMoney', function(amount)
local _Source = source
amount = tonumber(amount)
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].grade == 0 then
local gangData = selectFromDB("SELECT * FROM gangs WHERE id = @id", { ['@id'] = gang[1].gangId })
Expand Down Expand Up @@ -156,12 +135,7 @@ end)
RegisterServerEvent('Erfan:gang:getRanksOfmyGang')
AddEventHandler('Erfan:gang:getRanksOfmyGang', function()
local _Source = source
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].grade == 0 then
local grades = selectFromDB("SELECT * FROM gangs_grade WHERE gangId = @gangId", { ['@gangId'] = gang[1].gangId })
Expand All @@ -177,12 +151,7 @@ RegisterServerEvent('Erfan:gang:creatNewGrade')
AddEventHandler('Erfan:gang:creatNewGrade', function(name)
local _Source = source
amount = tonumber(amount)
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].grade == 0 then
local maxGrade = selectFromDB("SELECT MAX(grade) + 1 as garde FROM `gangs_grade` WHERE `gangId` = @gangId", { ['@gangId'] = gang[1].gangId })
Expand Down Expand Up @@ -210,12 +179,7 @@ RegisterServerEvent('Erfan:gang:updateGradeData')
AddEventHandler('Erfan:gang:updateGradeData', function(gradeId , variabel , value)
local _Source = source
amount = tonumber(amount)
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].grade == 0 then
executeOnDB('UPDATE `gangs_grade` set `'..variabel..'` = @value where gradeId = @gradeId and `gangId` = @gangId', {
Expand All @@ -236,12 +200,7 @@ end)
RegisterServerEvent('Erfan:gang:getMembersOfmyGang')
AddEventHandler('Erfan:gang:getMembersOfmyGang', function()
local _Source = source
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].grade == 0 then
local members = selectFromDB("SELECT * FROM gangs_member WHERE gangId = @gangId", { ['@gangId'] = gang[1].gangId })
Expand All @@ -258,27 +217,12 @@ end)

RegisterServerEvent('Erfan:gang:addNewMember')
AddEventHandler('Erfan:gang:addNewMember', function(gradeId , playerId)
print(gradeId)
print(playerId)
local _Source = source
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].grade == 0 then
local identifier = nil
print(gradeId)
print(playerId)
print(GetPlayerIdentifiers(playerId))
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
identifier = getPlayerIdentifier(playerId)
if identifier ~= nil then
executeOnDB("DELETE FROM `gangs_member` WHERE `playerIdentifiers` = @playerIdentifiers", {
['@playerIdentifiers'] = identifier
Expand Down Expand Up @@ -311,12 +255,7 @@ end)
RegisterServerEvent('Erfan:gang:changeGradeMemberFromGang')
AddEventHandler('Erfan:gang:changeGradeMemberFromGang', function( playerId , gradeId)
local _Source = source
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].grade == 0 then
executeOnDB("UPDATE `gangs_member` set `grade` = @grade where playerIdentifiers = @playerIdentifiers and gangId = @gangId ", {
Expand All @@ -326,13 +265,7 @@ AddEventHandler('Erfan:gang:changeGradeMemberFromGang', function( playerId , gra
} , function(e)
if activeGangMember['g_'..gang[1].gangId] then
for _key1,gangMemberSRC in ipairs(activeGangMember['g_'..gang[1].gangId]) do
local identifierCheck = nil
for _key2,identi in ipairs(GetPlayerIdentifiers(gangMemberSRC)) do
if string.match(identi, Config.IdentifiersPlayerWith ) then
identifierCheck = identi
break
end
end
local identifierCheck = getPlayerIdentifier(gangMemberSRC)
if identifierCheck == playerId then
playerId = gangMemberSRC
break
Expand All @@ -351,12 +284,7 @@ end)
RegisterServerEvent('Erfan:gang:deleteMemberFromGang')
AddEventHandler('Erfan:gang:deleteMemberFromGang', function(playerId)
local _Source = source
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].grade == 0 then
local identifier = playerId
Expand All @@ -365,13 +293,7 @@ AddEventHandler('Erfan:gang:deleteMemberFromGang', function(playerId)
} , function(e)
if activeGangMember['g_'..gang[1].gangId] then
for _key1,gangMemberSRC in ipairs(activeGangMember['g_'..gang[1].gangId]) do
local identifierCheck = nil
for _key2,identi in ipairs(GetPlayerIdentifiers(gangMemberSRC)) do
if string.match(identi, Config.IdentifiersPlayerWith ) then
identifierCheck = identi
break
end
end
local identifierCheck = getPlayerIdentifier(gangMemberSRC)
if identifierCheck == identifier then
table.remove( activeGangMember['g_'..gang[1].gangId] , _key1 )
playerId = gangMemberSRC
Expand All @@ -394,12 +316,7 @@ end)
RegisterServerEvent('Erfan:gang:wearGang')
AddEventHandler('Erfan:gang:wearGang', function()
local _Source = source
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT * FROM gangs_member WHERE playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier then
local grade = selectFromDB("SELECT * FROM gangs_grade WHERE gangId = @gangId and grade = @grade ", { ['@gangId'] = gang[1].gangId , ['@grade'] = gang[1].grade })
Expand All @@ -416,12 +333,7 @@ end)
RegisterServerEvent('Erfan:gang:armory_deposit')
AddEventHandler('Erfan:gang:armory_deposit', function()
local _Source = source
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT gm.playerIdentifiers , gg.accessArmory FROM gangs_member gm Left Join gangs_grade gg on (gg.gangId = gm.gangId and gg.grade = gm.grade ) WHERE gm.playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].accessArmory then
TriggerClientEvent('Erfan:gang:armory_deposit_open',_Source, OpenPlayerInventory(_Source) )
Expand All @@ -433,12 +345,7 @@ end)
RegisterServerEvent('Erfan:gang:armory_withdraw')
AddEventHandler('Erfan:gang:armory_withdraw', function()
local _Source = source
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT gm.playerIdentifiers , gg.accessArmory , g.inventory FROM gangs_member gm Left Join gangs_grade gg on (gg.gangId = gm.gangId and gg.grade = gm.grade ) Left Join gangs g on (g.id = gm.gangId ) WHERE gm.playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].accessArmory then
TriggerClientEvent('Erfan:gang:armory_withdraw_open',_Source, json.decode(gang[1].inventory) )
Expand All @@ -450,12 +357,7 @@ end)
RegisterServerEvent('Erfan:gang:armory_depositing')
AddEventHandler('Erfan:gang:armory_depositing', function(item , amount)
local _Source = source
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT gm.playerIdentifiers , gg.accessArmory , gm.gangId, g.inventory, g.discordHook FROM gangs_member gm Left Join gangs_grade gg on (gg.gangId = gm.gangId and gg.grade = gm.grade ) Left Join gangs g on (g.id = gm.gangId ) WHERE gm.playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].accessArmory then
local IsItemGet = PlayerInventoryGetItem(_Source, item.itemType, item.value, amount)
Expand Down Expand Up @@ -495,12 +397,7 @@ end)
RegisterServerEvent('Erfan:gang:armory_withdrawing')
AddEventHandler('Erfan:gang:armory_withdrawing', function(item , amount)
local _Source = source
for k,v in ipairs(GetPlayerIdentifiers(_Source)) do
if string.match(v, Config.IdentifiersPlayerWith ) then
identifier = v
break
end
end
local identifier = getPlayerIdentifier(_Source)
local gang = selectFromDB("SELECT gm.playerIdentifiers , gg.accessArmory , gm.gangId, g.inventory, g.discordHook FROM gangs_member gm Left Join gangs_grade gg on (gg.gangId = gm.gangId and gg.grade = gm.grade ) Left Join gangs g on (g.id = gm.gangId ) WHERE gm.playerIdentifiers = @playerIdentifiers", { ['@playerIdentifiers'] = identifier })
if gang ~= nil and gang[1] ~= nil and gang[1].playerIdentifiers == identifier and gang[1].accessArmory then
local gangInventory = json.decode(gang[1].inventory)
Expand Down
Loading

0 comments on commit bd28f24

Please sign in to comment.