Problems with Freeze and Unfreeze command
#1

I maked freeze and ufreeze commands.. but when i type /freeze (playerid) i freezed :S
Same thing when i type /unfreeze (playerid)
heres /freeze command


Код:
if(!strcmp(cmdtext, "/freeze", true, 5))
{
  if (IsPlayerAdmin(playerid))
  {
    if(!strlen(cmdtext[6]))
    {
      SendClientMessage(playerid, COLOR_ORED, "Usage: /freeze [playerid]");
      return 1;
    }
    new ID = strval(cmdtext[6]);
    new strv[170];
    if(IsPlayerConnected(ID))
    {
      format(strv, 170, "~ Your have been freezed");
      SendClientMessage(ID,COLOR_ORANGE, strv);
      TogglePlayerControllable( ID ,0);
    }
  }
  return SendClientMessage(playerid, COLOR_RED, "Your not rcon admin!");
}
Reply
#2

Код:
if(!strcmp(cmdtext, "/freeze", true, 5))
{
  if (IsPlayerAdmin(playerid))
  {
    if(!strlen(cmdtext[6]))
    {
      SendClientMessage(playerid, COLOR_ORED, "Usage: /freeze [playerid]");
      return 1;
    }
    new ID = strval(cmdtext[6]);
    new strv[170];
    if(IsPlayerConnected(ID))
    {
      format(strv, 170, "~ Your have been freezed");
      SendClientMessage(ID,COLOR_ORANGE, strv);
      TogglePlayerControllable( ID ,1); // 1 is freezed
    }
  }
  return SendClientMessage(playerid, COLOR_RED, "Your not rcon admin!");
}
Код:
if(!strcmp(cmdtext, "/unfreeze", true, 5))
{
  if (IsPlayerAdmin(playerid))
  {
    if(!strlen(cmdtext[6]))
    {
      SendClientMessage(playerid, COLOR_ORED, "Usage: /freeze [playerid]");
      return 1;
    }
    new ID = strval(cmdtext[6]);
    new strv[170];
    if(IsPlayerConnected(ID))
    {
      format(strv, 170, "~ Your have been freezed");
      SendClientMessage(ID,COLOR_ORANGE, strv);
      TogglePlayerControllable( ID ,0); // 0 is unfreezed
    }
  }
  return SendClientMessage(playerid, COLOR_RED, "Your not rcon admin!");
}
Reply
#3

Again same problem.. i cant freeze other players :S Alway i type /freeze 1 i freezed and im id 0
Reply
#4

Do you use strtok somewhere in your script?
Reply
#5

No?
Reply
#6

Then you should use it. Even better if you use dcmd or zcmd, but I'll show you how to use strtok.

First put

pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[32];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
somewhere in our script.

Then

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new idx;
    new cmd[128], tmp[256];
   
    cmd = strtok(cmdtext, idx);
...
And then change your command:

pawn Код:
if(!strcmp(cmd, "/freeze", true))
{
  if (IsPlayerAdmin(playerid))
  {
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
      SendClientMessage(playerid, COLOR_ORED, "Usage: /freeze [playerid]");
      return 1;
    }
    new ID = strval(tmp);
    new strv[170];
    if(IsPlayerConnected(ID))
    {
      format(strv, 170, "~ Your have been freezed");
      SendClientMessage(ID,COLOR_ORANGE, strv);
      TogglePlayerControllable( ID ,0);
    }
  }
  return SendClientMessage(playerid, COLOR_RED, "Your not rcon admin!");
}
Reply
#7

Where it put that

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new idx;
new cmd[128], tmp[256];

cmd = strtok(cmdtext, idx);
...
Reply
#8

Quote:
Originally Posted by Nakki
Where it put that

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new idx;
new cmd[128], tmp[256];

cmd = strtok(cmdtext, idx);
...
Find public OnPlayerCommandText(playerid, cmdtext[]) in your script and put it there.
Reply
#9

