Skocz do zawartości

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Wklejka j7xovht79s84 dodana przez nPaul, 21.11.2012 17:18
Typ:



HUD Adv.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
#include <amxmodx>
#include <amxmisc>
 
#pragma semicolon 0
 
new const PLUGIN[] = "Autoresponder/Advertiser";
new const VERSION[] = "0.5";
new const AUTHOR[] = "MaximusBrood";
 
#define NORM_AD 0
#define SAY_AD 1
 
#define COND 0
#define STORE 1
 
#define COND_TKN '%'
#define SAY_TKN '@'
 
#define COND_STKN "%"
#define DEVIDE_STKN "~"
#define SAY_STKN "@"
 
//-.-.-.-.-.-.-.-.DEFINES.-.-.-.-.-.-.-.-.-.-.
 
//Maximum amount of ads
#define MAXADS 64
 
//Minimum difference between two different ads (float)
new const Float:RAND_MIN = 60.0;
 
//Maximum difference between two different ads (float)
new const Float:RAND_MAX = 80.0;
 
//-.-.-.-.-.-.-.-.END DEFINES..-.-.-.-.-.-.-.
 
//Stores
new sayConditions[MAXADS][3][32];
new normConditions[MAXADS][3][32];
new normStore[MAXADS][128];
new sayStore[MAXADS][2][128];
 
new SyncHudObj;
 
//Counters
new adCount[2] = {0, 0};
 
public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR);
	register_cvar("admanager_version", "0.5", FCVAR_SERVER);
 
	register_cvar("ad_react_all", "1");
 
	SyncHudObj = CreateHudSyncObj();
 
	register_clcmd("say","eventSay");
	register_clcmd("say_team","eventSay");
 
	//Delay the load proces by 10 sec because we don't want to get more load
	//on the already high-load mapchange.
	//Too soon to affect players while playing, too late to create time-out @ mapchange
	set_task(10.0, "load");
}
 
public load()
{
	//Load the data
	new filepath[64];
	get_configsdir(filepath, 63);
	format(filepath, 63, "%s/advertisements.ini", filepath);
 
	if(file_exists(filepath))
	{
		new output[512], conditions[128], temp[64], type;
 
		//Open file
		new fHandle = fopen(filepath, "rt");
 
		//Checks for failure
		if(!fHandle)
		return;
 
		//Loop through all lines
		for(new a = 0; a < MAXADS && !feof(fHandle); a++)
		{
			//Get line
			fgets(fHandle, output, 511);
 
 
			//Work away comments
			if(output[0] == ';' || !output[0] || output[0] == ' ' || output[0] == 10) 
			{
				//Line is not counted
				a--;
				continue;
			}
 
			//Reset type
			type = 0;
 
			//Check if it contains conditions
			if(output[0] == COND_TKN)
			{
				//Cut the conditions off the string
				split(output, conditions, 127, output, 511, DEVIDE_STKN);
 
				//Determine if its say check or normal ad
				type = output[0] == SAY_TKN ? 1 : 0;
 
				//Put the conditions in own space
				for(new b = 0; b < 3; b++)
				{
					new sort[16], cond[32], numb;
 
					//Remove the % from line 
					conditions[0] = ' ';
					trim(conditions);
 
					//Get one condition from the line
					split(conditions, temp, 64, conditions, 127, COND_STKN);
 
					split(temp, sort, 15, cond, 31, " ");
 
					if(equali(sort, "map"))
					{
						numb = 0;
					} else if(equali(sort, "min_players"))
					{
						numb = 1;
					} else if(equali(sort, "max_players"))
					{
						numb = 2;
					} else
					{
						continue;
					}
 
					//Copy it to its final resting place ^^
					setString(COND, type, cond, adCount[type], numb);
 
					//Exit if it hasn't got more conditions
					if(!conditions[0])
					break;
				}
			}
 
			if(type == 0)
			type = output[0] == SAY_TKN ? 1 : 0;
 
			if(type == SAY_AD)
			{
				new said[32], answer[128];
 
				//Remove the @ from line
				output[0] = ' ';
				trim(output);
 
				split(output, said, 31, answer, 127, DEVIDE_STKN);
 
				//Save it
				setString(STORE, SAY_AD, said, adCount[SAY_AD], 0);
				setString(STORE, SAY_AD, answer, adCount[SAY_AD], 1);
			} else//if(type == NORM_AD)
			{
				//Save it
				setString(STORE, NORM_AD, output, adCount[NORM_AD]);
			}
 
			//Increment the right counter
			adCount[NORM_AD] += type == NORM_AD ? 1 : 0;
			adCount[SAY_AD]  += type == SAY_AD  ? 1 : 0;
		}
 
		//Set a first task, if there are any normal ads
		if(adCount[NORM_AD] != 0)
		set_task(random_float(RAND_MIN, RAND_MAX), "eventTask");
 
		//Close file to prevent lockup
		fclose(fHandle);	
	}
}
 
new currAd = -1;
 
