Jump to content

Problem with FairPlay Gaming


Jaber

Recommended Posts

Hi all :) , i have a problem with Fairplay Gaming ( Open source Roleplay GameMode thx Socialz ) my problem is i have a faction panel we can open it with presse F1 but for open the panel we need to restart res for every player join the server ...

Can you help me thx :)

The code :

ServerSide :

  
--[[
    - FairPlay Gaming: Roleplay
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program. If not, see .
 
    (c) Copyright 2014 FairPlay Gaming. All rights reserved.
]]
 
local factionTimer = {}
local factionTypes = {
    [1] = {"Law",           1000000},
    [2] = {"Medical",       1000000},
    [3] = {"Government",    1000000},
    [4] = {"News",          0},
    [5] = {"Gang",          0},
    [6] = {"Mafia",         0},
    [7] = {"Triad",         0},
    [8] = {"Other",         0}
}
 
function loadFactions()
    local query = dbQuery(exports['roleplay-accounts']:getSQLConnection(), "SELECT * FROM `??`", "factions")
    if (query) then
        local result, num_affected_rows, errmsg = dbPoll(query, -1)
        if (num_affected_rows > 0) then
            if (num_affected_rows == 1) then
                outputDebugString("1 faction loaded.")
            else
                outputDebugString(num_affected_rows .. " factions are about to be loaded.")
            end
 
            for result,row in pairs(result) do
                local faction = createTeam(row["name"])
                setElementData(faction, "roleplay:factions.id", row["id"], false)
                setElementData(faction, "roleplay:factions.type", row["type"], false)
                setElementData(faction, "roleplay:factions.name", row["name"], false)
                setElementData(faction, "roleplay:factions.description", row["description"], false)
                setElementData(faction, "roleplay:factions.motd", row["motd"], false)
                setElementData(faction, "roleplay:factions.ranks", row["ranks"], false)
                setElementData(faction, "roleplay:factions.wages", row["wages"], false)
                setElementData(faction, "roleplay:factions.cooldown", 0, false)
                setElementData(faction, "roleplay:factions.invites", row["inviteCount"], false)
                setElementData(faction, "roleplay:factions.bank", row["bankValue"], false)
 
                for _,player in ipairs(getElementsByType("player")) do
                    if (exports['roleplay-accounts']:getPlayerFaction(player)) then
                        if (exports['roleplay-accounts']:getPlayerFaction(player) == row["id"]) then
                            setPlayerTeam(player, faction)
                        end
                    end
                end
            end
        else
            outputDebugString("0 factions loaded. Does the factions table contain data and are the settings correct?")
        end
    end
end
 
function refreshFactionMenu(factionID)
    for i,v in ipairs(getElementsByType("player")) do
        if (exports['roleplay-accounts']:getPlayerFaction(v) == factionID) then
            if (getElementData(v, "roleplay:gui.isFactionMenu")) then
                triggerClientEvent(v, ":_closeFactionMenu_:", v)
                removeElementData(v, "roleplay:gui.isFactionMenu")
                showFactionMenu(v)
            end
        end
    end
end
 
