Jump to content

Applying Spawn Classes to ALC Groups


damien111

Recommended Posts

Restricting ALC Groups and Classes together is what i want. For invite only groups. But i cant figure it out. Heres my server side code which is all i edited.

  
g_root = getRootElement( ); 
classGroups = { }; 
  
  
addEvent( "spawn_clientRequestSpawn", true ); 
addEventHandler( "spawn_clientRequestSpawn", g_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]] 
            if skin.modelId == 29 and not isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(client)), aclGetGroup ( "SoS" ) ) then spawn = false 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 
    end 
); 
  
addEventHandler( "onPlayerSpawn", g_root, 
    function ( ) 
     
    end 
); 
  
addEventHandler( "onPlayerWasted", g_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", getResourceRootElement(), 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", g_root, function() deleteAllPlayerBlips(source) end ); 
  
  
------------------------------------------------------------------------------------------ 
------------------------------------------------------------------------------------------ 
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 
) 

and the line i added is after line 18. its

if skin.modelId == 29 and not isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(client)), aclGetGroup ( "SoS" ) ) then spawn = false end 

Im new to scripting but i know other langauges. Thanks in advance! :mrgreen:

Link to comment

Ok, let's try debugging and see what it outputs:

g_root = getRootElement( ); 
classGroups = { }; 
  
  
addEvent( "spawn_clientRequestSpawn", true ); 
addEventHandler( "spawn_clientRequestSpawn", g_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]] 
            outputChatBox ( "model id: ".. skin.modelId ) 
            outputChatBox ( "in acl: ".. tostring ( isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(client)), aclGetGroup ( "SoS" ) ) ) ) 
            if skin.modelId == 29 and not isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(client)), aclGetGroup ( "SoS" ) ) then spawn = false 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 
    end 
); 
  
addEventHandler( "onPlayerSpawn", g_root, 
    function ( ) 
    
    end 
); 
  
addEventHandler( "onPlayerWasted", g_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", getResourceRootElement(), 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", g_root, function() deleteAllPlayerBlips(source) end ); 
  
  
------------------------------------------------------------------------------------------ 
------------------------------------------------------------------------------------------ 
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 
) 

Use that and post here what it outputs to chat box.

Link to comment

I found your problem, the value of: skin.modelId is a string, not a number, so the result is "29", not 29.

if ( skin.modelId == "29" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "SoS" ) ) ) then 
    spawn = false 
end 

With that it'll work, tested.

Link to comment
  • MTA Team

Also, just saying. Models are integers. When you try to compare a string with an integer, it will return an error. Then again when you try to output a message, which tells you your location, you don't need to separately mark them as floats/integers in general, because the message will always return a string, so adding tostring() or tonumber() won't affect anything.

What you have there is the first thing I told you, which is trying to compare a string with an integer. So as solidsnake already advised you to do, is to add the string (quotation marks). It's logical and interesting afterall.

Good luck!

Edited by Guest
Link to comment

I added all that i needed. it worked with 1 but when i added more it didnt here is my code.

  
g_root = getRootElement( ); 
classGroups = { }; 
  
  
addEvent( "spawn_clientRequestSpawn", true ); 
addEventHandler( "spawn_clientRequestSpawn", g_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]] 
            if ( skin.modelId == "165" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "SPECIALUNITS" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "286" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "SPECIALUNITS" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "285" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "SWAT" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "287" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "MF" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "312" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "MF" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "294" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "SPECIALFORCES" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "153" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "STAFF" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "211" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "STAFF" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "30" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "CLO" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "122" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "NINJA" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "29" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "SoA" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "115" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "SoA" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "165" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "MIB" ) ) ) then 
            spawn = false 
            if ( skin.modelId == "164" and not isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( client ) ), aclGetGroup ( "MIB" ) ) ) then 
            spawn = false 
    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 
    end 
); 
  
addEventHandler( "onPlayerSpawn", g_root, 
    function ( ) 
     
    end 
); 
  
addEventHandler( "onPlayerWasted", g_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", getResourceRootElement(), 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", g_root, function() deleteAllPlayerBlips(source) end ); 
  
  
------------------------------------------------------------------------------------------ 
------------------------------------------------------------------------------------------ 
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 
) 
 

Also , how can i make it so it detects when someone cant spawn as the class and then displays a message box. or panel or something.

ps- Thanks myonlake! :D

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