Some help...
#1

Hello everyone. I am not a pro scripter and thus want a help from you all.I wante to make a hidebadge command. It means that the player can hide his original nametag colour(the colour on your names when you press TAB)...

I used sscanf.. But I can't use it properly so I am using isnull..

First I defined these things at the top of my gamemode.
//---Some functions---//
#if !defined isnull
#define isnull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
//----end of these functions---//

Then I used this command...(I use i-zcmd to make commands..)

CMD:hbadge(playerid, params[])
{

if(isnull(params)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /hbadge [FBI,LSPD,OFF]");
else if(strcmp(params,"lspd",true) == 0)
{
SetPlayerColor(playerid,COLOR_BLUE);
SendClientMessage(playerid, COLOR_WHITE, "Badge on.");

}
else if(strcmp(params,"fbi",true) == 0)
{
SetPlayerColor(playerid,COLOR_LIGHTERBLUE);
SendClientMessage(playerid, COLOR_WHITE, "Badge on.");

}
else if(strcmp(params,"off",true) == 0)
{
SetPlayerColor(playerid,COLOR_WHITE);
SendClientMessage(playerid, COLOR_WHITE, "You're badge has been removed");

}
return 1;
}
//---End of command---//


I added isnull because if they just wrote /hbadge then a message would say them "Correct Usage:blah blah blah.."
Everything works perfect... The badge works..
But when I type only /hbadge the SendClientMessage with correct usage doesn't show up.. Please help..
If you think should use sscanf please mention how...
I say again.. I am a noob scripter..not as pro like you all..
Thanks...
Graceful if you help..
Reply
#2

I Suggest you use a dialog response
because that is much easier and you can understand it better.

Do you want me to make it for you?
Reply
#3

If you still need the old one, You Haven't returned a value so,

Code:
CMD:hbadge(playerid, params[])
{
	if(isnull(params)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /hbadge [FBI,LSPD,OFF]");
	else if(strcmp(params,"lspd",true) == 0)
	{
		SetPlayerColor(playerid,COLOR_BLUE);
		SendClientMessage(playerid, COLOR_WHITE, "Badge on.");
		return 1;
	}
	else if(strcmp(params,"fbi",true) == 0)
	{
		SetPlayerColor(playerid,COLOR_LIGHTERBLUE);
		SendClientMessage(playerid, COLOR_WHITE, "Badge on.");
		return 1;
	}
	else if(strcmp(params,"off",true) == 0)
	{
		SetPlayerColor(playerid,COLOR_WHITE);
		SendClientMessage(playerid, COLOR_WHITE, "You're badge has been removed");
		return 1;
	}
   return 1;
}
Please rep me if it helped!
Reply
#4

You're using an else-if statement for nothing. You're returning a value in every single statement making the else-if statements redundant. Here's an example with sscanf:

PHP Code:
CMD:hbadge(playeridparams[]) {
    new
        
faction[5];
    if(
sscanf(params"s[5]"faction)) {
        return 
SendClientMessage(playeridCOLOR_RED"USAGE: /hbadge [FBI, LSPD, OFF]");
    }
    if(!
strcmp(faction"fbi"true)) {
        
SetPlayerColor(playeridCOLOR_BLUE);
        
SendClientMessage(playeridCOLOR_WHITE"Badge on.");
    }
    else if(!
strcmp(faction"lspd"true)) {
        
SetPlayerColor(playeridCOLOR_LIGHTERBLUE);
        
SendClientMessage(playeridCOLOR_WHITE"Badge on.");
    }
    else if(!
strcmp(faction"off"true)) {
        
SetPlayerColor(playeridCOLOR_WHITE);
        
SendClientMessage(playeridCOLOR_WHITE"Your badge has been removed.");        
    }
    else {
        
SendClientMessage(playeridCOLOR_RED"You've entered an incorrect faction name.");
    }
    return 
true;

The exclamation point before the strcmp function is the same as doing "== 0" at the end of the strcmp function.
Reply
#5

Ankon Said:
Quote:

I used sscanf.. But I can't use it properly so I am using isnull..

Reply
#6

Quote:
Originally Posted by Godey
View Post
Ankon Said:
So what? He has to learn somehow. And why not by a working example?
Reply
#7

Quote:

So what? He has to learn somehow. And why not by a working example?

Sure, well atleast it's fixed
And both function the same tho'
Reply
#8

Yep AndySedeyn is right... I have to learn.. and thank you all for the fix... Thanks AndySedeyn.... I quite learned somethings.. Thanks...
Rep(ed) you both.. Thanks...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)