public eventTask()
{
	//Go past all ads and check conditions
	for(new a = 0; a < adCount[NORM_AD]; a++)
	{
		//Put current ad to the next one
		currAd = currAd == adCount[NORM_AD] - 1 ? 0 : currAd + 1;
 
		if(checkConditions(currAd, NORM_AD))
		{
			//Display the ad
			new data[3];
			data[0] = currAd;
			data[1] = NORM_AD;
			data[2] = 0;
			displayAd(data);
 
			break;
		}
	}
 
	//Set a new task
	set_task(random_float(RAND_MIN, RAND_MAX), "eventTask");
 
	return PLUGIN_CONTINUE;
}
 
public eventSay(id)
{
	//If nothing is said, don't check
	if(adCount[SAY_AD] == 0)
	return PLUGIN_CONTINUE;
 
	new talk[64], keyword[16];
	read_args(talk, 63) ;
 
	//En nu rennen voor jullie zakgeld klootzjakken!
	for(new a = 0; a < adCount[SAY_AD]; a++)
	{
		//Get the string
		getString(STORE, SAY_AD, keyword, 15, a, 0);
 
		if(containi(talk, keyword) != -1)
		{
			//Check the rest if it fails to conditions
			if(!checkConditions(a, SAY_AD))
			continue;
 
			new data[3];
			data[0] = a;
			data[1] = SAY_AD;
			data[2] = id;
 
			//Set the task
			set_task(0.3, "displayAd", 0, data, 3);
 
			//Don't execute more of them
			break;
		}
	}
 
	return PLUGIN_CONTINUE;
}
 
public displayAd(params[])
{
	//Get the string that is going to be displayed
	new message[128];
	getString(STORE, params[1], message, 127, params[0], params[1]);
 
	//If its enabled by cvar and id is set, display to person who triggered message only
	if(get_cvar_num("ad_react_all") == 0 && params[2] != 0)
	{
		new name[64];
		get_user_name(params[2],name,charsmax(name));
		//replace_all(message,charsmax(message),"[you]",name)
		set_hudmessage(255, 255, 255, 0.6, -1.0, 0, 0.0, 0.3, 0.0, 0.0, 2);
		ShowSyncHudMsg(params[2], SyncHudObj, "%i", message);
 
	} else
	{
		//Display the message to everyone
		new plist[32], playernum, player;
 
		get_players(plist, playernum, "c");
 
		for(new i = 0; i < playernum; i++)
		{
			player = plist[i];
			new temp[128];
			copy(temp,charsmax(temp),message);
			new name[64];
			get_user_name(player,name,charsmax(name));
			//replace_all(temp,charsmax(temp),"[you]",name)
			set_hudmessage(255, 255, 255, 0.6, -1.0, 0, 0.0, 0.3, 0.0, 0.0, 2);
			ShowSyncHudMsg(player, SyncHudObj, "%i", temp);
		}
	}
 
	return PLUGIN_HANDLED;
}
 
stock checkConditions(a, type)
{
	//Mapname
	if((type == NORM_AD && normConditions[a][0][0]) || (type == SAY_AD && sayConditions[a][0][0]))
	{
		new mapname[32];
		get_mapname(mapname, 31);
 
		if(! (type == NORM_AD && equali(mapname, normConditions[a][0]) ) || (type == SAY_AD && equali(mapname, sayConditions[a][0]) ) )
		return false;
	}
 
	//Min Players
	if((type == NORM_AD && normConditions[a][1][0]) || (type == SAY_AD && sayConditions[a][1][0]))
	{
		new playersnum = get_playersnum();
 
		if( (type == NORM_AD && playersnum < str_to_num(normConditions[a][1]) ) || (type == SAY_AD && playersnum < str_to_num(sayConditions[a][1]) ) )
		return false;
	}
 
	//Max Players
	if((type == NORM_AD && normConditions[a][2][0]) || (type == SAY_AD && sayConditions[a][2][0]))
	{
		new playersnum = get_playersnum();
 
		if( (type == NORM_AD && playersnum > str_to_num(normConditions[a][2]) ) || (type == SAY_AD && playersnum > str_to_num(sayConditions[a][2]) ) )
		return false;
	}
 
	//If everything went fine, return true
	return true;
}	
 
stock getString(mode, type, string[], len, one, two = 0)
{
	//server_print("mode: %d type: %d len: %d one: %d two %d", mode, type, len, one, two);
 
	//Uses the fact that a string is passed by reference
	if(mode == COND)
	{
		if(type == NORM_AD)
		{
			copy(string, len, normConditions[one][two]);
		} else//if(type = SAY_AD)
		{
			copy(string, len, sayConditions[one][two]);
		}
	} else//if(mode == STORE)
	{
		if(type == NORM_AD)
		{
			copy(string, len, normStore[one]);
		} else//if(type == SAY_AD)
		{
			copy(string, len, sayStore[one][two]);
		}
	}
}
 
stock setString(mode, type, string[], one, two = 0)
{
	if(mode == COND)
	{
		if(type == NORM_AD)
		{
			copy(normConditions[one][two], 31, string);
		} else//if(type = SAY_AD)
		{
			copy(sayConditions[one][two], 31, string);
		}
	} else//if(mode == STORE)
	{
		if(type == NORM_AD)
		{
			copy(normStore[one], 127, string);
		} else//if(type == SAY_AD)
		{
			copy(sayStore[one][two], 127, string);
		}
	}
}

Dodanych wklejek: 4031
Powered By (Pav32) Pastebin © 2011