Author Topic: Need help with chat functions  (Read 1156 times)

Code: [Select]
package Chat
{
    function serverCmdMessageSent(%client,%msg)
    {
        if(%client.chat == 0)
        {
            %position = %client.player.position;
            InitContainerRadiusSearch(%position,30,$TypeMasks::PlayerObjectType);
            while((%targetObject=containerSearchNext()) !$= 0)
            {
                %c = %targetObject.client;
                messageClient(%c,'',"\c7[Local]:\c3" SPC %client.name @ "\c6:" SPC %msg);
            }
        }
        
        else if(%client.chat == 1)
        {
            messageAll('',"\c2[OOC]:\c3" SPC %client.name @ "\c6:" SPC %msg);
        }
        
        %client.chat = 0;
    }        
};

function serverCmdOOC(%client,%msg)
{
    %client.chat = 1;
}

Now how would I finish the server command OOC? So it changed %client.chat to 1 and also use whatever I put after /ooc. So something like /ooc test test test would output [OOC] client.name: test test test?

-code snip-

Now how would I finish the server command OOC? So it changed %client.chat to 1 and also use whatever I put after /ooc. So something like /ooc test test test would output [OOC] client.name: test test test?


You might be over brown townyzing it, but I'm pretty sure its just as simple as calling the serverCmdMessageSent function in your serverCmdOOC function
Code: [Select]
function serverCmdOOC(%client,%msg)
{
    %client.chat = 1;
serverCmdMessageSent(%client,%msg);
}

That still only sends the first word of a message. I know I could make it so I set %client.chat = 1 then just type a message and it would work. But I want to be able to do a whole message with /ooc on 1 line.

Ooh, I see what you're saying. Well, you're gonna have a problem doing it with serverCmds considering all the parameters are made to be delineated with a space.
You'd have to do:
Code: [Select]
serverCmdOOC(%client,%a, %b, %c, %d, %e, %f, %g, %h, %i)
{
%client.chat = 1;
%words = "abcdefghi"; %msg = "";
for(%i = 0; %i<strLen(%str); %i++)
eval("%msg = %msg SPC %"@getSubStr(%words,%i,1)@";");
serverCmdMessageSent(%client,%msg);
}
I'm to lazy to add more arguments, but this is a hacky/not fun way to do it. ( I just showed you this for example purposes)

I'd personally package the serverCmdMessageSent function to look for the first four characters being /ooc so that you could use the rest of the string as your message (and you wouldnt have to deal with the whole serverCmd parameter thing. Better yet, use some sort of delimeter like ! or \ to make typing in OOC faster and more user friendly. It would basically do a check like any eval addon anyone has ever made but instead of running the rest of the message as a script, it would put it in chat for everyone to see. You wouldn't even need to set a %client.chat variable.
« Last Edit: March 17, 2013, 10:42:48 PM by DYLANzzz »

Why not use the ServerCmdTeamMessageSent function?

I'd personally package the serverCmdMessageSent function to look for the first four characters being /ooc

That's not how the chat system works.

Why not use the ServerCmdTeamMessageSent function?


How would that work exactly? I'm still really new to doing this so I'm sorry if that's a dumb question.

How would that work exactly? I'm still really new to doing this so I'm sorry if that's a dumb question.

Try using the search feature.

The MessageSent is working fine, I'm having problems with doing %client.chat = 1 and running message sent at the same time. Are you saying to do the OOC with TeamMessageSent?

 It works fine if I do /ooc for %client.chat = 1 then go and type after I enter that. I want to have %client.chat = 1 then do my message after the command on the same line.

I'm getting the problem where only one string out of all of them shows up. The local chat works fine though.

You can do something like this:

Code: [Select]
function serverCmdOOC(%client,%a,%b,%c,%d,%e,%f,%g,%h,%i,%j,%k,%l,%m,%n,%o,%p,%q,%r,%s,%t,%u,%v,%w,%x,%y,%z)
{
%client.chat = true;
%argList = "abcdefghijklmnopqrstuvwxyz";
%length = strLen(%argList);

for(%int=0;%int<%length;%int++)
{
eval("%currWord = %" @ getSubStr(%argList,%int,1) @ ";");
%message = %message SPC %currWord;
}

if(%message !$= "")
{
%message = trim(%message);
serverCmdMessageSent(%client,%message);
}
}

 I've done all of this in Script_RPChat.
 search it in the add-ons, I think I even commented the code.

That's not how the chat system works.
Yeah, I understand that but why mess with stringing a bunch of parameters together from a server command when you can just look for some sort of token at the start of the chat message string so you can just use the rest of the message?

Yeah, I understand that but why mess with stringing a bunch of parameters together from a server command when you can just look for some sort of token at the start of the chat message string so you can just use the rest of the message?

Mainly because a message starting with /ooc wouldn't even be sent to the server. You could use a different prefix though.

Mainly because a message starting with /ooc wouldn't even be sent to the server. You could use a different prefix though.

So do something like the old City RP and RPChat using ^ and make it so it finds the ^whatever and runs the right type of chat like RPChat? So it's impossible to do this with a server command without having multiple variables for the message?

So it's impossible to do this with a server command without having multiple variables for the message?

Yes.

Yes.


So I could make it so the chat function looks to see if the message starts with ^ChatType then it would run the type of chat that I want? I know that's how Lugnut's RPChat did it, but wasn't sure if it was the only way.

Code: [Select]
package Chat
{
    function serverCmdMessageSent(%client,%msg)
    {
        %firstWord = strupr(getWord(%msg, 0));
        %firstChar = getSubStr(%msg,0,1);
        if(%firstChar $= "^")
        {
            %msg = removeWord(%msg, 0);
            if(%firstWord $= "^OOC")
            {   
                messageAll('',"\c2[OOC]\c7" SPC %client.clanprefix @ "\c3" @ %client.name @ "\c7" @ %client.clansuffix @ "\c6:" SPC %msg);
                return;
            }
            messageClient(%client,'',"You did not enter a valid type of chat!");
            return;
        }
       
       
        %position = %client.player.position;
        InitContainerRadiusSearch(%position,30,$TypeMasks::PlayerObjectType);
        while((%targetObject=containerSearchNext()) !$= 0)
        {
            %c = %targetObject.client;
            messageClient(%c,'',"\c1[Local] \c7" SPC %client.clanprefix @ "\c3" @ %client.name @ "\c7" @ %client.clansuffix @ "\c6:" SPC %msg);
        }
               
    }
};
ActivatePackage(Chat);


This is the best way to go about doing this, right?
« Last Edit: March 19, 2013, 08:32:00 AM by devildogelite »