Why do you help with so hard way? He's just a player from my server and he's a beginner? How in hell he could know what is strtok?

But ontopic: I have a solution

Look at the command line, there's that 5. That is the command length without parameters. The length of /freeze is 7, not 5. I made a fixed version, it's here

pawn Код:
if(!strcmp(cmdtext, "/freeze", true, 7))
{
  if (IsPlayerAdmin(playerid))
  {
    if(!strlen(cmdtext[8]))
    {
      SendClientMessage(playerid, COLOR_ORED, "Usage: /freeze [playerid]");
      return 1;
    }
    new ID = strval(cmdtext[8]);
    new strv[170];
    if(IsPlayerConnected(ID))
    {
      format(strv, 170, "~ You have been frozen!");
      SendClientMessage(ID,COLOR_ORANGE, strv);
      TogglePlayerControllable( ID ,0);
    }
  }
  return SendClientMessage(playerid, COLOR_RED, "You are not an admin (RCON)");
}
And unfreeze:

pawn Код:
if(!strcmp(cmdtext, "/unfreeze", true, 9))
{
  if (IsPlayerAdmin(playerid))
  {
    if(!strlen(cmdtext[10]))
    {
      SendClientMessage(playerid, COLOR_ORED, "Usage: /unfreeze [playerid]");
      return 1;
    }
    new ID = strval(cmdtext[10]);
    new strv[170];
    if(IsPlayerConnected(ID))
    {
      format(strv, 170, "~ You have been unfrozen!");
      SendClientMessage(ID,COLOR_ORANGE, strv);
      TogglePlayerControllable( ID ,1);
    }
  }
  return SendClientMessage(playerid, COLOR_RED, "You are not an admin (RCON)");
}
Reply
#10

Quote:
Originally Posted by Jakku
Why do you help with so hard way? He's just a player from my server and he's a beginner? How in hell he could know what is strtok?
And if he doesn't understand this he will always stay a beginner.
Reply
#11

Quote:
Originally Posted by MadeMan
Quote:
Originally Posted by Jakku
Why do you help with so hard way? He's just a player from my server and he's a beginner? How in hell he could know what is strtok?
And if he doesn't understand this he will always stay a beginner.
That's your opinion
Reply
#12

Quote:
Originally Posted by Nakki
I maked freeze and ufreeze commands.. but when i type /freeze (playerid) i freezed :S
Same thing when i type /unfreeze (playerid)
heres /freeze command


Код:
if(!strcmp(cmdtext, "/freeze", true, 5))
{
  if (IsPlayerAdmin(playerid))
  {
    if(!strlen(cmdtext[6]))
    {
      SendClientMessage(playerid, COLOR_ORED, "Usage: /freeze [playerid]");
      return 1;
    }
    new ID = strval(cmdtext[6]);
    new strv[170];
    if(IsPlayerConnected(ID))
    {
      format(strv, 170, "~ Your have been freezed");
      SendClientMessage(ID,COLOR_ORANGE, strv);
      TogglePlayerControllable( ID ,0);
    }
  }
  return SendClientMessage(playerid, COLOR_RED, "Your not rcon admin!");
}
Use this command's seems it works!
freeze- >
Код:
if(strcmp(cmd, "/freeze", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /freeze [playerid/PartOfName]");
				return 1;
			}
			new playa;
			playa = ReturnUser(tmp);
			if(PlayerInfo[playa][pAdmin] > 0)
			{
				SendClientMessage(playerid, COLOR_GRAD2, "Admins can not be frozen");
				return 1;
			}
			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);
						format(string, sizeof(string), "AdmCmd/HlpCmd: %s Freezes %s",sendername, giveplayer);
						printf("%s",string);
						format(string, sizeof(string), "AdmCmd/HlpCmd: %s was Frozen by %s",giveplayer ,sendername);
						ABroadCast(COLOR_LIGHTRED,string,1);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GRAD1, "  you are not authorized to use that command!");
			}
		}
		return 1;
	}
