Jump to content

New Chat


Recommended Posts

addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do -- Loop all the players.  
            bindKey ( player, "U", "down", "chatbox", "GangChat" ) -- Bind the key "U" to the "GangChat" command. 
        end 
    end 
) 
  
addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        bindKey ( source, "U", "down", "chatbox", "GangChat" ) -- Bind the key "U" to the "GangChat" command. 
    end 
) 
  
function gangChat ( thePlayer, _, ... ) 
    local text = table.concat ( { ... }, " " ) 
    if ( #text > 0 ) then 
        outputChatBox ( text, thePlayer ) 
    end 
end 
addCommandHandler ( "GangChat", gangChat ) 

Link to comment

Thanks working, but is there a way to lt only people who get invited can talk in gang chat?

like example /invite randomplayer then we are the only players who can talk in gang chat and other people can't see

I edited the code to keep showing player name

addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do -- Loop all the players. 
            bindKey ( player, "U", "down", "chatbox", "gangChat" ) -- Bind the key "U" to the "GangChat" command. 
        end 
    end 
) 
  
addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        bindKey ( source, "U", "down", "chatbox", "gangChat" ) -- Bind the key "U" to the "GangChat" command. 
    end 
) 
  
function gangChat ( thePlayer, _, ... ) 
    local text = table.concat ( { ... }, " " ) 
    if ( #text > 0 ) then 
        outputChatBox ("#FF32AA (GANG) "..getPlayerName(thePlayer)..": #FFFFFF" ..text, thePlayer, 255, 255, 255, true ) 
    end 
end 
addCommandHandler ( "gangChat", gangChat ) 

Link to comment

Lol no! Setelementdata, thats all.

For example.

addCommandHandler("invite", 
    function (player, cmd, name) 
        if not name then return end 
        setElementData(getPlayerFromName(name), "invited", true) 
    end 
) 

And then you are just checking

if (getElementData(player, "invited") then 

Link to comment
  • Moderators
Lol no! Setelementdata, thats all.

For example.

addCommandHandler("invite", 
    function (player, cmd, name) 
        if not name then return end 
        setElementData(getPlayerFromName(name), "invited", true) 
    end 
) 

And then you are just checking

if (getElementData(player, "invited") then 

Will only work for one group chat and you will have to invite the guys each time they reconnect.

I would use element datas to know in which group the guy is and persist the data in database (Mysql or account datas).

The invite command will check in which group the player who wrote the cmd is and then add the target player to that group.

Then the chat will display group messages between guys that are in the same group.

Link to comment

Well I wrote you how, but...

    addEventHandler ( "onResourceStart", resourceRoot, 
        function ( ) 
            for _, player in ipairs ( getElementsByType ( "player" ) ) do -- Loop all the players. 
                bindKey ( player, "U", "down", "chatbox", "gangChat" ) -- Bind the key "U" to the "GangChat" command. 
            end 
        end 
    ) 
      
    addEventHandler ( "onPlayerJoin", root, 
        function ( ) 
            bindKey ( source, "U", "down", "chatbox", "gangChat" ) -- Bind the key "U" to the "GangChat" command. 
        end 
    ) 
      
    function gangChat ( thePlayer, _, ... ) 
        local isInvited = getElementData ( thePlayer, "invited" ) or false 
        if ( isInvited ) then 
            local text = table.concat ( { ... }, " " ) 
            if ( #text > 0 ) then 
                outputChatBox ("#FF32AA (GANG) "..getPlayerName(thePlayer)..": #FFFFFF" ..text, thePlayer, 255, 255, 255, true ) 
            end 
        end 
    end 
    addCommandHandler ( "gangChat", gangChat ) 
     
    function invitePlayer ( thePlayer, _, playerName ) 
        if not playerName then return end 
        local playerToInvite = getPlayerFromName(playerName) 
         
        if ( isElement ( playerToInvite ) ) then 
            setElementData ( playerToInvite, "invited", true ) 
            outputChatBox ( "You have been invited to the chat.", playerToInvite) 
        else 
            outputChatBox ( "There is no such a player!", thePlayer ) 
        end 
    end 
    addCommandHandler ( "invite", invitePlayer ) 

Link to comment
  • Moderators
I have a problem, when i invite a player, i can't use gangChat but he can use them, i want to both can talk in the gang chat, like a pm chat box

A gang chat is not the same as PM because PM is between two players only (at least for me).

You have to do another command first to create the gang/group and then you will invite other players in it.

If you don't want to let anyone be able to create a gang/group (then definied by the script), you will have to create the group 1st and then you need to put AT LEAST one guy into it (usually the leader).

In your case, the player1 who is not in a gang/group is inviting player2 in a gang he doesn't own.

Link to comment
  • Moderators

You don't want to use other resources but you can't do it yourself either even after we told you the main idea and the functions you would have to use.

Learn to script simple stuff first. Check the Introduction to Scripting available on the wiki main page.

function createGang( thePlayer, cmd, gngName ) 
    if not thePlayer or not cmd then return end 
    if not gngName then  
        return outputChatBox("SYNTAX: /createGang ") 
    end 
  
    if getElementData(thePlayer, "gang") then 
        return outputChatBox("You are already in a gang. Do /leaveGang to leave it.", thePlayer) 
    end 
  
    if isGangAlreadyExist(gngName) then 
        return outputChatBox("The gang "..gngName.." already exist !", thePlayer) 
    end 
  
    local newGang = createElement("gang") 
    setElementData(newGang, "name", gngName) 
    setElementData(newGang, "leader", gngName) 
    setElementData(newGang, "members", {}) 
  
    outputChatBox("You successfully created the "..gngName.." gang and you are the leader !", thePlayer) 
end 
addCommandHandler("createGang", createGang, false, false) 
  
function inviteInGang( thePlayer, cmd, playerName ) 
    if not thePlayer or not cmd then return end 
    if not playerName then 
        return outputChatBox("SYNTAX: /invite ", thePlayer) 
    end 
  
    local gang = getElementData(thePlayer, "gang") 
    if not gang then 
        return outputChatBox("You must be part of a gang first. Do /createGang to create your own.", thePlayer) 
    end 
  
    local newMember = getPlayerFromName(playerName) 
    if not newMember then 
        return outputChatBox("Player "..playerName.." not found !", thePlayer) 
    end 
  
    if newMember == thePlayer then 
        return outputChatBox("You can't invite your self into a gang !", thePlayer) 
  
    if getElementData(newMember, "gang") then 
        return outputChatBox("The player "..playerName.." is already in a gang. Ask him to leave first.", thePlayer) 
    end 
  
    if addNewMemberToGang(gang, newMember) then 
        local gangName = getElementData(gang, "name") or "" 
        outputChatBox("Congrats ! You are now part of the "..tostring(gangName).." gang !", newMember) 
        outputChatBox(playerName.." is now a member of your gang !", thePlayer) 
    else 
        outputChatBox("An error has occured. Please contact an administrator.", thePlayer) 
    end 
end 
addCommandHandler("invite", inviteInGang, false, false) 
  
function leaveGang( thePlayer ) 
    if not thePlayer then return end 
    local gang = getElementData(thePlayer, "gang") 
    if not gang then 
        return outputChatBox("You already aren't in a gang !", thePlayer) 
    end 
  
    if removeMemberFromGang( gang, thePlayer ) then 
        local gangName = getElementData(gang, "name") or "" 
        local leader = getElementData(gang, "leader") 
        outputChatBox("You successfully left the "..tostring(gangName).." gang !", thePlayer) 
        if leader and isElement(leader) then 
            outputChatBox(playerName.." left your gang !", leader) 
        end 
    else 
        outputChatBox("An error has occured. Please contact an administrator.", thePlayer) 
    end 
end 
addCommandHandler("leaveGang", leaveGang, false, false) 
  
function addNewMemberToGang( theGang, thePlayer ) 
    if not theGang or not thePlayer then return end 
    local members = getElementData(theGang, "members") 
    table.insert(members, thePlayer) 
    return (setElementData(newMember, "gang", theGang) and  
        setElementData(theGang "members", members)) 
end 
  
function removeMemberFromGang( theGang, thePlayer ) 
    if not theGang or nor thePlayer then return end 
    local tmp = getElementData(theGang, "members") or {} 
    local members = {} 
    for k, member in ipairs(members) do 
        if member ~= thePlayer then table.insert(members, member) end 
    end 
    return (removeElementData(thePlayer, "gang") and 
        setElementData(theGang, "members", members)) 
end 
  
function isGangAlreadyExist( gngName ) 
    for k, theGang in ipairs (getElementsByType("gang")) do 
        local name = getElementData(theGang, "name") or "" 
        if name == gngName then return true end 
    end 
    return false 
end 
  
function gangChat ( thePlayer, _, ... ) 
    local text = table.concat ( { ... }, " " ) 
    local theGang = getElementData(thePlayer, "gang") 
    if #text == 0 or not theGang then return end 
    local members = getElementData(theGang, "members") or {} 
    local playerName = getPlayerName(thePlayer) 
    for k, member in ipairs (members) do 
        outputChatBox ("#FF32AA (GANG) "..playerName..": #FFFFFF"..text, member, 255, 255, 255, true ) 
    end 
end 
addCommandHandler ( "gangChat", gangChat ) 
addCommandHandler ( "gc", gangChat ) 

This script may have bugs since I didn't test it.

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