/ad command
#1

how to make a simple ad command like this

for eg:Advertisement: selling alpha for -------
Advertisement by [Playername]

thx
Reply
#2

Just an example:
PHP код:
CMD:ad(playeridparams[])
{
   new 
string[128], message[128], playername[MAX_PLAYER_NAME];
   if(
sscanf(params"s[128]"message)) return SendClientMessage(playerid, -1"Syntax: /ad [message]");
   
GetPlayerName(playeridplayernameMAX_PLAYER_NAME);
   
format(stringsizeof string"Advertisement by %s: %s"playernamemessage);
   
SendClientMessageToAll(-1string); 
Reply
#3

Quote:
Originally Posted by saffierr
Посмотреть сообщение
Just an example:
PHP код:
CMD:ad(playeridparams[])
{
   new 
string[128], message[128], playername[MAX_PLAYER_NAME];
   if(
sscanf(params"s[128]"message)) return SendClientMessage(playerid, -1"Syntax: /ad [message]");
   
GetPlayerName(playeridplayernameMAX_PLAYER_NAME);
   
format(stringsizeof string"Advertisement by %s: %s"playernamemessage);
   
SendClientMessageToAll(-1string); 
which cmd processer i have to use for it ?
Reply
#4

Required zcmd & sscanf
Reply
#5

I have remade your command..

Код:
CMD:ad(playerid, params[])
{
	if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, -1, "{CDCDCD}Syntax: {FFFFFF}/Ad [Text]");
	if(strlen(params) < 3) return SendClientMessage(playerid, -1, "{FF8000}ERROR: Invalid Text Length!");
	new MyName[24], String[164]; GetPlayerName(playerid, MyName, 24);
	format(String, 164, "{FFFF00}New Advertisement: %s: %s", MyName, params);
	return SendClientMessageToAll(-1, String);
}
Reply
#6

Quote:
Originally Posted by TheHonnor
Посмотреть сообщение
I have remade your command..

Код:
CMD:ad(playerid, params[])
{
	if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, -1, "{CDCDCD}Syntax: {FFFFFF}/Ad [Text]");
	if(strlen(params) < 3) return SendClientMessage(playerid, -1, "{FF8000}ERROR: Invalid Text Length!");
	new MyName[24], String[164]; GetPlayerName(playerid, MyName, 24);
	format(String, 164, "{FFFF00}New Advertisement: %s: %s", MyName, params);
	return SendClientMessageToAll(-1, String);
}
and how can i make GivePlayerMoney(playerid,-10000) ??
and i need a timer of 1 miinute for each ad
thnx
Reply
#7

PHP код:
new advtime[MAX_PLAYERS];

CMD:ad(playerid,params[])
{
    new 
string[128], message[128], playername[MAX_PLAYER_NAME];
   if(
sscanf(params"s[128]"message)) return SendClientMessage(playerid, -1"Syntax: /ad [message]");
   if(
GetPlayerMoney(playerid) <= 10000) return SendClientMessage(playerid, -1"Error: You don't have $10000 to make a Advertisement");
   if(
advtime[playerid] == 1) return SendClientMessage(playerid, -1"Error: please wait before making another Advertisement");
   
GetPlayerName(playeridplayernameMAX_PLAYER_NAME);
   
format(stringsizeof(string), "{FFFF00}Advertisement by %s: %s"playernamemessage);
   
SendClientMessageToAll(-1string); 
   
advtime[playerid] = 1;
   
SetTimerEx("advtimer"60000false"i",playerid);
   return 
1;
}
forward advtimer(playerid);
public 
advtimer(playerid)
{
    if(
advtime[playerid] == 1)
    {
        
advtime[playerid] = 0;
    }

Don't forget to reset the variable on playerconnect/disconnect
just add this under onplayerconnect
PHP код:
public OnPlayerConnect(playerid)
{
    
advtime[playerid] = 0;

Reply
#8

Try this

PHP код:
COMMAND:ad(playeridparams[])
{
    if (
GetSVarInt(ad_true_msg) == 1)
        return 
SendClientMessage(playerid, -1, !"{CDCDCD}You can't send an advertising message!");    
    if (
sscanf(params"s[128]"params))
        return 
SendClientMessage(playerid, -1, !"{CDCDCD}Syntax: {FFFFFF}/ad [text]");    
    new 
name[MAX_PLAYER_NAME], ad_message[145] = "Advertisement by ";    
    
GetPlayerName(playeridnameMAX_PLAYER_NAME);    
    
strcat(ad_messagename);
    
strcat(ad_message": ");
    
strcat(ad_messageparams);
    
SetSVarInt("ad_true_msg"1);
    
SetTimerEx("@__OnPlayerSendAdMsg"1000*590"s"ad_message);
    
    return 
SendClientMessage(playerid, -1, !"Your message has been sent!");
}
@
__OnPlayerSendAdMsg(message[]); 
@
__OnPlayerSendAdMsg(message[])
{
    
SendClientMessageToAll(0xFFFF00FFmessage);
    
SetSVarInt("ad_true_msg"0);

Write me if there are errors in my example. I have not tested his version
Reply
#9

Quote:
Originally Posted by xTURBOx
Посмотреть сообщение
PHP код:
new advtime[MAX_PLAYERS];
CMD:ad(playerid,params[])
{
    new 
string[128], message[128], playername[MAX_PLAYER_NAME];
   if(
sscanf(params"s[128]"message)) return SendClientMessage(playerid, -1"Syntax: /ad [message]");
   if(
GetPlayerMoney(playerid) <= 10000) return SendClientMessage(playerid, -1"Error: You don't have $10000 to make a Advertisement");
   if(
advtime[playerid] == 1) return SendClientMessage(playerid, -1"Error: please wait before making another Advertisement");
   
GetPlayerName(playeridplayernameMAX_PLAYER_NAME);
   
format(stringsizeof(string), "{FFFF00}Advertisement by %s: %s"playernamemessage);
   
SendClientMessageToAll(-1string); 
   
advtime[playerid] = 1;
   
SetTimerEx("advtimer"60000false"i",playerid);
   return 
1;
}
forward advtimer(playerid);
public 
advtimer(playerid)
{
    if(
advtime[playerid] == 1)
    {
        
advtime[playerid] = 0;
    }

Don't forget to reset the variable on playerconnect/disconnect
just add this under onplayerconnect
PHP код:
public OnPlayerConnect(playerid)
{
    
advtime[playerid] = 0;

it does not reduces 10k from player :P
Reply
#10

totally forgot to add "GivePlayerMoney(playerid,-10000);"
Just add it under if (advtime[playerid].....

Eg
Код:
 if (advtime[playerid].....
GivePlayerMoney(playerid,-10000);
GetPlayerName....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)