unfreeze- >
Код:
if(strcmp(cmd, "/unfreeze", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /unfreeze [playerid]");
				return 1;
			}
			new playa;
			playa = ReturnUser(tmp);
			if (PlayerInfo[playerid][pAdmin] >= 1)
			{
			  if(IsPlayerConnected(playa))
			  {
			    if(playa != INVALID_PLAYER_ID)
			    {
			  	  GetPlayerName(playa, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
						TogglePlayerControllable(playa, 1);
						format(string, sizeof(string), "AdmCmd/HlpCmd: %s UnFroze %s",sendername, giveplayer);
						printf("%s",string);
						format(string, sizeof(string), "AdmCmd/HlpCmd: %s was UnFrozen by %s",giveplayer ,sendername);
						ABroadCast(COLOR_LIGHTRED,string,1);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GRAD1, "  you are not authorized to use that command!");
			}
		}
		return 1;
	}
Reply
#13

Quote:
Originally Posted by WellDoneNick
Quote:
Originally Posted by Nakki
I maked freeze and ufreeze commands.. but when i type /freeze (playerid) i freezed :S
Same thing when i type /unfreeze (playerid)
heres /freeze command


Код:
if(!strcmp(cmdtext, "/freeze", true, 5))
{
  if (IsPlayerAdmin(playerid))
  {
    if(!strlen(cmdtext[6]))
    {
      SendClientMessage(playerid, COLOR_ORED, "Usage: /freeze [playerid]");
      return 1;
    }
    new ID = strval(cmdtext[6]);
    new strv[170];
    if(IsPlayerConnected(ID))
    {
      format(strv, 170, "~ Your have been freezed");
      SendClientMessage(ID,COLOR_ORANGE, strv);
      TogglePlayerControllable( ID ,0);
    }
  }
  return SendClientMessage(playerid, COLOR_RED, "Your not rcon admin!");
}
Use this command's seems it works!
freeze- >
Код:
if(strcmp(cmd, "/freeze", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /freeze [playerid/PartOfName]");
				return 1;
			}
			new playa;
			playa = ReturnUser(tmp);
			if(PlayerInfo[playa][pAdmin] > 0)
			{
				SendClientMessage(playerid, COLOR_GRAD2, "Admins can not be frozen");
				return 1;
			}
			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);
						format(string, sizeof(string), "AdmCmd/HlpCmd: %s Freezes %s",sendername, giveplayer);
						printf("%s",string);
						format(string, sizeof(string), "AdmCmd/HlpCmd: %s was Frozen by %s",giveplayer ,sendername);
						ABroadCast(COLOR_LIGHTRED,string,1);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GRAD1, " you are not authorized to use that command!");
			}
		}
		return 1;
	}
unfreeze- >
Код:
if(strcmp(cmd, "/unfreeze", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /unfreeze [playerid]");
				return 1;
			}
			new playa;
			playa = ReturnUser(tmp);
			if (PlayerInfo[playerid][pAdmin] >= 1)
			{
			  if(IsPlayerConnected(playa))
			  {
			    if(playa != INVALID_PLAYER_ID)
			    {
			  	  GetPlayerName(playa, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
						TogglePlayerControllable(playa, 1);
						format(string, sizeof(string), "AdmCmd/HlpCmd: %s UnFroze %s",sendername, giveplayer);
						printf("%s",string);
						format(string, sizeof(string), "AdmCmd/HlpCmd: %s was UnFrozen by %s",giveplayer ,sendername);
						ABroadCast(COLOR_LIGHTRED,string,1);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GRAD1, " you are not authorized to use that command!");
			}
		}
		return 1;
	}
He will get a load of errors because there are "PlayerInfo" etc. I gave him the working commands, so you don't have to reply
Reply
#14

Yes.. I have now working Freeze and Unfreeze commands
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)