#1

i am trying to make a command so when you do /kill

its kills you and a message saying ([there name] has just die


Код:
	if (strcmp("/kill",cmdtext,true,100) ==0){
	SetPlayerHealth(playerid,0);
	SendClientMessageToAll(0xAFAFAF00,pName);
can someone help me please



cheers carljohno
Reply
#2

Код:
if (strcmp("/kill", cmdtext, true, 10) == 0)
	{
		new pName[MAX_PLAYER_NAME];
  	new string[48];
  	GetPlayerName(playerid, pName, sizeof(pName));
  	format(string, sizeof(string), "%s has died", pName);
  	SendClientMessageToAll(0xAAAAAAAA, string);
  	SetPlayerHealth(playerid,0);
		return 1;
	}
look in the wiki next time

WeeDarr
Reply
#3

Try this:

pawn Код:
if (!strcmp(cmdtext, "/kill", true))
{
  new string[34];
  GetPlayerName(playerid, string, 24);
  SetPlayerHealth(playerid, 0.0);
  format(string, 34, "%s has died.", string);
  SendClientMessageToAll(0xFFFFFFFF, string);
  return true;
}
WeeDarr:
1) You do not need to determin how many cells to use for "/kill", and even if you did, 10 is a bit much.
2) Both strcmp and OnPlayerCommandText are meant to return boolean values, so why state one in strcmp but then return a standard integer?
3) You don't need both pName and string....
4) Why are you creating string with 48 cells, as when formatting it you could only ever use up to 34.
5) When getting the player's name, why are you using sizeof(pName) instead of just MAX_PLAYER_NAME or even the value of MAX_PLAYER_NAME which is 24. There is no point in making it work out the size when you can just simply state it instead.
6) The same goes for string, even though you don't need both pName and string you do have both and you are then working out the string size, when again you can just state it.
7) When setting the player's health, please follow the criteria of the parameters. The health part requests a float and you are giving it an integer just simply because it works. You shouldn't do that, in this example it will work. But in other languages or even in different situations in pawn you will not do yourself favours by stating integers instead of floats. It just so happens that in this case the integer is changed into a float of the same value upon usage.
8.) Learn to indent your code.
9) Not a scripting issue, but you are saying the player has died and then setting the health, surely it would be logical to make sure the player had died before telling people he had .
Reply
#4

Quote:
Originally Posted by BeckzyBoi
2) Both strcmp and OnPlayerCommandText are meant to return boolean values, so why state one in strcmp but then return a standard integer?
strcmp's return value is not boolean.

Quote:
Originally Posted by BeckzyBoi
5) When getting the player's name, why are you using sizeof(pName) instead of just MAX_PLAYER_NAME or even the value of MAX_PLAYER_NAME which is 24. There is no point in making it work out the size when you can just simply state it instead.
There is a point: flexibility. You know why, as explained in another thread. Both sizeof() and MAX_PLAYER_NAME are resolved at compile time. You should take advantage of the fact that the compiler will figure stuff out for you.
Reply
#5

1. sorry that i never noticed that...
2. What?
3. got it off the wiki, dont blame me
4. same as above
5. i dont know, it wasnt me...
6. same as 5
7. ok ill remember for next time
8. it was indented in pawno, when you put it in a post the indenting goes wrong
9. Shut up... :P

WeeDarr
Reply
#6

Quote:
Originally Posted by WeeDarr
look in the wiki next time

WeeDarr
well i didnt know what to type in wiki or i would


but thanks for the help anyway
Reply
#7

About the indentation. Do not use TAB. Even in pawno it is encouraged that you use 4 standard spaces as an alternative.
Reply
#8

Quote:
Originally Posted by BeckzyBoi
About the indentation. Do not use TAB. Even in pawno it is encouraged that you use 4 standard spaces as an alternative.
Thats the most Pathetic thing I have ever Heared.
Reply
#9

Quote:
Originally Posted by Grove
Thats the most Pathetic thing I have ever Heared.
You must have a pretty awsome life then, there is nothing at all pathetic about my post. It is the truth :/. You will not always be able to use TAB in script editors, infact you are lucky that pawno has that option. It is just encouraged that you don't use it as you will get so comfortable with using it that when you use a different language in a different editor that doesn't support TAB then you are going to be well pissed off. Just like i was then when i seen your lame reply. Nobody can go through life with everything being so unorthadox as you seem to imagine it all to be.
Reply
#10

Quote:
Originally Posted by BeckzyBoi
Quote:
Originally Posted by Grove
Thats the most Pathetic thing I have ever Heared.
You must have a pretty awsome life then, there is nothing at all pathetic about my post. It is the truth :/. You will not always be able to use TAB in script editors, infact you are lucky that pawno has that option. It is just encouraged that you don't use it as you will get so comfortable with using it that when you use a different language in a different editor that doesn't support TAB then you are going to be well pissed off. Just like i was then when i seen your lame reply. Nobody can go through life with everything being so unorthadox as you seem to imagine it all to be.
I normally stick up for you beckzy, but I am willing to bet you can use tab in every script editor.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)