I need a quick /ad command
#1

Can someone give me a quick /ad command (its an advertisement command)

This command should appear for everyone in the server.

I've searched for one, none of them worked for me.
Reply
#2

Search.
http://forum.sa-mp.com/index.php?top...1554#msg691554
Reply
#3

Quote:
Originally Posted by Don Correlli
Thanks for that, but i get an error with that code. Whats the problem, Heres the code

Код:
 if(strcmp("/ad", cmdtext, true, 3) == 0)
	{
	new PlayerMoney;
	PlayerMoney = GetPlayerMoney(playerid);
	if(PlayerMoney >= 500)
	{
	if(cmdtext[3] == 0)
	{
	SendClientMessage(playerid, COLOR_RED, "Usage: /ad [advertising]");
	return 1;
	}
	new string[128];
	new PlayerName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
	ResetPlayerMoney(playerid);
	GivePlayerMoney(playerid, PlayerMoney -500);
	format(string, sizeof(string), "%s (ID: %d) is advertising: %s", PlayerName, playerid, cmdtext[4]);
	SendClientMessageToAll(COLOR_RED, string);
	return 1;
	}
	return 1;
	}
heres the warning

Код:
(513) : warning 219: local variable "string" shadows a variable at a preceding level
Reply
#4

It's warning and not error. You have "string" already defined somewhere in your script.
Just delete:
pawn Код:
new string[128];
Reply
#5

Quote:
Originally Posted by Don Correlli
It's warning and not error. You have "string" already defined somewhere in your script.
Just delete:
pawn Код:
new string[128];
code didnt work...when i type /ad and writing nothing happens
Reply
#6

Requires bigstrtok + strtok. Search for it around the forums or in SeifAdmin :P
pawn Код:
new cmd[128], tmp[128], name[MAX_PLAYER_NAME], str[128], idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/ad", true) == 0)
{
  tmp = bigstrtok(cmdtext, idx);
  if(!strlen(tmp)) return SendClientMessage(playerid, color, "Usage: /ad [message]");
  GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  format(str, sizeof str, "[ADVERTISMENT] %s: %s", name, tmp);
  SendClientMessageToAll(color, str);
  return 1;
}
Reply
#7

its very easy

Код:
public OnPlayerCommandText

new cmd[128], idx;
cmd = strtok(cmdtext, idx);

if (strcmp(cmd, "/ad", true)==0)
{
  new tmp[128];
  tmp = strtok(cmdtext, idx);

  if (strlen(tmp)==0) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /ad (text)"); // 0xFF0000AA is Red

  new adstring[128], pname[24];
  format(adstring, sizeof(adstring), "ADVERTISEMENT: %s, contact: %s [%i]", tmp, pname, (playerid));
  SendClientMessageToAll(0xFFFF00AA, adstring); // 0xFFFF00AA is yellow
  //GivePlayerMoney(playerid, -5) ;
  //GameTextForPlayer(playerid, "~r~-$5", 1500, 1);
  // remove the //'s from in front of the two lines above this if you want it to cost the player $5 to advertise
}
there ya go just copy and paste that at the top of your "OnPlayerCommandText"

yea yea i know it uses strtok, if you dont have <dutils.inc> with your game mode, past this at the bottom of the file:

Код:
stock strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}
 
	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
EDIT: I realize mine isn't as good as others and doesn't check how much cash you got, but it should work fine.
Reply
#8

Thanks for all the help guys
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)