Underscores
#1

Hello, I got a problem, I'm not very good at scripting and still learning but.. How do I fix this? When I remove underscores it works for playerid, but with giveplayerid it bugs, sends messages to the wrong players etc or wrong names

Код:
stock RemoveUnderScore(playerid)
{
 new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid,name,sizeof(name));
	for(new i = 0; i < MAX_PLAYER_NAME; i++)
{
	if(name[i] == '_') name[i] = ' ';
}
	return name;
}

stock RPN(giveplayerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(giveplayerid,name,sizeof(name));
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if(name[i] == '_') name[i] = ' ';
    }
    return name;
}
That's what I got to remove underscores.

Example of a command;

Код:
	if(strcmp(cmd, "/freeze", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_WHITE, "USAGE: /freeze [playerid/PartOfName]");
				return 1;
			}
			new playa;
			playa = ReturnUser(tmp);
			if(PlayerInfo[playerid][pAdmin] >= 2)
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
				        GetPlayerName(playa, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
						TogglePlayerControllable(playa, 0);
						PlayerFrozen[playerid] = 1;
						format(string, sizeof(string), "{FF0000}Server action{FF0000}: You have been frozen by an Admin %s.",RemoveUnderScore(playerid));
						SendClientMessage(giveplayerid, COLOR_RED, string);
						format(string, sizeof(string), "{FF0000}Server action{FF0000}: You have frozen %s.", RPN(giveplayerid));
						SendClientMessage(playerid, COLOR_RED, string);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GRAD1, "   You are not authorized to use that command !");
			}
		}
		return 1;
	}
The message supposed to go at the reciever gets sent to me, and it gives my name on all..
Reply
#2

Why do you even have two functions that do exactly the same?
Reply
#3

Because i'm new to scripting, and because it didn't work with giveplayerid so I tried something :P..
Reply
#4

If it works for playerid, but not for giveplayerid, don't you think maybe giveplayerid == INVALID_PLAYER_ID?
Reply
#5

Well.. weird thing is, at a couple commands it works, while the sendmessage code is exact the same as other command which it wont work

Anyone got a solution?
Reply
#6

giveplayerid is 'playa' replace it

pawn Код:
stock RemoveUnderScore(playerid)
{
    new name[MAX_PLAYER_NAME + 1];
    GetPlayerName(playerid,name,sizeof(name));

    for(new i = 0; name[i] != 0; i++)
        if(name[i] == '_')
            name[i] = ' ';

    return name;
}

if(strcmp(cmd, "/freeze", true) == 0)
{
    if(PlayerInfo[playerid][pAdmin] >= 2)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
            return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /freeze [playerid/PartOfName]");

        new playa = ReturnUser(tmp);
        if(playa != INVALID_PLAYER_ID)
        {
            GetPlayerName(playa, giveplayer, sizeof(giveplayer));
            GetPlayerName(playerid, sendername, sizeof(sendername));
            TogglePlayerControllable(playa, 0);
            PlayerFrozen[playerid] = 1;
            format(string, sizeof(string), "{FF0000}Server action{FF0000}: You have been frozen by an Admin %s.",RemoveUnderScore(playerid));
            SendClientMessage(giveplayerid, COLOR_RED, string); // giveplayerid ?
            format(string, sizeof(string), "{FF0000}Server action{FF0000}: You have frozen %s.", RPN(giveplayerid)); // giveplayerid ?
            SendClientMessage(playerid, COLOR_RED, string);
        } // else player not connected
    }
    else
        SendClientMessage(playerid, COLOR_GRAD1, "   You are not authorized to use that command !");
    return 1;
}
Reply
#7

GetPlayerName(playa, giveplayer, sizeof(giveplayer));

to

GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer)); ?


Sorry for those dumb questions, but I have to learn it somewhere..
Reply
#8

Here
pawn Код:
// giveplayerid ?
in SendClientMessage
Reply
#9

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Here
pawn Код:
// giveplayerid ?
in SendClientMessage
I don't really understand what you mean here.. It's already in SendClientMessage? Check my previous post to see what I changed, hope it's good .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)