local amountsUsed = {}
function showFactionMenu(player)
    if (not player) or (not isElement(player)) or (getElementType(player) ~= "player") then return end
    if (getElementData(player, "roleplay:gui.isFactionMenu")) then
        triggerClientEvent(player, ":_closeFactionMenu_:", player)
        removeElementData(player, "roleplay:gui.isFactionMenu")
    else
        if (not exports['roleplay-accounts']:isClientPlaying(player)) then return end
        local factionID = exports['roleplay-accounts']:getPlayerFaction(player)
        local faction = getFactionByID(factionID)
        if (not factionID) or (not faction) then
            outputChatBox("You're not in a faction.", player, 245, 20, 20, false)
            return
        end
 
        if (amountsUsed[player]) and (amountsUsed[player] >= 2) then
            outputChatBox("Please wait before using the faction menu again.", player, 245, 20, 20, false)
            return
        else
            amountsUsed[player] = (amountsUsed[player] and amountsUsed[player]+1 or 1)
        end
 
        local factionName = getFactionName(faction)
        local factionType = getFactionType(faction)
        local factionMOTD = getFactionMOTD(faction)
        local factionRanks = getFactionRanks(faction)
        local factionWages = getFactionWages(faction)
        local factionPlayers = {}
 
        local query = dbQuery(exports['roleplay-accounts']:getSQLConnection(), "SELECT `??`, `??`, `??`, `??`, DATEDIFF(NOW(), `??`) AS `??` FROM `??` WHERE `??` = '??' ORDER BY `??` DESC, `??` ASC", "id", "characterName", "factionRank", "factionPrivileges", "loginDate", "loginDate", "characters", "factionID", factionID, "factionRank", "characterName")
        if (not query) then
            outputChatBox("An error occured when tried to fetch faction members.", player, 245, 20, 20, false)
            return
        end
 
        local result, num_affected_rows = dbPoll(query, -1)
        if (not result) then
            outputChatBox("An error occured when tried to fetch faction members.", player, 245, 20, 20, false)
            return
        elseif (num_affected_rows == 0) then
            outputChatBox("You're not in a faction.", player, 245, 20, 20, false)
            return
        end
 
        for _,row in pairs(result) do
            table.insert(factionPlayers, {
                ["id"] = row["id"],
                ["name"] = row["characterName"],
                ["rank"] = row["factionRank"],
                ["privileges"] = row["factionPrivileges"],
                ["lastOnline"] = row["lastOnline"]
            })
        end
 
        setElementData(player, "roleplay:gui.isFactionMenu", 1, false)
        triggerClientEvent(player, ":_showFactionMenu_:", player, factionID, factionName, factionType, factionMOTD, factionRanks, factionWages, factionPlayers)
        setTimer(function(player) if (not isElement(player)) then amountsUsed[player] = nil else amountsUsed[player] = 0 end end, 3000, 1, player)
    end
end
 
