SA-MP Forums Archive
Freezing with Reason - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Freezing with Reason (/showthread.php?tid=65064)



Freezing with Reason - Robbin237 - 09.02.2009

Hi guys im making a script to freeze someone, with the Name and ID: Decysen (1) and then reason: Your reason here. Can somebody help me with this?

dcmd_freeze(playerid, params[])
{
if(IsPlayerAdmin(playerid)) {
new string[256];
new Player = strval(params);
new Name[MAX_PLAYER_NAME+1];
GetPlayerName(Player, Name, sizeof(Name));

format(string, sizeof(string), "Frozen: %s (%d) Reason:", Name, GetPlayerID(Name));
SendClientMessageToAll(COLOR_PINK, string);
TogglePlayerControllable(Player, false);
}
return 1;
}

Maybe somebody can make the whole code for me :P
Ty!


Re: Freezing with Reason - ShizNator - 09.02.2009

Check out sscanf in the fast commands on SA-MP Wiki it is very usefull with dcmd and will allow you to do what you want with ease.


Re: Freezing with Reason - Robbin237 - 09.02.2009

I cant get it to work..

dcmd_mute(playerid,params[]){
if(IsPlayerAdmin(playerid)) {

new
name,
reason;

if (sscanf(params, "dd", name, reason)) {
SendClientMessage(playerid, 0xFF0000AA, "Usage: /mute [playerid/partname] [reason]");
} else {
new string[256];
new Player = strval(params);
new Name[MAX_PLAYER_NAME+1];
GetPlayerName(Player, Name, sizeof(Name));
new PlayerHisID = GetPlayerID(Name);

if (!reason) {
format(string, sizeof(string), "MUTE: %s (%d) Reason: %s", Name, GetPlayerID(Name), reason);
} else {
format(string, sizeof(string), "MUTE: %s (%d) Reason: No Reason", Name, GetPlayerID(Name));
}

SendClientMessageToAll(COLOR_PINK, string);

pmuted[PlayerHisID] = 1;
}
}
return 1;
}

Plz help


Re: Freezing with Reason - ShizNator - 10.02.2009

Well this is not exactly what you want but will work for an id. As I was looking at your code I noticed you want to do a id/name command. Im not sure as to how it would be done exactly. Maybe you can figure it out. Or maybe just do yourself a seperate command that will give you the id from the name then with the id do the /mute [id] [reason].
Hope it helps. [edit] Removed the ! from if(!strlen(reason))
pawn Код:
dcmd_mute(playerid,params[])
{
  new string[256], reason[128], Name[24];
  new tomute;
  if(IsPlayerAdmin(playerid))
  {
    if(sscanf(params, "ds", tomute, reason))
    {
      SendClientMessage(playerid, 0xFF0000AA, "Usage: /mute [playerid] [reason]");
    }
    else
    {
      GetPlayerName(Player, Name, sizeof(Name));
      if(strlen(reason))
      {
        format(string, sizeof(string), "MUTE: %s (%d) Reason: %s", Name, tomute, reason);
      }
      else
      {
        format(string, sizeof(string), "MUTE: %s (%d) Reason: No Reason", Name, tomute);
      }
      SendClientMessageToAll(COLOR_PINK, string);
      pmuted[tomute] = 1;
    }
  }
  return 1;
}



Re: Freezing with Reason - Backwardsman97 - 10.02.2009

Why did you make the variable named "string" with a size of 256?

Quote:
Originally Posted by ssǝן‾ʎ
[anchor=i128]
  • Max input is 128
The SA:MP chat box has a maximum line length of 128, if someone types something you know it will never be longer than 128 ever. This includes text and commands, so why use a buffer twice that length to process the input?



Re: Freezing with Reason - 1337pr0 - 10.02.2009

Quote:
Originally Posted by backwardsman97
Why did you make the variable named "string" with a size of 256?

Quote:
Originally Posted by ssǝן‾ʎ
[anchor=i128]
  • Max input is 128
The SA:MP chat box has a maximum line length of 128, if someone types something you know it will never be longer than 128 ever. This includes text and commands, so why use a buffer twice that length to process the input?
Quote:
Originally Posted by Kye
I have decided to unsticky this topic because it was shown in an earlier benchmark that the performance difference between allocating 128 vs 256 cells was negligible. String allocation is unlikely to occur during any tight loops where most performance issues exist.

It's true that the chat/window buffer length is a maximum of 128, however it's dangerous in many languages to allocate buffers smaller or equal to the size of the original string. 256 is generally used to give 128 base length plus an additional 128 characters if anything further is appended.

It should be noted that anything sent to the client intended for the chat window that is greater than 128 characters will be ignored.

Program optimisation has been studied since the 1960s and they have found that most execution time and bottlenecks occur in the inner-most loop.



Re: Freezing with Reason - Backwardsman97 - 10.02.2009

Quote:
Originally Posted by 1337pr0
Quote:
Originally Posted by backwardsman97
Why did you make the variable named "string" with a size of 256?

Quote:
Originally Posted by ssǝן‾ʎ
[anchor=i128]
  • Max input is 128
The SA:MP chat box has a maximum line length of 128, if someone types something you know it will never be longer than 128 ever. This includes text and commands, so why use a buffer twice that length to process the input?
Quote:
Originally Posted by Kye
I have decided to unsticky this topic because it was shown in an earlier benchmark that the performance difference between allocating 128 vs 256 cells was negligible. String allocation is unlikely to occur during any tight loops where most performance issues exist.

It's true that the chat/window buffer length is a maximum of 128, however it's dangerous in many languages to allocate buffers smaller or equal to the size of the original string. 256 is generally used to give 128 base length plus an additional 128 characters if anything further is appended.

It should be noted that anything sent to the client intended for the chat window that is greater than 128 characters will be ignored.

Program optimisation has been studied since the 1960s and they have found that most execution time and bottlenecks occur in the inner-most loop.
Touchй


Re: Freezing with Reason - ShizNator - 10.02.2009

Quote:
Originally Posted by backwardsman97
Why did you make the variable named "string" with a size of 256?

Quote:
Originally Posted by ssǝן‾ʎ
[anchor=i128]
  • Max input is 128
The SA:MP chat box has a maximum line length of 128, if someone types something you know it will never be longer than 128 ever. This includes text and commands, so why use a buffer twice that length to process the input?
I didn't put it at 256 he did I just copied his text change a few things. To make it work. I never use 255 unless im saving a long list of variables in one line to a textfile. I know I should of changed it but hell can't do everything for them they gotta learn stuff on their own too 95% of the pepole that come here to ask scripting questions never even read the damn Wiki. Its not my fault people don't read the important sticky's. Don't know if it was designated to me but don't stick that s*** on me.


Re: Freezing with Reason - Robbin237 - 10.02.2009

Now it keeps saying no reason ...


Re: Freezing with Reason - ShizNator - 10.02.2009

Quote:
Originally Posted by Robbin237
Now it keeps saying no reason ...
Yeah remove the ! from here sorry. I just read the code wrong.
pawn Код:
if(!strlen(reason))