03.07.2016, 14:38
Hi, help for make /advertise command
CMD:advertisements(playerid, params[]) {
if(gPlayerLogged[playerid] == 0) {
SendClientMessage(playerid, COLOR_GREY, "You're not logged in.");
}
else if(GetPVarType(playerid, "Injured")) {
SendClientMessage(playerid, COLOR_GREY, "You can't use advertisements while injured.");
}
else if(PlayerCuffed[playerid] != 0) {
SendClientMessage(playerid, COLOR_GREY, "You can't use advertisements right now.");
}
else if(PlayerInfo[playerid][pJailTime] > 0) {
SendClientMessage(playerid, COLOR_GREY, "You can't use advertisements while in jail.");
}
else ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
return 1;
}
switch(dialogid) {
case DIALOG_ADMAIN: if(response) switch(listitem) {
case 0: {
new
szDialog[2256],
szBuffer[32],
arrAdverts[MAX_PLAYERS] = INVALID_PLAYER_ID,
iDialogCount,
iCount,
iBreak,
iRand;
for(new x; x < 50; ++x) ListItemTrackId[playerid][x] = -1;
foreach(Player, i) if(!isnull(szAdvert[i])) arrAdverts[iCount++] = i;
while(iDialogCount < 50 && iBreak < 5000) {
iRand = random(iCount);
if(arrAdverts[iRand] != INVALID_PLAYER_ID) {
strcpy(szBuffer, szAdvert[arrAdverts[iRand]], sizeof(szBuffer));
if(AdminDuty[playerid] == 0) format(szDialog, sizeof(szDialog), "%s%s... (%i)\r\n", szDialog, szBuffer, PlayerInfo[arrAdverts[iRand]][pNumber]);
else format(szDialog, sizeof(szDialog), "%s%s... (%s)\r\n", szDialog, szBuffer, GetPlayerNameEx(arrAdverts[iRand]));
ListItemTrackId[playerid][iDialogCount++] = arrAdverts[iRand];
arrAdverts[iRand] = INVALID_PLAYER_ID;
}
++iBreak;
}
if(!isnull(szDialog)) return ShowPlayerDialogEx(playerid, DIALOG_ADLIST, DIALOG_STYLE_LIST, "Advertisements - List", szDialog, "Select", "Return");
ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
SendClientMessage(playerid, COLOR_GREY, "No advertisements have been posted.");
}
case 1: ShowPlayerDialogEx(playerid, DIALOG_ADSEARCH, DIALOG_STYLE_INPUT, "Advertisements - Search", "Enter a search phrase.", "Search", "Return");
case 2: {
if(PlayerInfo[playerid][pADMute] == 1) {
SendClientMessage(playerid, COLOR_GREY, "You're muted from advertisements.");
}
else if(PlayerInfo[playerid][pNumber] == 0) {
SendClientMessage(playerid, COLOR_GRAD2, "You don't have a cell phone.");
}
else ShowPlayerDialogEx(playerid, DIALOG_ADPLACE, DIALOG_STYLE_INPUT, "Advertisements - Place Advertisement", "Enter your desired advertisement text! Keep it below 128 characters.", "Submit", "Return");
}
case 3: {
if(PlayerInfo[playerid][pADMute] == 1) {
SendClientMessage(playerid, COLOR_GREY, "You're muted from advertisements.");
}
else if(PlayerInfo[playerid][pNumber] == 0) {
SendClientMessage(playerid, COLOR_GRAD2, "You don't have a cell phone.");
}
else if(iAdverTimer >= 1) {
ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
return SendClientMessage(playerid, COLOR_GREY, "Only one priority advertisement can be placed every 30 seconds.");
}
else if(GetPVarType(playerid, "adT")) {
ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
return SendClientMessage(playerid, COLOR_GREY, "You may only place one priority advertisement every two minutes.");
}
else ShowPlayerDialogEx(playerid, DIALOG_ADPLACEP, DIALOG_STYLE_INPUT, "Advertisements - Priority Advertisement",
"Enter your desired advertisement text! Keep it below 128 characters.\nAs this is a priority advertisement, it will be broadcasted, and will cost you $800.", "Submit", "Return");
}
}
case DIALOG_ADPLACE: {
if(response) {
new
iLength = strlen(inputtext);
if(!(2 <= iLength <= 127)) {
ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
return SendClientMessage(playerid, COLOR_GREY, "Your input was too long or too short.");
}
iLength *= 5;
if(GetPlayerCash(playerid) < iLength) {
ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
return SendClientMessage(playerid, COLOR_GREY, "You don't have enough cash for this.");
}
strcpy(szAdvert[playerid], inputtext, 128);
GivePlayerCash(playerid, -iLength);
format(string, sizeof(string), "Congratulations, you have placed your advertisement for $%d!", iLength);
SendClientMessage(playerid, COLOR_WHITE, string);
}
else ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
}
case DIALOG_ADPLACEP: {
if(response) {
if(iAdverTimer >= 1) {
SendClientMessage(playerid, COLOR_GREY, "Only one priority advertisement can be placed every 30 seconds.");
return ShowPlayerDialogEx(playerid, DIALOG_ADPLACEP, DIALOG_STYLE_INPUT, "Advertisements - Priority Advertisement",
"Enter your desired advertisement text! Keep it below 128 characters.\nAs this is a priority advertisement, it will be broadcasted, and will cost you $800.", "Submit", "Return");
}
else if(GetPlayerCash(playerid) < 800) {
ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
return SendClientMessage(playerid, COLOR_GREY, "You don't have enough cash for this.");
}
else if(!(2 <= strlen(inputtext) <= 79)) {
ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
return SendClientMessage(playerid, COLOR_GREY, "Your input was too long or too short.");
}
iAdverTimer = 30;
SetPVarInt(playerid, "adT", 120);
strcpy(szAdvert[playerid], inputtext, 128);
GivePlayerCash(playerid, -800);
new
szMessage[128];
format(szMessage, sizeof(szMessage), "Advertisement: %s - contact %s (%i)", inputtext, GetPlayerNameEx(playerid), PlayerInfo[playerid][pNumber]);
SendClientMessageToAllEx(TEAM_GROVE_COLOR, szMessage);
return SendClientMessage(playerid, COLOR_WHITE, "Congratulations, you've placed your priority advertisement!");
}
else ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
}
case DIALOG_ADSEARCH: {
if(response) {
if(!(4 <= strlen(inputtext) <= 80))
return ShowPlayerDialogEx(playerid, DIALOG_ADSEARCH, DIALOG_STYLE_INPUT, "Advertisements - Search", "Queries must be between 4\n and 80 characters in length.\n\nEnter a search phrase.", "Search", "Return");
else for(new x; x < 50; ++x) ListItemTrackId[playerid][x] = -1;
new
szDialog[2256],
szSearch[80],
szBuffer[32],
iCount;
strcat(szSearch, inputtext, sizeof(szSearch)); // strfind is a piece of shit when it comes to non-indexed arrays, maybe this'll help.
foreach(Player, i) if(!isnull(szAdvert[i])) {
// printf("[ads] [NAME: %s] [ID: %i] [AD: %s] [SEARCH: %s]", GetPlayerNameEx(i), i, szAdvert[i], szSearch);
if(strfind(szAdvert[i], szSearch, true) != -1 && iCount < 50) {
// printf("[ads - MATCH] [NAME: %s] [ID: %i] [AD: %s] [SEARCH: %s] [COUNT: %i] [DIALOG LENGTH: %i] [FINDPOS: %i]", GetPlayerNameEx(i), i, szAdvert[i], szSearch, iCount, strlen(szDialog), strfind(szAdvert[i], szSearch, true));
strcpy(szBuffer, szAdvert[i], sizeof(szBuffer));
if(AdminDuty[playerid] == 0) format(szDialog, sizeof(szDialog), "%s%s... (%i)\r\n", szDialog, szBuffer, PlayerInfo[i][pNumber]);
else format(szDialog, sizeof(szDialog), "%s%s... (%s)\r\n", szDialog, szBuffer, GetPlayerNameEx(i));
ListItemTrackId[playerid][iCount++] = i;
}
}
if(!isnull(szDialog)) ShowPlayerDialogEx(playerid, DIALOG_ADSEARCHLIST, DIALOG_STYLE_LIST, "Advertisements - Search Results", szDialog, "Select", "Return");
else ShowPlayerDialogEx(playerid, DIALOG_ADSEARCHLIST, DIALOG_STYLE_INPUT, "Advertisements - Search", "No results found.\n\nEnter a search phrase.", "Search", "Return");
}
else ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
}
case DIALOG_ADSEARCHLIST: if(response) {
new
i = ListItemTrackId[playerid][listitem],
szDialog[164];
if(IsPlayerConnected(i) && !isnull(szAdvert[i])) {
format(szDialog, sizeof(szDialog), "%s\r\nContact: %i", szAdvert[i], PlayerInfo[i][pNumber]);
ShowPlayerDialogEx(playerid, DIALOG_ADFINAL, DIALOG_STYLE_MSGBOX, "Advertisements - Search Result", szDialog, "Return", "Exit");
}
else SendClientMessage(playerid, COLOR_GREY, "This player has either disconnected or withdrawn their advertisement.");
}
case DIALOG_ADFINAL: {
if(response) return ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
}
case DIALOG_ADLIST: {
if(response) {
new
i = ListItemTrackId[playerid][listitem],
szDialog[164];
if(IsPlayerConnected(i) && !isnull(szAdvert[i])) {
format(szDialog, sizeof(szDialog), "%s\r\nContact: %i", szAdvert[i], PlayerInfo[i][pNumber]);
return ShowPlayerDialogEx(playerid, DIALOG_ADFINAL, DIALOG_STYLE_MSGBOX, "Advertisements - Search Result", szDialog, "Return", "Exit");
}
else SendClientMessage(playerid, COLOR_GREY, "This player has either disconnected or withdrawn their advertisement.");
}
else ShowPlayerDialogEx(playerid, DIALOG_ADMAIN, DIALOG_STYLE_LIST, "Advertisements", "List Advertisements\nSearch Advertisements\nPlace Advertisement\nPlace Priority Advertisement", "Select", "Cancel");
}
}
CMD:ad(playerid, params[]) { if(isnull(params)) return SendClientMessage(playerid, -1, "{0008F7}USAGE: {FFFFFF}/AD TEXT"); GameTextForAll(params, 4000, 0); return 1; }