SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 02/01/2016, 05:39 AM   #1
Ankon
Little Clucker
 
Join Date: May 2015
Posts: 37
Reputation: 0
Question Some help...

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..
__________________
Ankon is offline   Reply With Quote
Old 02/01/2016, 05:55 AM   #2
Godey
Big Clucker
 
Godey's Avatar
 
Join Date: Jun 2015
Location: India
Posts: 150
Reputation: 6
Default Re: Some help...

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?
__________________
My works:
[1] Find the Pizza Box!
Note: I didn't upload my works

Code:
OnPlayerConnect(playerid)
{
    SendClientMessage(playerid, -1, "Welcome to my server and now goodbye!");
    Kick(playerid);
}
Godey is offline   Reply With Quote
Old 02/01/2016, 06:06 AM   #3
Godey
Big Clucker
 
Godey's Avatar
 
Join Date: Jun 2015
Location: India
Posts: 150
Reputation: 6
Default Re: Some help...

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!
__________________
My works:
[1] Find the Pizza Box!
Note: I didn't upload my works

Code:
OnPlayerConnect(playerid)
{
    SendClientMessage(playerid, -1, "Welcome to my server and now goodbye!");
    Kick(playerid);
}
Godey is offline   Reply With Quote
Old 02/01/2016, 06:14 AM   #4
AndySedeyn
High-roller
 
AndySedeyn's Avatar
 
Join Date: Feb 2014
Location: Belgium
Posts: 1,206
Reputation: 681
Default Re: Some help...

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.
AndySedeyn is offline   Reply With Quote
Old 02/01/2016, 06:18 AM   #5
Godey
Big Clucker
 
Godey's Avatar
 
Join Date: Jun 2015
Location: India
Posts: 150
Reputation: 6
Default Re: Some help...

Ankon Said:
Quote:
I used sscanf.. But I can't use it properly so I am using isnull..
__________________
My works:
[1] Find the Pizza Box!
Note: I didn't upload my works

Code:
OnPlayerConnect(playerid)
{
    SendClientMessage(playerid, -1, "Welcome to my server and now goodbye!");
    Kick(playerid);
}
Godey is offline   Reply With Quote
Old 02/01/2016, 06:20 AM   #6
AndySedeyn
High-roller
 
AndySedeyn's Avatar
 
Join Date: Feb 2014
Location: Belgium
Posts: 1,206
Reputation: 681
Default Re: Some help...

Quote:
Originally Posted by Godey View Post
Ankon Said:
So what? He has to learn somehow. And why not by a working example?
AndySedeyn is offline   Reply With Quote
Old 02/01/2016, 06:21 AM   #7
Godey
Big Clucker
 
Godey's Avatar
 
Join Date: Jun 2015
Location: India
Posts: 150
Reputation: 6
Default Re: Some help...

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'
__________________
My works:
[1] Find the Pizza Box!
Note: I didn't upload my works

Code:
OnPlayerConnect(playerid)
{
    SendClientMessage(playerid, -1, "Welcome to my server and now goodbye!");
    Kick(playerid);
}
Godey is offline   Reply With Quote
Old 03/01/2016, 10:55 AM   #8
Ankon
Little Clucker
 
Join Date: May 2015
Posts: 37
Reputation: 0
Default Re: Some help...

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...
__________________
Ankon is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 02:36 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.