Unreachable code :/
#1

Код:
CMD:slap(playerid, params[])
{
	new targetid, string[128], name[128];
	if(sscanf(params, "s", string))
	{
	    if(IsPlayerAdmin(playerid))
	    {
	                SendClientMessage(playerid, 0x708090FF, "Syntax: /slap [playerid]");
                        if(!IsPlayerConnected(targetid)) return
			SendClientMessage(playerid, 0xFFFFFFF,"That player is not connected to the server!");
			SetPlayerVelocity(targetid, 0.5, 0.0, 0.0); return
   			format(string, sizeof(string), "%s has slapped %s",GetName(playerid), GetName(playerid), name);
			SendMessageToRAdmins(0xFF0000FF, string);
	     }
	}
	else
	{
		if(!IsPlayerAdmin(playerid)) return
		SendClientMessage(playerid, 0x708090FF, "You are not a admin!");
	}
	return 1;
}
Problem:
Код:
GreenIsGo.pwn(280) : warning 225: unreachable code
Line 280:
Код:
SendMessageToRAdmins(0xFF0000FF, string);
I know its bad but im just confused :/
Reply
#2

Replace this line
pawn Код:
format(string, sizeof(string), "%s has slapped %s",GetName(playerid), GetName(playerid), name);
with
pawn Код:
format(string, sizeof(string), "%s has slapped %s",GetName(playerid), GetName(targetid));
Reply
#3

Replace this line:

pawn Код:
format(string, sizeof(string), "%s has slapped %s",GetName(playerid), GetName(playerid), name);
With this one:

pawn Код:
format(string, sizeof string, "%s has slapped %s",GetName(playerid), GetName(targetid));
Reply
#4

Код:
CMD:slap(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, 0x708090FF, "You are not a admin!");
        
	new targetid, string[128];
	if(isnull(params))
	    return SendClientMessage(playerid, 0x708090FF, "Syntax: /slap [playerid]");
	    
     if(!IsPlayerConnected(targetid))
	 	return SendClientMessage(playerid, 0xFFFFFFF,"That player is not connected to the server!");
	 	
	SetPlayerVelocity(targetid, 0.5, 0.0, 0.0);
	format(string, sizeof(string), "%s has slapped %s", GetName(playerid), GetName(targetid));
	SendMessageToRAdmins(0xFF0000FF, string);
	return 1;
}
Very messed up in your code. Don't use sscanf to a single command argument. You use the specifier "s" to the number that corresponds to a string. Take a look at my code and remember what and how.
Reply
#5

i know :/ im VERY new to scripting, was just messing around trying to figure things out through trial and error
Reply
#6

Quote:
Originally Posted by ProfeQ
Посмотреть сообщение
Код:
CMD:slap(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, 0x708090FF, "You are not a admin!");
        
	new targetid, string[128];
	if(isnull(params))
	    return SendClientMessage(playerid, 0x708090FF, "Syntax: /slap [playerid]");
	    
     if(!IsPlayerConnected(targetid))
	 	return SendClientMessage(playerid, 0xFFFFFFF,"That player is not connected to the server!");
	 	
	SetPlayerVelocity(targetid, 0.5, 0.0, 0.0);
	format(string, sizeof(string), "%s has slapped %s", GetName(playerid), GetName(targetid));
	SendMessageToRAdmins(0xFF0000FF, string);
	return 1;
}
Very messed up in your code. Don't use sscanf to a single command argument. You use the specifier "s" to the number that corresponds to a string. Take a look at my code and remember what and how.
That's not going to work, you never assign a value to targetid! Replacing:
Код:
if(isnull(params))
	    return SendClientMessage(playerid, 0x708090FF, "Syntax: /slap [playerid]");
with

Код:
if(sscanf(params,"r",targetid))
	    return SendClientMessage(playerid, 0x708090FF, "Syntax: /slap [playerid]");
Is far better, than the command can use the playerid, or the name (and it works).
Reply
#7

Trial and error is good for me, I recommend you also edit the scripts from the Internet, is useful in understanding the new features and solutions to some things.

//Edit:
Ohh god, my mistake. I would suggest, however, dispense with sscanf.

Код:
CMD:slap(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, 0x708090FF, "You are not a admin!");
        
	new string[128];
	if(isnull(params))
	    return SendClientMessage(playerid, 0x708090FF, "Syntax: /slap [playerid]");
	    
     if(!IsPlayerConnected(strval(params)))
	 	return SendClientMessage(playerid, 0xFFFFFFF,"That player is not connected to the server!");
	 	
	SetPlayerVelocity(strval(params), 0.5, 0.0, 0.0);
	format(string, sizeof(string), "%s has slapped %s", GetName(playerid), GetName(strval(params)));
	SendMessageToRAdmins(0xFF0000FF, string);
	return 1;
}
Reply
#8

Still getting the same warning when i go to compile.
Reply
#9

Quote:
Originally Posted by ProfeQ
Посмотреть сообщение
Trial and error is good for me, I recommend you also edit the scripts from the Internet, is useful in understanding the new features and solutions to some things.
I was trying that but then i realized most of the scripts i find on the internet have things that i have no idea what to do with...

Edit:
Quote:
Originally Posted by ProfeQ
Посмотреть сообщение
//Edit:
Ohh god, my mistake. I would suggest, however, dispense with sscanf.

Код:
CMD:slap(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, 0x708090FF, "You are not a admin!");
        
	new string[128];
	if(isnull(params))
	    return SendClientMessage(playerid, 0x708090FF, "Syntax: /slap [playerid]");
	    
     if(!IsPlayerConnected(strval(params)))
	 	return SendClientMessage(playerid, 0xFFFFFFF,"That player is not connected to the server!");
	 	
	SetPlayerVelocity(strval(params), 0.5, 0.0, 0.0);
	format(string, sizeof(string), "%s has slapped %s", GetName(playerid), GetName(strval(params)));
	SendMessageToRAdmins(0xFF0000FF, string);
	return 1;
}
Anddd now im confused lol
Reply
#10

Quote:
Originally Posted by pyrodave
Посмотреть сообщение
pawn Код:
if(sscanf(params,"r",targetid))
        return SendClientMessage(playerid, 0x708090FF, "Syntax: /slap [playerid]");
That won't work, you have to use that to make it work:

pawn Код:
if(sscanf(params,"u",targetid)) return SendClientMessage(playerid, 0x708090FF, "Syntax: /slap [playerid]");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)