Player's chat in virtual world
#1

Hi.
How can i make virtualworld-chat?
That, if player is in world 0, can tell with players in world 0 and if he is in 1, can tell with there's players and see messages from he's world only. How?
Reply
#2

when a player send a message loop through all players (recommending foreach for this) and check if the player is in the same virtualworld, if he is then send him a client message with the text he wrote, if he is not, then don't do anything


P.S. don't forget to return 0; at the end so only your custom message will be sent.
Reply
#3

Use GetPlayerVirtualWorld and make a for-loop.
Like:
pawn Code:
stock SendVirtualMessage(virtualworld, color, string[])
{
    new i=0;
    for(i<GetMaxPlayers();i++)
    {
        if(IsPlayerConnected(i))
        {
            // You can do this, if u want:
            //if(IsLoggedIn[i] == 1) or what ever.
            if(GetPlayerVirtualWorld(i) == virtualworld)
            {
                SendClientMessage(i, color, string);
            }
        }
    }
    return 1;
}
That's it.
Reply
#4

thanks!
Reply
#5

I can't use that.
This
Code:
	new string[128];
	format(string, sizeof(string), "%s: %s", GetPlayerName(playerid), text);
	new worldid = GetPlayerVirtualWorld(playerid);
	SendVirtualMessage(worldid, 0x000000FF, string);
Reply
#6

Quote:
Originally Posted by 'Pawno.
View Post
Use GetPlayerVirtualWorld and make a for-loop.
Like:
pawn Code:
stock SendVirtualMessage(virtualworld, color, string[])
{
    new i=0;
    for(i<GetMaxPlayers();i++)
    {
        if(IsPlayerConnected(i))
        {
            // You can do this, if u want:
            //if(IsLoggedIn[i] == 1) or what ever.
            if(GetPlayerVirtualWorld(i) == virtualworld)
            {
                SendClientMessage(i, color, string);
            }
        }
    }
    return 1;
}
That's it.
the array creation should be in the for()
pawn Code:
SendVirtualMessage(virtualworld, color, string[]) {
    for(new i=0;i<GetMaxPlayers();i++) {
        if(IsPlayerConnected(i)) {
            if(GetPlayerVirtualWorld(i) == virtualworld) {
                SendClientMessage(i, color, string);
            }
        }
    }
}
Reply
#7

You can, but the GetPlayerName isn't the right way.
pawn Code:
new pName[24];
GetPlayerName(playerid, pName, sizeof (pName));
and then use pName instead of GetPlayerName(playerid);
Reply
#8

Try something like:

pawn Code:
public OnPlayerText(playerid, text[])
{
// You put the virtual world you want to send the message; in this case the virtual world is "1"; you can use other virtual world.
if(GetPlayerVirtualWorld(playerid) == 1)
{
new String[128];
GetPlayerName(playerid, String, sizeof(String));
format(String, sizeof(String), "%s [%d]: {FFFFFF}%s", String, playerid, text);
Message(String);
return 0;
}
// Here you put other functions.
return 0;
}
Then create this public:

pawn Code:
forward Message(const string[]);
public Message(const string[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) == 1) if(GetPlayerVirtualWorld(i) == 1) SendClientMessage(i, GetPlayerColor(i), string);
// We put the same virtual world for the player who is in the same virtual world. In this case is "1"; you can use other virtual world.
}
return 1;
}
Good luck
Reply
#9

pawn Code:
public OnPlayerText(playerid, text[])
{
    new var = GetPlayerVirtualWorld(playerid), fstr[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(fstr, sizeof(fstr), "%s(%d): %s", name, playerid, text);
    for(new i = 0; i < MAX_PLAYERS; i++) //Foreach is a recommended alternative
    {
        if(!IsPlayerConnected(i)) continue;
        if(GetPlayerVirtualWorld(i) != var) continue;
        SendClientMessage(playerid, -1, fstr);
    }
    return 0;
}
It's really quite simple.
Reply
#10

Good. Now i had in OnPlayerText:
Code:
if(loggedadminC == false) return 0;
from admin login system, if he is not login can't write.

Now, how i can do that in Threshold's code?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)