1. Hi guys,

    On my adventure into the world of developing a RPG System that would look likes the one promissed by the devs from WarZ, I stuck in the quest of creating a function that lets the players talk only to their group/party.

    Pls, give me some advice of a good code to use or analyse mine if possible and thell me what I may change to make it work.

    Code:
    function PLUGIN:GroupChat( player, cmd, args )
        local pID = rust.UserIDFromPlayer( player )
        local pGroup = LESData.PlayerData[pID].Group -- Catch the player's group name
        if not pGroup or (pGroup == "") then
            self:ChatMessage( player, "You have no group!" )
            return
        end
        local gMsg = args[0] -- With this method, the player must use at least one double quote mark after the command to identify the message that way (i.e. /gc "my message here). I couldn't think in any way of receive all the args in the message without the quotes and then send it to the chat.
        local playerList = self:GetAllPlayers() -- GetAllPlayers function catchs the baseplayer ids from all online players.
        for k,pIDs in pairs(playerList) do
            local gPID = rust.UserIDFromPlayer(pIDs) -- Convert the baseplayer ids to the SteamID (duuh)
            local gCatch = LESData.PlayerData[gPID].Group -- I though that with this I would catch the group name of each online player, but it seems not to work, since the console throws me an exception (attempt to index field '?' (a nil value))
            if pGroup == gCatch then -- Suposed to compare the Talking Player group name with the groups from all online active players
                self:ChatMessage( gPID, player.displayName..": "..gMsg ) -- Suposed to send the chat message from the player issuing the command to all the group members.
            end
        end
    end
    
    [DOUBLEPOST=1420429838][/DOUBLEPOST]Ok... I guess I figured out what can be happening about the "field '?'"...

    The plugin needs to create a basic data file for the player as soon as it connects for the first time... I was ussing "OnPlayerConnect"... with "OnPlayerInit" the basic player data is being created as intended so no ? fields will be found anywhere :)

    The only issues that remains, is the fact that I couldn't make the player send the group chat message without using the quotes at the start of the message... :(
     
    Last edited by a moderator: Jan 5, 2015
  2. To get all args from a chat command and build a string from it you can try something like this
    Code:
    local i = 0
    local msg = ""
    while args[i] do
        msg = msg.." "..args[i]
        i = i + 1
    end
    Havent tested it so no guarantee it works.
     
  3. I tried something like that at the firsts days of my adventure, but maybe I had messed with something that broke the code... now that its cleaner I will try that again :)

    Tnx Domestos!
     
  4. you can see exemples on some of my plugins:
    Code:
    msg = ""
    for i=1, args.Length-1 do
      msg = msg .. args[i] .. " "
    end
    
     
  5. I was reading all the plugins that I use in the moment and couldn't find a good option to put it in to use...
    Yours works if I change i=1 to i=0.

    Code:
    msg = ""
    for i=1, args.Length-1 do
      msg = msg .. args[i] .. " "
    end
    Tnx as ever Reneb and Domestos ;)