addEvent(":_syncFactionChange_:", true)
addEventHandler(":_syncFactionChange_:", root,
    function(type, ...)
        local type = tonumber(type)
        if (source ~= client) or (not type) or (type <= 0) or (type > 6) then return end
        local factionID = exports['roleplay-accounts']:getPlayerFaction(client)
        local faction = getFactionByID(factionID)
        if (not factionID) or (not faction) or (not exports['roleplay-accounts']:getFactionPrivileges(client)) then
            outputChatBox("You're not in a faction.", client, 245, 20, 20, false)
            return
        end
 
        if (exports['roleplay-accounts']:getFactionPrivileges(client) <= 0) then
            outputChatBox("Your privileges are too low for that action.", client, 245, 20, 20, false)
            return
        end
 
        local args = {...}
 
        if (type == 1) then
            local newMotd = args[1]
            setElementData(faction, "roleplay:factions.motd", newMotd, false)
            dbExec(exports['roleplay-accounts']:getSQLConnection(), "UPDATE `??` SET `??` = '??' WHERE `??` = '??'", "factions", "motd", newMotd, "id", factionID)
 
            for i,v in ipairs(getPlayersInTeam(faction)) do
                if (exports['roleplay-accounts']:isClientPlaying(v)) then
                    outputChatBox(" [FactionAct] " .. getPlayerName(client):gsub("_", " ") .. " updated the Message of the Day.", v, 50, 210, 220, false)
                end
            end
        elseif (type == 2) then
            local newRanks = toJSON(args[1])
            local newWages = toJSON(args[2])
            setElementData(faction, "roleplay:factions.ranks", newRanks, false)
            setElementData(faction, "roleplay:factions.wages", newWages, false)
            dbExec(exports['roleplay-accounts']:getSQLConnection(), "UPDATE `??` SET `??` = '??', `??` = '??' WHERE `??` = '??'", "factions", "ranks", newRanks, "wages", newWages, "id", factionID)
 
            for i,v in ipairs(getPlayersInTeam(faction)) do
                if (exports['roleplay-accounts']:isClientPlaying(v)) then
                    outputChatBox(" [FactionAct] " .. getPlayerName(client):gsub("_", " ") .. " updated the ranks.", v, 50, 210, 220, false)
                end
            end
        elseif (type == 3) then
            local charName = args[1]:gsub(" ", "_")
            local newRank = args[2]
            local ranks = fromJSON(getFactionRanks(faction))
            dbExec(exports['roleplay-accounts']:getSQLConnection(), "UPDATE `??` SET `??` = '??' WHERE `??` = '??' AND `??` = '??'", "characters", "factionRank", newRank, "characterName", charName, "factionID", factionID)
 
            local player = getPlayerFromName(charName)
            if (player) then
                setElementData(player, "roleplay:characters.faction:rank", newRank, true)
            end
 
            for i,v in ipairs(getPlayersInTeam(faction)) do
                if (exports['roleplay-accounts']:isClientPlaying(v)) then
                    outputChatBox(" [FactionAct] " .. getPlayerName(client):gsub("_", " ") .. " set " .. exports['roleplay-accounts']:getRealPlayerName(charName) .. " rank to \"" .. ranks[newRank] .. "\".", v, 50, 210, 220, false)
                end
            end
        elseif (type == 4) then
            local charName = args[1]:gsub(" ", "_")
            local newRights = args[2]-1
            dbExec(exports['roleplay-accounts']:getSQLConnection(), "UPDATE `??` SET `??` = '??' WHERE `??` = '??' AND `??` = '??'", "characters", "factionPrivileges", newRights, "characterName", charName, "factionID", factionID)
 
            local player = getPlayerFromName(charName)
            if (player) then
                setElementData(player, "roleplay:characters.faction:privileges", newRights, true)
            end
 
            for i,v in ipairs(getPlayersInTeam(faction)) do
                if (exports['roleplay-accounts']:isClientPlaying(v)) then
                    outputChatBox(" [FactionAct] " .. getPlayerName(client):gsub("_", " ") .. " set " .. exports['roleplay-accounts']:getRealPlayerName(charName) .. " rights to \"" .. (newRights == 0 and "Member" or (newRights == 1 and "Leader" or "Owner")) .. "\".", v, 50, 210, 220, false)
                end
            end
        elseif (type == 5) then
            for _,vehicle in ipairs(getElementsByType("vehicle")) do
                if (exports['roleplay-vehicles']:getVehicleRealID(vehicle)) then
                    if (exports['roleplay-vehicles']:getVehicleFaction(vehicle)) and (exports['roleplay-vehicles']:getVehicleFaction(vehicle) == factionID) then
                        if (exports['roleplay-vehicles']:isVehicleEmpty(vehicle)) then
                            fixVehicle(vehicle)
                            setVehicleEngineState(vehicle, false)
                            setVehicleOverrideLights(vehicle, 1)
                            setElementFrozen(vehicle, true)
                            setVehicleLocked(vehicle, true)
                            setElementData(vehicle, "roleplay:vehicles.fuel", 100, true)
                            setElementData(vehicle, "roleplay:vehicles.fuel;", 100, true)
                            setElementData(vehicle, "roleplay:vehicles.engine", 0, true)
                            setElementData(vehicle, "roleplay:vehicles.winstate", 0, true)
                            setElementData(vehicle, "roleplay:vehicles.currentGear", 0, true)
                            setElementData(vehicle, "roleplay:vehicles.handbrake", 1, true)
                            respawnVehicle(vehicle)
                        end
                    end
                end
            end
 
            for i,v in ipairs(getPlayersInTeam(faction)) do
                if (exports['roleplay-accounts']:isClientPlaying(v)) then
                    outputChatBox(" [FactionAct] " .. getPlayerName(client):gsub("_", " ") .. " respawned all unoccupied vehicles.", v, 50, 210, 220, false)
                end
            end
        elseif (type == 6) then
            local vehicleID = args[1]
            local vehicle = exports['roleplay-vehicles']:getVehicle(vehicleID)
            if (vehicle) then
                if (exports['roleplay-vehicles']:getVehicleFaction(vehicle)) and (exports['roleplay-vehicles']:getVehicleFaction(vehicle) == factionID) then
                    fixVehicle(vehicle)
                    setVehicleEngineState(vehicle, false)
                    setVehicleOverrideLights(vehicle, 1)
                    setElementFrozen(vehicle, true)
                   
Link to comment

Try this(Idk if it works):

  
addEventHandler("onPlayerJoin", resourceRoot, 
    function() 
        loadFactions() 
        for i,v in ipairs(getElementsByType("player")) do 
        bindf1() 
        setTimer(bindf1, 3500, 1) 
        end 
    end 
) 
  

Link to comment
Try this(Idk if it works):
  
addEventHandler("onPlayerJoin", resourceRoot, 
    function() 
        loadFactions() 
        for i,v in ipairs(getElementsByType("player")) do 
        bindf1() 
        setTimer(bindf1, 3500, 1) 
        end 
    end 
) 
  

Why you looping players and you don't use the values at all

@Jaber, you want the gui to be showen on the player join the server?

Link to comment
  • Moderators
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        loadFactions() 
        for i,v in ipairs(getElementsByType("player")) do 
            bindf1(v) 
        end 
    end 
) 
function bindf1(v) 
    bindKey(v, "F1", "down", showFactionMenu) 
end 
  
addEventHandler("onPlayerJoin", resourceRoot, 
    function() 
        bindf1(source) 
    end 
) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...