Jump to content

Applying Spawn Classes to ALC Groups


damien111

Recommended Posts

Edited your code a bit smaller, not sure if it'll work or anything, but give it a try. No need to make a bunch of lines when you can instead just make one table.

Try this first, and if it gives an error, try the other one.

local classGroups = {} 
local spawning = { 
    [1] = {"165, 286", "SPECIALUNITS"}, 
    [2] = {"285", "SWAT"}, 
    [3] = {"287, 312", "MF"}, 
    [4] = {"294", "SPECIALFORCES"}, 
    [5] = {"153, 211", "STAFF"}, 
    [6] = {"30", "CLO"}, 
    [7] = {"122", "NINJA"}, 
    [8] = {"29, 115", "SoA"}, 
    [9] = {"165, 164", "MIB"} 
} 
  
addEvent("spawn_clientRequestSpawn", true) 
addEventHandler("spawn_clientRequestSpawn", root, 
    function(categoryIndex, classIndex, skinIndex) 
        if skinIndex then 
            local class = classGroups[categoryIndex].classes[classIndex] 
            local skin = class.skinMngr.skins[skinIndex] 
            local spawn = true 
            local spawned 
             
            --[[if not classGroups[cetegoryIndex].owner then -- if there is NO owner of the clan/gang spawn player 
                spawn = true 
            else -- if there IS owner of the clan/gang then check if he's member of the clan/gang 
                
            end]] 
             
            for i,v in ipairs(spawning) do 
                if (skin.modelId == (string.find(spawning[i][1], ", ") and spawning[i][1]:gsub(", ", " or ") or spawning[i][1])) and (not isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(client)), aclGetGroup (spawning[i][2])))) then 
                    spawn = false 
                else 
                    spawn = true 
                    break 
                end 
            end 
        end 
        if spawn then 
            if not class.team then 
                class.team = createTeam(class.name, class.color.red, class.color.green, class.color.blue) 
            end 
             
            local plrTeam = getPlayerTeam(client) 
            if ((plrTeam) and (plrTeam ~= class.team) and (countPlayersInTeam(plrTeam) == 1)) then 
                destroyElement(plrTeam) 
            end 
                
            spawned = spawnPlayer( 
                client, 
                skin.spawnLoc.x, 
                skin.spawnLoc.y, 
                skin.spawnLoc.z, 
                skin.spawnLoc.rot, 
                skin.modelId, 
                0, 0, 
                class.team 
            ) 
        end 
         
        if spawned then 
            setElementData(client, "team", class.name) 
            fadeCamera(client, true) 
            setCameraTarget(client, client) 
            setTimer(setCameraTarget, 200, 1, client, client) 
            triggerClientEvent(client, "spawn_SpawnedSuccessfully", client) 
            --setPlayerMoney(client, 500) 
            for _, weapon in ipairs(class.weaponMngr.weapons) do 
                giveWeapon(client, weapon.id, weapon.ammo, false) 
            end 
            createBlipAttachedTo(client, 0, 2, class.color.red, class.color.green, class.color.blue) 
        else 
            triggerClientEvent(client, "spawn_FailedToSpawn", client) 
            if countPlayersInTeam(class.team) == 0 then 
                destroyElement(class.team) 
                class.team = nil; 
            end 
        end 
    end 
) 
  
addEventHandler("onPlayerSpawn", root, 
    function() 
         
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        fadeCamera(source, false, 4) 
        setTimer(requestMenu, 5000, 1, source) 
        deleteAllPlayerBlips(source) 
    end 
) 
  
function requestMenu(player) 
    callClientFunc(player, "showSpawnMenu", true, true) 
    callClientFunc(player, "classSelected") 
end 
  
addCommandHandler("kill", 
    function(plr) 
        killPed(plr) 
    end 
) 
  
function preloadClassesInfo() 
    local groups = getElementsByType("category") 
    for _, group in ipairs(groups) do 
        table.insert(classGroups, Group:New(group)) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, preloadClassesInfo) 
  
