Author Topic: I have a small question regarding a "local" chat, aka, limited range chat.  (Read 691 times)

I'm developing a server, I will call it Force of Nature. Basically, as a requirement for it I need a chat where players are limited as where it's possible to speak. I am aware that add-ons like this already exist, at least I think, but I want to make my own for a learning process. I am new to TorqueScript, so please don't be a huge starfish.

Here's what I have so far:

function servercmdlc(%client, %Chat1, %Chat2);
{


    {
        isObject(%client);
        %client.name = var //I want to make players able to type in a nickname to be heard as, I am unaware of how to do so.
        var = clientSendMessage //Is this even a real command?
    }

        {


        }
};

In which ways should I clean up my script, and how would I go about making this certain form of communication in game? Thanks!

Well, for starters, no one will use /lc. I can garantee you that. Do you know how to package? If so, package
serverCmdMessageSent(%client,%msg)
Go step by step. Once you can manage to echo in the console messageSent and not send the chat to the rest of the clients, work on checking for nearby players.

function servercmdlc(%client, %Chat1, %Chat2);
{


    {
        isObject(%client);
        %client.name = var //I want to make players able to type in a nickname to be heard as, I am unaware of how to do so.
        var = clientSendMessage //Is this even a real command?
    }

        {


        }

};


Bolded are things that are unnecessary (Just the 4 braces inside the function), italicized things will not work as you probably intended them to, and underlined lines are lines that will give you a syntax error.

The first and last lines should not have a ; at the end of it, that's only at the end of a statement. %client.name = var will give you a syntax error because you forgot to put a ; at the end of it. The next line... I just don't even know what you're trying to do here.

isObject(%client); will serve no purpose for 2 reasons:
1. It just calls the function and doesn't do anything with the result
2. %client will always exist assuming it's a player typing in the command.

I can try to point you in the right direction, but you have a long ways to go it seems.

1. You need to first, have spam protection at the beginning so this is where you would compare strings using %string1 $= %string2.
2. You also need a lot more arguments, each word a player types will be an argument. (%chat1,%chat2,%chat3, etc).
3. Then check if %client has an object (%client.player).
4. After that, you'd probably loop through the client group (clientgroup.getCount(); and clientGroup.getObject(index);), grab each player (if it exists) and using the vectorDist(transform1,transform2) function check if player a's position is near player b's position.
5. After this, you can can send a message to the player's client object and voila.


Check this out, it's not done and needs improvement (like flood protection, stripping ML characters, etc) but will give you a base to get started with. I also want you to finish the the vectorDist part of it where it actually sends the message.

I did not test this, so if anyone can spot any errors, let me know.

Also, check out this guide: TSForBlockland
« Last Edit: March 29, 2015, 09:41:38 PM by elm »