Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define filterscript
- #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
- /* ----------EDIT FROM HERE----------*/
- #define COLOR_FOUND 0xFFFF00AA //Color of the message if a hit was found in /hits
- #define COLOR_MSG 0x00FFFFFF //Color of general messages
- #define COLOR_ERROR 0xFF0000FF //Color of the message if there was an error
- #define ANTISPAM_TIME 5 //The minimum time between /hit commands to prevent spam (in seconds)
- /*----------NO NEED TO EDIT FROM HERE----------*/
- new hit[MAX_PLAYERS];
- new hiter[MAX_PLAYERS];
- new ID;
- new antispam[MAX_PLAYERS];
- stock ReturnPlayerName(id)
- {
- new tehname[MAX_PLAYER_NAME];
- GetPlayerName(id, tehname, sizeof(tehname));
- return tehname;
- }
- stock sscanf(string[], format[], {Float,_}:...)
- {
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs();
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if (ch >= '0' && ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return 1;
- }
- }
- while ((ch = string[stringPos]) && ch != ' ');
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- ch,
- num = 0;
- while ((ch = string[stringPos++]))
- {
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- case ' ':
- {
- break;
- }
- default:
- {
- return 1;
- }
- }
- }
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new tmp[25];
- strmid(tmp, string, stringPos, stringPos+sizeof(tmp)-2);
- setarg(paramPos, 0, _:floatstr(tmp));
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != ' ')
- {
- setarg(paramPos, i++, ch);
- }
- if (!i) return 1;
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != ' ')
- {
- stringPos++;
- }
- while (string[stringPos] == ' ')
- {
- stringPos++;
- }
- paramPos++;
- }
- while (format[formatPos] == 'z') formatPos++;
- return format[formatPos];
- }
- dcmd_hit(playerid, params[])
- {
- new amount;
- if(sscanf(params, "dd", ID, amount))
- {
- SendClientMessage(playerid, COLOR_ERROR, "USAGE: /hit [ID] [amount]");
- }
- else if(amount > 0)
- {
- if(IsPlayerConnected(ID))
- {
- if(GetPlayerMoney(playerid) >= amount)
- {
- if(antispam[playerid] == 0)
- {
- hit[ID] = amount;
- hiter[ID] = playerid;
- new string[256];
- format(string, sizeof(string), "You have placed a hit on %s (%i) for $%i", ReturnPlayerName(ID), ID, amount);
- SendClientMessage(playerid, COLOR_MSG, string);
- format(string, sizeof(string), "%s (%i) has placed a hit on %s (%i) for $%i", ReturnPlayerName(playerid), playerid, ReturnPlayerName(ID), ID, amount);
- SendClientMessageToAll(COLOR_MSG, string);
- antispam[playerid] = 1;
- SetTimerEx("antispamtimer", ANTISPAM_TIME*1000, false, "d", playerid);
- }
- else
- {
- SendClientMessage(playerid, COLOR_ERROR, "Please wait before placing another hit!");
- }
- }
- else
- {
- SendClientMessage(playerid, COLOR_ERROR, "You do not have enough money!");
- }
- }
- else
- {
- SendClientMessage(playerid, COLOR_ERROR, "That player is not connected!");
- }
- }
- else
- {
- SendClientMessage(playerid, COLOR_ERROR, "Minimum amount to hit a person with is $1!");
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(hit, 3, cmdtext);
- if(!strcmp(cmdtext, "/hits", true))
- {
- new count = 0;
- SendClientMessage(playerid, COLOR_MSG, "Listing currently placed hits:");
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- if(IsPlayerConnected(i) && hit[i] > 0)
- {
- new string[256];
- format(string, 256, "Hit on %s (%i) for $%i", ReturnPlayerName(i), i, hit[i]);
- SendClientMessage(playerid, COLOR_FOUND, string);
- count++;
- }
- }
- if(count == 0)
- {
- SendClientMessage(playerid, COLOR_ERROR, "No hits placed at this time!");
- }
- }
- return 0;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- if(reason <= 46 && hit[playerid] != 0)
- {
- new string[256];
- format(string, sizeof(string), "%s (%i) killed %s (%i) and recieved $%i for a completed hit", ReturnPlayerName(killerid), killerid, ReturnPlayerName(playerid), playerid, hit[playerid]);
- SendClientMessageToAll(COLOR_MSG, string);
- GivePlayerMoney(killerid, hit[playerid]);
- GivePlayerMoney(hiter[playerid], GetPlayerMoney(hiter[playerid])-hit[playerid]);
- hit[playerid] = 0;
- }
- else if(hit[playerid] != 0)
- {
- new string[256];
- format(string, sizeof(string), "The hit on %s (%i) has been cancelled (died)", ReturnPlayerName(playerid), playerid);
- SendClientMessageToAll(COLOR_MSG, string);
- hit[playerid] = 0;
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid)
- {
- if(hit[playerid] > 0)
- {
- new string[256];
- format(string, sizeof(string), "The hit on %s (%i) has been cancelled (disconnected)", ReturnPlayerName(playerid), playerid);
- SendClientMessageToAll(COLOR_MSG, string);
- hit[playerid] = 0;
- }
- return 1;
- }
- forward antispamtimer(id);
- public antispamtimer(id)
- {
- antispam[id] = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement