makepremium command?
#1

Код:
COMMAND:makepremium(playerid, params[])
{
	if(IsPlayerAdmin(playerid))
	{
	if(IsPlayerConnected(playerid))
	{
	new playerfile[128], pname[MAX_PLAYER_NAME];
		GetPlayerName(playerid, pname, sizeof(pname));
		format(playerfile, sizeof(playerfile), "Premium/Users/%s.ini",pname);
	 	if(dini_Exists(playerfile)) return dini_IntSet(playerfile, "Level", 1);
	} else SendClientMessage(playerid, red, "Error: You must be an Admin to use that command.");
	
 }
return 1;
}
As i have noticed This code will make YOU premium if YOU are an admin.. how to convert it to work with all admins to make a NORMAL PLAYER a premium user? Will we be nice also if a "ADMIN %s has just made you PREMIUM!"

someone could help?
Reply
#2

I didn't got what you want to do . You said that this commands wont work like /makepremium ID and it's working only if the person who wants premium have to do the command ?
Reply
#3

You have to extract the "user" param from the "params" string. For this, since you're already using ZCMD, I'd recommend installing (or using, if you have already installed it) SSCANF: https://sampforum.blast.hk/showthread.php?tid=570927 .
Use the "u" specifier, so you'll get something like this:
Код:
new targetID;
if(sscanf(params, "u", targetID))
{
//the admin didn't respect the syntax (he didn't write [/makepremium <player>]) 
}
else
{
//a value has been set to the targetID variable, but it can be either valid (player found) or invalid (player not found)
     if(!IsPlayerConnected(targetID))
     {
     //target player is not connected
     }
     else
     {
     //target player is connected and ready to receive the Premium status, insert all your messages and stuff here
     }
}
All you have to do is understand this code, maybe rewrite it to look better and merge it with your command and you're good to go.


Also, some off-topic note: saving data in files (dini) is outdated, consider moving to a database saving system.
Reply
#4

Quote:
Originally Posted by SpikeSpigel
Посмотреть сообщение
I didn't got what you want to do . You said that this commands wont work like /makepremium ID and it's working only if the person who wants premium have to do the command ?
NEIN what are u saying it's what i would like to! (an admin do /makepremium ID and the ID becomes premium)

As for now the filterscript make yourself premium only if logged as admin!
Reply
#5

Quote:
Originally Posted by HazardouS
Посмотреть сообщение
You have to extract the "user" param from the "params" string. For this, since you're already using ZCMD, I'd recommend installing (or using, if you have already installed it) SSCANF: https://sampforum.blast.hk/showthread.php?tid=570927 .
Use the "u" specifier, so you'll get something like this:
Код:
new targetID;
if(sscanf(params, "u", targetID))
{
//the admin didn't respect the syntax (he didn't write [/makepremium <player>]) 
}
else
{
//a value has been set to the targetID variable, but it can be either valid (player found) or invalid (player not found)
     if(!IsPlayerConnected(targetID))
     {
     //target player is not connected
     }
     else
     {
     //target player is connected and ready to receive the Premium status, insert all your messages and stuff here
     }
}
All you have to do is understand this code, maybe rewrite it to look better and merge it with your command and you're good to go.


Also, some off-topic note: saving data in files (dini) is outdated, consider moving to a database saving system.
hmmm I'm not too good in using sscanf and a total noob in MySQL

EDIT:

Код:
COMMAND:makepremium(playerid, params[])
{
	if(IsPlayerAdmin(playerid))
	{
	if(IsPlayerConnected(playerid))
	{
	new targetID;
	if(sscanf(params, "u", targetID))
	{
	SendClientMessage(playerid, red, "Error: You must enter [/makepremium <player>])");
	}
	else
	{
	
     if(!IsPlayerConnected(targetID))
     {
     SendClientMessage(playerid, red, "Error: User is not online!");
     }
     else
     {
     new playerfile[128], pname[MAX_PLAYER_NAME];
		GetPlayerName(playerid, pname, sizeof(pname));
		format(playerfile, sizeof(playerfile), "Premium/Users/%s.ini",pname);
	 	if(dini_Exists(playerfile)) return dini_IntSet(playerfile, "Level", 1);
		 else SendClientMessage(playerid, red, "Error: You must be an Admin to use that command.");
	}
	
     }
}
	
 }
return 1;
}
You think that this code is good?
Reply
#6

Here you go. I've added only the basic stuff, you can format the strings before sending them so you can include the target player name in the message sent to the admin, for example.

Код:
COMMAND:makepremium(playerid, params[])
{
	if(!IsPlayerConnected(playerid)) return 1;
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "Error: You must be an Admin to use that command.");
	new targetID;
	if(sscanf(params, "u", targetID)) return SendClientMessage(playerid, red, "Error: Syntax error.");
	if(!IsPlayerConnected(targetID)) return SendClientMessage(playerid, red, "Error: Player not connected.");
	new playerfile[128], pname[MAX_PLAYER_NAME];
	GetPlayerName(targetID, pname, sizeof(pname));
	format(playerfile, sizeof(playerfile), "Premium/Users/%s.ini", pname);
	if(dini_Exists(playerfile)) return dini_IntSet(playerfile, "Level", 1);
	SendClientMessage(playerid, -1, "You have given Premium to a player");
	SendClientMessage(targetID, -1, "You have received Premium from an Admin.");
	return 1;
}
Reply
#7

Quote:
Originally Posted by HazardouS
Посмотреть сообщение
Here you go. I've added only the basic stuff, you can format the strings before sending them so you can include the target player name in the message sent to the admin, for example.

Код:
COMMAND:makepremium(playerid, params[])
{
	if(!IsPlayerConnected(playerid)) return 1;
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "Error: You must be an Admin to use that command.");
	new targetID;
	if(sscanf(params, "u", targetID)) return SendClientMessage(playerid, red, "Error: Syntax error.");
	if(!IsPlayerConnected(targetID)) return SendClientMessage(playerid, red, "Error: Player not connected.");
	new playerfile[128], pname[MAX_PLAYER_NAME];
	GetPlayerName(targetID, pname, sizeof(pname));
	format(playerfile, sizeof(playerfile), "Premium/Users/%s.ini", pname);
	if(dini_Exists(playerfile)) return dini_IntSet(playerfile, "Level", 1);
	SendClientMessage(playerid, -1, "You have given Premium to a player");
	SendClientMessage(targetID, -1, "You have received Premium from an Admin.");
	return 1;
}
many thx dude! if i would like to do like that? You have received Premium from Admin %s ?
Reply
#8

The code you posted should work too.

To include variables in strings (such as player names), use the "format" function: https://sampwiki.blast.hk/wiki/Format
Код:
new string[64], pname[24];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "My name is %s", pname);
SendClientMessage(playerid, -1, string);
Something like this ^
Reply
#9

Quote:
Originally Posted by HazardouS
Посмотреть сообщение
The code you posted should work too.

To include variables in strings (such as player names), use the "format" function: https://sampwiki.blast.hk/wiki/Format
Код:
new string[64], pname[24];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "My name is %s", pname);
SendClientMessage(playerid, -1, string);
Something like this ^
Код:
COMMAND:makepremium(playerid, params[])
{
	if(!IsPlayerConnected(playerid)) return 1;
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "Error: You must be an Admin to use that command.");
	new targetID;
	if(sscanf(params, "u", targetID)) return SendClientMessage(playerid, red, "Error: Syntax error.");
	if(!IsPlayerConnected(targetID)) return SendClientMessage(playerid, red, "Error: Player not connected.");
	new playerfile[128], pname[MAX_PLAYER_NAME];
	GetPlayerName(targetID, pname, sizeof(pname));
	format(playerfile, sizeof(playerfile), "Premium/Users/%s.ini", pname);
	if(dini_Exists(playerfile)) return dini_IntSet(playerfile, "Level", 1);
	SendClientMessage(playerid, -1, "You have given Premium to a player");
	new adminname[128], pname2[24];
	GetPlayerName(playerid, pname2, sizeof(pname2));
	format(adminname,sizeof(adminname),"You have received Premium from Admin %s", pname2);
	SendClientMessage(targetID, COLOR_YELLOW, adminname);
	return 1;
}
this should work dude?

meeeh i owe You a big beer ahah
Reply
#10

Yes, it should work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)