Professional Documents
Culture Documents
Factions Lua
Factions Lua
local factionMembers = {}
local memberDuty = {}
for i, v in pairs(factions) do
exports.oxmysql:query("SELECT id,username,userFaction,last_login
FROM users WHERE faction = @faction",{['@faction'] = tostring(i)}, function(result)
factionMembers[tostring(i)] = result
end)
Citizen.Wait(30)
end
end)
end
--[[
Weapons Packs
1: Silver Pack
2: Gold Pack
3: Platinum Pack
]]
local fWeaponPacks = {
{
-- Pistoale --
{id = "body_vintagepistol", name = "Vintage Pistol", price = 10000},
},
{
-- Pistoale --
{id = "body_vintagepistol", name = "Vintage Pistol", price = 10000},
{id = "body_minismg", name = "Mini SMG", price = 30000},
-- Rifles --
{id = "body_gusenberg", name = "Gusenberg", price = 30000},
-- Diverse --
{id = "body_molotov", name = "Molotov", price = 2000},
{id = "body_molotov", name = "Munitie Molotov", price = 600},
},
{
-- Pistoale --
{id = "body_vintagepistol", name = "Vintage Pistol", price = 10000},
{id = "body_doubleaction", name = "Double Action", price = 30000},
{id = "body_navyrevolver", name = "Navy Revolver", price = 250000},
{id = "body_gadgetpistol", name = "Gadget Pistol", price = 1000000},
{id = "body_minismg", name = "Mini SMG", price = 30000},
-- Rifles--
{id = "body_gusenberg", name = "Gusenberg", price = 30000},
{id = "body_mg", name = "Machine Gun", price = 40000},
{id = "body_combatmg", name = "Combat MG", price = 55000},
-- Diverse --
{id = "body_stickybomb", name = "Sticky Bomb", price = 75000},
{id = "ammo_stickybomb", name = "Munitie Sticky Bomb", price = 50000},
{id = "body_molotov", name = "Molotov", price = 2000},
{id = "ammo_molotov", name = "Munitie Molotov", price = 600},
},
}
local fHealPack = {
{id = "body_armor", name = "Vesta Anti-Glont", price = 5000},
{id = "medkit", name = "Trusa Medicala", price = 10000},
{id = "adrenalina", name = "Injectie Adrenalina", price = 3000},
{id = "bandajmic", name = "Bandaj Mic", price = 100},
{id = "bandajmare", name = "Bandaj Mare", price = 200},
}
AddEventHandler("onDatabaseConnect", function(db)
Citizen.Wait(500)
getFactionsConfig()
end)
RegisterCommand("loadfactions", function(player)
local granted = false
if (player ~= 0) and vRP.isUserAdministrator(vRP.getUserId(player)) then
granted = true
end
vRPclient.denyAcces(player, {})
end)
ExecuteCommand("loadfactions");
function vRP.getFactionByColor(color)
for i, v in pairs(factions) do
if v.fColor == color then
return tostring(i)
end
end
return false
end
function vRP.getFactions()
local factionsList = {}
for i, v in pairs(factions) do
factionsList[i] = v
end
return factionsList
end
function vRP.getUserFaction(user_id)
local tmp = vRP.getUserTmpTable(user_id)
if tmp then
return tmp.fName
end
end
function vRP.getFactionRanks(faction)
local ngroup = factions[faction]
if ngroup then
return ngroup.fRanks
end
end
function vRP.getFactionSlots(faction)
local ngroup = factions[faction]
if ngroup then
local factionSlots = ngroup.fSlots
return factionSlots
end
end
function vRP.getFactionColor(faction)
local ngroup = factions[faction]
if ngroup then
local factionColor = ngroup.fColor
return factionColor
end
end
function vRP.getFactionType(faction)
local ngroup = factions[faction]
if ngroup then
return tostring(ngroup.fType)
end
end
function vRP.getFactionBlip(faction)
local ngroup = factions[faction]
if ngroup then
return tostring(ngroup.fBlip)
end
end
function vRP.getFactionBudget(faction)
local factionObj = factions[faction] or {budget = 0}
if factionObj.budget then
return factionObj.budget
end
return 0
end
function vRP.hasUserFaction(user_id)
local tmp = vRP.getUserTmpTable(user_id)
if tmp then
if tmp.fName == "user" then
return false
else
return true
end
end
return false
end
function vRP.isUserInFaction(user_id,group)
local tmp = vRP.getUserTmpTable(user_id)
if tmp then
if tmp.fName == group then
return true
else
return false
end
end
end
function vRP.isUserFactionDuty(user_id)
return memberDuty[user_id] == nil
end
function tvRP.isUserFactionDuty()
return vRP.isUserFactionDuty(vRP.getUserId(source))
end
function vRP.isUserPolitist(user_id)
return vRP.isUserInFaction(user_id, "Politia Romana")
end
function vRP.isUserMedic(user_id)
return vRP.isUserInFaction(user_id, "Smurd")
end
function vRP.getFactionOffice(faction)
local ngroup = factions[faction]
if ngroup then
return ngroup.fOffice
end
end
function vRP.getFactionHome(faction)
local ngroup = factions[faction]
if ngroup then
local factionHome = ngroup.fHome
return factionHome[1], factionHome[2], factionHome[3]
end
end
function vRP.spawnAtFactionHome(user_id)
local player = vRP.getUserSource(user_id)
if player then
local x, y, z = vRP.getFactionHome(vRP.getUserFaction(user_id))
vRPclient.teleport(player, {x, y, z})
vRPclient.setHealth(player, {200})
end
end
function vRP.setFactionLeader(user_id,theFaction,leaderRank)
local tmp = vRP.getUserTmpTable(user_id)
if tmp then
local userFaction = vRP.getUserFaction(user_id)
local factionRanks = vRP.getFactionRanks(userFaction)
local newRank = factionRanks[#factionRanks].rank
if leaderRank == 1 then
newRank = factionRanks[#factionRanks-1].rank
end
tmp.fRank = newRank
tmp.fLeader = leaderRank;
function vRP.isFactionLeader(user_id)
local faction = vRP.getUserFaction(user_id)
local tmp = vRP.getUserTmpTable(user_id)
if faction then
if tmp.fLeader == 2 then
return true
end
end
return false
end
function vRP.getFactionRank(user_id)
local tmp = vRP.getUserTmpTable(user_id)
if tmp then
return tmp.fRank
end
end
vRP.getUserFactionRank = vRP.getFactionRank
function vRP.isFactionCoLeader(user_id)
local faction = vRP.getUserFaction(user_id)
local tmp = vRP.getUserTmpTable(user_id)
if faction then
if tmp.fLeader == 1 then return true end
end
return false
end
function vRP.setFactionRank(user_id, rank, theFaction)
if vRP.getUserSource(user_id) then
local tmp = vRP.getUserTmpTable(user_id)
tmp.fRank = rank
local groupUsers = factionMembers[theFaction]
if groupUsers then
for i, v in pairs(groupUsers) do
if v.id == user_id then
v.userFaction.rank = rank
end
end
end
exports.oxmysql:execute("UPDATE users SET rank = @rank, leader =
@leader WHERE id = @id",{
['@id'] = user_id,
['@rank'] = rank
})
else
local groupUsers = factionMembers[theFaction]
if groupUsers then
for i, v in pairs(groupUsers) do
if v.id == user_id then
v.userFaction.rank = rank
end
end
end
exports.oxmysql:execute("UPDATE users SET rank = @rank, leader =
@leader WHERE id = @id",{
['@id'] = user_id,
['@rank'] = rank
})
end
end
function vRP.addUserFaction(user_id,theGroup)
local player = vRP.getUserSource(user_id)
if (player) then
local ngroup = factions[theGroup]
if ngroup then
local factionRank = ngroup.fRanks[1].rank
local tmp = vRP.getUserTmpTable(user_id)
if tmp then
tmp.fName = theGroup
tmp.fRank = factionRank
function vRP.getUsersByFaction(group)
return factionMembers[group] or {}
end
function vRP.getOnlineUsersByFaction(group)
local oUsers = {}
return oUsers
end
tmp.fName = "user"
tmp.fRank = 'none'
end
if vRP.hasUserFaction(user_id) then
local theFaction = vRP.getUserFaction(user_id) or "Civil"
local rank = vRP.getFactionRank(user_id) or "Unknown"
local leader = vRP.isFactionLeader(user_id) or false
local coLeader = vRP.isFactionCoLeader(user_id) or false
local members = vRP.getUsersByFaction(theFaction) or 0
local fType = vRP.getFactionType(theFaction) or "Civil"
local fSlots = vRP.getFactionSlots(theFaction) or 0
menu.css={top="75px",header_color="rgba(200,0,0,0.75)"}
membersMenu[v.username] =
{function(player, choice)
local usr_id =
vRP.getUserId(player)
local controlMember = {name =
"", css = {
top="75px",
header_color="rgba(0,
125, 255, 0.75"}
}
if
target then
local name = GetPlayerName(target)
vRP.closeMenu(target)
vRP.removeUserFaction(userID, theFaction)
vRP.removeUserFaction(userID, theFaction)
controlMember["🔰 SCHIMBA
RANK"] = {function()
local actualRank =
vRP.getFactionRank(userID)
local ranks =
factions[theFaction].fRanks
local rankMenu =
{name = "", css = {
top="75px",
for k, v in
pairs(ranks) do
local rank =
v.rank
rankMenu[rank] = {function(player)
vRP.openMenu(player, rankMenu)
end}
end
vRP.openMenu(player,
controlMember)
end}
end
end
vRP.openMenu(player, membersMenu)
end}
local ranks =
vRP.getFactionRanks(theFaction) or {}
table.sort(ranks, function(a, b)
return a.rank:upper() <
b.rank:upper()
end)
for i, v in pairs(ranks) do
local facRank = v.rank
local salary = tonumber(v.payday)
ranksMenu[facRank.." 💸
"..vRP.formatMoney(salary)] = {function() end}
end
vRP.openMenu(player,ranksMenu)
end}
end
vRP.openMenu(player,menu)
end)
end}
end
add(choices)
end
end)
RegisterServerEvent("vRP:openFactionChest", function(x)
local user_id = vRP.getUserId(source)
if vRP.hasUserFaction(user_id) then
local theFaction = vRP.getUserFaction(user_id)
local factionType = vRP.getFactionType(theFaction)
RegisterServerEvent("vRP:openFactionStore", function(storeType)
local user_id = vRP.getUserId(source)
local theFaction = vRP.getUserFaction(user_id) or "user"
Citizen.CreateThread(function()
TriggerClientEvent("discord:setUserData", source, user_id,
(rows[1].faction ~= "user" and rows[1].faction or nil))
end)
AddEventHandler("vRP:playerLeave", function(user_id)
memberDuty[user_id] = nil
end)
if factions[group] then
local members = vRP.getUsersByFaction(group)
local fSlots = factions[group].fSlots
if theTarget then
local name = GetPlayerName(theTarget)
if(lider == 2) then
vRP.addUserFaction(id,group)
Citizen.Wait(500)
vRP.setFactionLeader(id,group,2)
vRPclient.notify(player,{"Jucatorul
"..name.." a fost adaugat ca lider in factiunea "..group})
elseif(lider == 1) then
vRP.addUserFaction(id,group)
Citizen.Wait(500)
vRP.setFactionLeader(id,group,1)
vRPclient.notify(player,{"Jucatorul
"..name.." a fost adaugat ca si colider in factiunea "..group})
vRP.closeMenu(target)
vRP.removeUserFaction(target_id,target_faction)
if(theFaction == "user")then
vRPclient.notify(player,{"Jucatorul nu este in nici o
factiune!", "error"})
else
vRP.setFactionLeader(id,theFaction,2)
vRPclient.notify(player,{name.." a fost adaugat ca lider in
factiunea "..theFaction})
if(theFaction == "user")then
vRPclient.notify(player,{"Jucatorul nu este in nici o
factiune!", "error"})
else
vRP.setFactionLeader(id,theFaction,1)
vRPclient.notify(player,{name.." a fost adaugat ca si co-
lider in factiunea "..theFaction})
local chestCoords = {}
for coord in string.gmatch(factionChest or "0,0,0","[^,]+") do
table.insert(chestCoords,tonumber(coord))
end
local cx,cy,cz = 0,0,0
if chestCoords[1] then
cx = chestCoords[1]
end
if chestCoords[2] then
cy = chestCoords[2]
end
if chestCoords[3] then
cz = chestCoords[3]
end
local newFaction = {
name = numeFactiune,
type = "Mafie",
slots = slots,
color = color,
blip = 310,
ranks = {
[1] = {
rank = "Membru",
payday = 0,
},
[2] = {
rank = "Co-Lider",
payday = 0,
},
[3] = {
rank = "Lider",
payday = 0,
},
},
home = {
[1] = x,
[2] = y,
[3] = z,
},
office = {
healPack = false,
chestPos = {
[1] = cx,
[2] = cy,
[3] = cz,
},
healPos = {
[1] = 0,
[2] = 0,
[3] = 0,
},
weaponPack = weaponPack,
}
}
exports.oxmysql:execute("INSERT INTO factions
(name,type,slots,color,ranks,home,office, blip)
VALUES(@name,@type,@slots,@color,@ranks,@home,@office, @blip)",{
['@name'] = newFaction.name,
['@type'] = newFaction.type,
['@slots'] = newFaction.slots,
['@color'] = newFaction.color,
['@ranks'] = json.encode(newFaction.ranks),
['@home'] = json.encode(newFaction.home),
['@office'] = json.encode(newFaction.office),
['@blip'] = json.encode(newFaction.blip)
})
vRPclient.notify(player,{"Factiunea a fost creata cu succes!",
"info"})
else
local coords = {}
for coord in string.gmatch(fcoords or "0,0,0","[^,]+") do
table.insert(coords,tonumber(coord))
end
local x,y,z = 0,0,0
if coords[1] then
x = coords[1]
end
if coords[2] then
y = coords[2]
end
if coords[3] then
z = coords[3]
end
local chestCoords = {}
for coord in string.gmatch(factionChest or "0,0,0","[^,]+") do
table.insert(chestCoords,tonumber(coord))
end
local cx,cy,cz = 0,0,0
if chestCoords[1] then
cx = chestCoords[1]
end
if chestCoords[2] then
cy = chestCoords[2]
end
if chestCoords[3] then
cz = chestCoords[3]
end
local healCoords = {}
for coord in string.gmatch(fhealthCoords or "0,0,0","[^,]+") do
table.insert(healCoords,tonumber(coord))
end
local hx,hy,hz = 0,0,0
if healCoords[1] then
hx = healCoords[1]
end
if healCoords[2] then
hy = healCoords[2]
end
if healCoords[3] then
hz = healCoords[3]
end
local newFaction = {
name = numeFactiune,
type = "Mafie",
slots = slots,
color = color,
ranks = {
[1] = {
rank = "Membru",
payday = 0,
},
[2] = {
rank = "Co-Lider",
payday = 0,
},
[3] = {
rank = "Lider",
payday = 0,
},
},
home = {
[1] = x,
[2] = y,
[3] = z,
},
office = {
healPack = true,
chestPos = {
[1] = cx,
[2] = cy,
[3] = cz,
},
healPos = {
[1] = hx,
[2] = hy,
[3] = hz,
},
weaponPack = weaponPack,
}
}
exports.oxmysql:execute("INSERT INTO factions
(name,type,slots,color,ranks,home,office, blip)
VALUES(@name,@type,@slots,@color,@ranks,@home,@office,@blip)",{
['@name'] = newFaction.name,
['@type'] = newFaction.type,
['@slots'] = newFaction.slots,
['@color'] = newFaction.color,
['@ranks'] = json.encode(newFaction.ranks),
['@home'] = json.encode(newFaction.home),
['@office'] = json.encode(newFaction.office),
['@blip'] = json.encode(newFaction.blip)
})
vRPclient.notify(player,{"Factiunea a fost creata cu succes!",
"info"})
end
SetTimeout(1000, function()
ExecuteCommand('loadFactions')
end)
end)
end
if vRP.isUserAdministrator(user_id) then
choices["🪖 FACTION MANAGEMENT"] = {function(player)
local fManagementMenu = {name = "", css = {top="75px",
header_color="rgba(0,125,255,0.75)"}}
add(choices)
end
end)
if src then
if src ~= exceptSrc and not memberDuty[memberId] then
fnct(src)
end
end
end
end
vRP.executaPentruFactiune = vRP.doFactionFunction
vRP.executaPentruFType = vRP.doFactionTypeFunction