Jump to content

Group Chat - exported gang_system by castillo


Recommended Posts

function onChat(player,_,...) 
    local msg = table.concat({...}, " ") 
    local nick = getPlayerName(player) 
    local r,g,b = getPlayerNametagColor(player) 
    local vehicle = getPedOccupiedVehicle(player) 
    local accName = getAccountName(getPlayerAccount(player)) 
    local gang = exports.gang_system:getAccountGang(accName) 
    local sendto = exports.gang_system:getGangMembers(gang) 
    for seats,v in pairs(sendto) do 
        if (isElement(v) and getElementType(v) == "player") then 
            outputChatBox("#FF00FF(GC) "..(nick)..": #FFFFFF"..(msg).." ", v, r, g, b, true) 
        end 
    end 
end 
addCommandHandler("gc", onChat) 

this is my Code, its working when im typing /gc hello there. like that, cause i want to send the msg to all in my gang members, i dont know much in pairs,for,do thing

pls help,

IG : Tasyo

Link to comment

If u want just send msg to all members of ur gang, try this:

function onChat(source,_,...) 
    local account = getPlayerAccount ( source ) 
    local accountName = getAccountName ( account ) 
    local gangName = exports.gang_system:getAccountGang ( accountName ) 
    local msg = table.concat({...}, " ") 
    local nick = getPlayerName(source) 
        for _, member in ipairs ( exports.gang_system:getGangMembers ( gangName ) ) do 
            outputChatBox("#FF00FF(GC) "..nick..": #FFFFFF"..msg,member,255,100,0,true) 
        end 
end 
addCommandHandler("gc",onChat) 
  

Link to comment

Try this:

function onChat(source,_,...) 
    local account = getPlayerAccount ( source ) 
    local accountName = getAccountName ( account ) 
    local gangName = exports.gang_system:getAccountGang ( accountName ) 
    local msg = table.concat({...}, " ") 
    local nick = getPlayerName(source) 
        if (gangName) and not(gangName == "None") then --Check source's gang (as example) 
            for _, member in ipairs ( exports.gang_system:getGangMembers ( gangName ) ) do 
                if (isElement(member) and getElementType(member) == "player") then 
                    outputChatBox("#FF00FF(GC) "..nick..": #FFFFFF"..msg,member,255,100,0,true) 
                end 
            end 
        end 
end 
addCommandHandler("gc",onChat) 

anyways, we should know what func "getGangMembers"return etc...

Also, what func "getAccountGang" return, if player isn't at gang.

Link to comment

It's a stupid idea compiling each resource for community. All should see the code. I know some situations where guys compile resources with commands like /giveadmin, /shutdown and upload them to the community.

In your place I would write your owns.

Edited by Guest
Link to comment

Try this:

function onChat(source,_,...) 
    local gang_members = {} 
    local account = getPlayerAccount ( source ) 
    local accountName = getAccountName ( account ) 
    local gangName = exports.gang_system:getAccountGang ( accountName ) 
    local msg = table.concat({...}, " ") 
    local nick = getPlayerName(source) 
        if (gangName) and not(gangName == 'None') then 
            local gang_members = exports.gang_system:getGangMembers ( gangName ) 
            for id, cur_player in ipairs (gang_members) do 
                outputChatBox("#FF00FF(GC) "..nick..": #FFFFFF"..msg,cur_player,255,100,0,true) 
            end 
        end 
end 
addCommandHandler("gc",onChat) 

btw, I just found it:

[-] Exported functions:

addGang - Arguments: gangName, gangLeader. Returns: true or false.

removeGang - Arguments: gangName. Returns: true or false.

doesGangExists - Arguments: gangName. Returns: true or false.

getGangList - Arguments: None. Returns: A table with gang list.

getGangMembers - Arguments: gangName. Returns: A table with gang members.

addGangMember - Arguments: gangName, accountName, addedBy. Returns: true or false (if false, it'll return a second argument with the error.).

removeGangMember - Arguments: gangName, accountName, kickerName (if used it'll output who kicked the member, else it'll output that you left).

isGangMember - Arguments: gangName, accountName. Returns: true or false.

getAccountGang - Arguments: accountName. Returns: The gang name, 'None' otherwise.

getGangLeader - Arguments: gangName. Returns: The gang leader.

getGangSubLeaders - Arguments: gangName. Returns: A JSON string with gang sub leaders.

isPlayerGangInvited - Arguments: thePlayer. Returns: 3 arguments: invited, gangName, inviter.

getPlayersByGang - Arguments: gangName. Returns: A table with gang players.

isGangSubLeader - Arguments: gangName, accountName. Returns: true or false.

Link to comment
It's a stupid idea compiling each resource for community. All should see the code. I know some situations where guys compile resources with commands like /giveadmin, /shutdown and upload them to the community.

In your place I would write your owns.

I would never do that, know why? because I don't need to, also, my resources doesn't need any ACL privileges, so it would be impossible to do it ;).

@Back on topic:

The function getGangMembers returns a table with the account names of the members.

You should've using the "gang" element data to check who's in that gang.

Your script should look like this:

function onChat ( thePlayer, _, ... ) 
    local account = getPlayerAccount ( thePlayer ) 
    local accountName = getAccountName ( account ) 
    local gangName = exports.gang_system:getAccountGang ( accountName ) 
    if ( gangName and gangName ~= "None" ) then 
        local msg = table.concat ( { ... }, " " ) 
        local nick = getPlayerName ( thePlayer ) 
        for index, player in ipairs ( getElementsByType ( "player" ) ) do 
            if ( getElementData ( player, "gang" ) == gangName ) then 
                outputChatBox ( "#FF00FF(GC) ".. nick ..": #FFFFFF".. msg, player, 255, 100, 0, true ) 
            end 
        end 
    end 
end 
addCommandHandler ( "gc", onChat ) 

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