function deleteAllPlayerBlips(player) 
    local elements = getAttachedElements(player) 
    if (elements) then 
        for i, element in ipairs(elements) do 
            if (getElementType(element) == "blip") then 
                destroyElement(element) 
            end 
        end 
    end 
    print("number of players in team: " .. tostring(countPlayersInTeam(getPlayerTeam(player))) 
end 
addEventHandler("onPlayerQuit", root, deleteAllPlayerBlips) 
  
function callClientFunc(player, funcName, ...) 
    if #{...} ~= 0 then 
        triggerClientEvent(player, "_clientCallFunction", root, funcName, ...) 
    else 
        triggerClientEvent(player, "_clientCallFunction", root, funcName) 
    end 
end 
  
addEvent("_serverCallFunction", true) 
addEventHandler("_serverCallFunction", root, 
    function(funcName, ...) 
        _G[funcName](...) 
    end 
) 

local classGroups = {} 
local spawning = { 
    [1] = {"165, 286", "SPECIALUNITS"}, 
    [2] = {"285, 285", "SWAT"}, 
    [3] = {"287, 312", "MF"}, 
    [4] = {"294, 294", "SPECIALFORCES"}, 
    [5] = {"153, 211", "STAFF"}, 
    [6] = {"30, 30", "CLO"}, 
    [7] = {"122, 122", "NINJA"}, 
    [8] = {"29, 115", "SoA"}, 
    [9] = {"165, 164", "MIB"} 
} 
  
addEvent("spawn_clientRequestSpawn", true) 
addEventHandler("spawn_clientRequestSpawn", root, 
    function(categoryIndex, classIndex, skinIndex) 
        if skinIndex then 
            local class = classGroups[categoryIndex].classes[classIndex] 
            local skin = class.skinMngr.skins[skinIndex] 
            local spawn = true 
            local spawned 
             
            --[[if not classGroups[cetegoryIndex].owner then -- if there is NO owner of the clan/gang spawn player 
                spawn = true 
            else -- if there IS owner of the clan/gang then check if he's member of the clan/gang 
                
            end]] 
             
            for i,v in ipairs(spawning) do 
                if (skin.modelId == spawning[i][1]:gsub(", ", " or ")) and (not isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(client)), aclGetGroup (spawning[i][2])))) then 
                    spawn = false 
                else 
                    spawn = true 
                    break 
                end 
            end 
        end 
        if spawn then 
            if not class.team then 
                class.team = createTeam(class.name, class.color.red, class.color.green, class.color.blue) 
            end 
             
            local plrTeam = getPlayerTeam(client) 
            if ((plrTeam) and (plrTeam ~= class.team) and (countPlayersInTeam(plrTeam) == 1)) then 
                destroyElement(plrTeam) 
            end 
                
            spawned = spawnPlayer( 
                client, 
                skin.spawnLoc.x, 
                skin.spawnLoc.y, 
                skin.spawnLoc.z, 
                skin.spawnLoc.rot, 
                skin.modelId, 
                0, 0, 
                class.team 
            ) 
        end 
         
        if spawned then 
            setElementData(client, "team", class.name) 
            fadeCamera(client, true) 
            setCameraTarget(client, client) 
            setTimer(setCameraTarget, 200, 1, client, client) 
            triggerClientEvent(client, "spawn_SpawnedSuccessfully", client) 
            --setPlayerMoney(client, 500) 
            for _, weapon in ipairs(class.weaponMngr.weapons) do 
                giveWeapon(client, weapon.id, weapon.ammo, false) 
            end 
            createBlipAttachedTo(client, 0, 2, class.color.red, class.color.green, class.color.blue) 
        else 
            triggerClientEvent(client, "spawn_FailedToSpawn", client) 
            if countPlayersInTeam(class.team) == 0 then 
                destroyElement(class.team) 
                class.team = nil; 
            end 
        end 
    end 
) 
  
addEventHandler("onPlayerSpawn", root, 
    function() 
         
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        fadeCamera(source, false, 4) 
        setTimer(requestMenu, 5000, 1, source) 
        deleteAllPlayerBlips(source) 
    end 
) 
  
function requestMenu(player) 
    callClientFunc(player, "showSpawnMenu", true, true) 
    callClientFunc(player, "classSelected") 
end 
  
addCommandHandler("kill", 
    function(plr) 
        killPed(plr) 
    end 
) 
  
function preloadClassesInfo() 
    local groups = getElementsByType("category") 
    for _, group in ipairs(groups) do 
        table.insert(classGroups, Group:New(group)) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, preloadClassesInfo) 
  
function deleteAllPlayerBlips(player) 
    local elements = getAttachedElements(player) 
    if (elements) then 
        for i, element in ipairs(elements) do 
            if (getElementType(element) == "blip") then 
                destroyElement(element) 
            end 
        end 
    end 
    print("number of players in team: " .. tostring(countPlayersInTeam(getPlayerTeam(player))) 
end 
addEventHandler("onPlayerQuit", root, deleteAllPlayerBlips) 
  
function callClientFunc(player, funcName, ...) 
    if #{...} ~= 0 then 
        triggerClientEvent(player, "_clientCallFunction", root, funcName, ...) 
    else 
        triggerClientEvent(player, "_clientCallFunction", root, funcName) 
    end 
end 
  
addEvent("_serverCallFunction", true) 
addEventHandler("_serverCallFunction", root, 
    function(funcName, ...) 
        _G[funcName](...) 
    end 
) 

Link to comment

@myonlake, why create new table of skins if it's already in the xml file and in classGroups table or local class table in spawn request function?

@damien111, why adding ACL support if password protection is good enough for clans. Nobody will know the password except for the clan members and server owner. If you can't trust your clan member then why have such member?

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...