Страница 1 от 2

Server Commands v1.2

Публикувано на: 17 Сеп 2018, 16:57
от illusion

Име на плъгина: Server Commands [v1.2]

Автор: summertime vibes. // Аз

Описание:
- Прост плъгин, с който може с дадена команда, която сте написали в чата да изкарва информация за нея. Има cvar, от който може да направите да изкарва информацията по 3 начина (чат, hud и dhud съобщение). Вкарани са възможно повече дефиниции и константи с цел плъгинът да е максимално олекотен за използване.
Cvars:
amx_message 0/1/2 (0 - Chat ; 1 - HUD ; 2 - DHUD) - как да излиза първото съобщение
amx_message2 0/1/2 (0 - Chat ; 1 - HUD ; 2 - DHUD) - как да излиза второто съобщение
amx_sc_advert_time (Default: 300.0) - през колко секунди да се показва рекламното съобщение.

Команди:
/scadvert - включва / изключва advert съобщенията в чата. По подразбиране е включено.

КОД:

Код за потвърждение: Избери целия код

#include <amxmodx>
#include <formatin>
#include <cromchat>
#if AMXX_VERSION_NUM < 183
	#include <dhudmessage>
#endif

// Defines
#define AUTHOR "summertime vibes"
#define VERSION "1.2"

#define HudPrefix "[HUD Prefix]"
#define DHUDPrefix "[DHUD PREFIX]"

#define firstcommand "/command1"
#define secondcommand "/command2"

// New
new pCvar, pCvar2, cvar_time
new bool:g_AdvertMessage = true

// New Const
new const g_iCommand[] = { "/command1" }
new const g_iCommandTwo[] = { "/command2" }
new const g_iCommandAdvert[] = { "/scadvert" }

public plugin_init()
{
	register_plugin("Server Commands", VERSION, AUTHOR)

	for(new i; i<sizeof(g_iCommand); i++)
	{
		register_clcmd(formatin("say %s", g_iCommand[i]), "cmd1")
		register_clcmd(formatin("say_team %s", g_iCommand[i]), "cmd1")
	}

	for(new i; i<sizeof(g_iCommandTwo); i++)
	{
		register_clcmd(formatin("say %s", g_iCommandTwo[i]), "cmd2")
		register_clcmd(formatin("say_team %s", g_iCommandTwo[i]), "cmd2")
	}

	for(new i; i<sizeof(g_iCommandAdvert); i++)
	{
		register_clcmd(formatin("say %s", g_iCommandAdvert[i]), "advertcmd")
		register_clcmd(formatin("say_team %s", g_iCommandAdvert[i]), "advertcmd")
	}

	pCvar = register_cvar("amx_sc_message", "0") // 0 - chat ; 1 - hud ; 2 - dhud
	pCvar2 = register_cvar("amx_sc_message2", "0") // 0 - chat ; 1 - hud ; 2 - dhud
	cvar_time = register_cvar("amx_sc_advert_time", "300.0")

	set_task(get_pcvar_float(cvar_time), "Advert", _,_,_, "b");

	CC_SetPrefix("&x04[Server Commands]")
}

public Advert()
    if(g_AdvertMessage)
    {
	    CC_SendMessage(0, "^x03Write in the  chat &x01%s &x03or &x01%s &x03to view the commands information&x01.",firstcommand, secondcommand);
	    return
    }

public advertcmd(id)
{
	g_AdvertMessage = !g_AdvertMessage
	CC_SendMessage(id, "&x01Advert Messages have been &x03%s&x01.", g_AdvertMessage ? "enabled" : "disabled" );
}	    

public cmd(id)
{
		switch(get_pcvar_num(pCvar))
		{
			case 0: CC_SendMessage(id, "^x04The text when you write the command.")
			case 1:
			{
				set_hudmessage(random(256), random(256), random(256), -1.0, 0.26, 2, 6.0, 12.0)
	    	                show_hudmessage(id, "%s The text when you write the command.",HudPrefix)
    		}
			case 2:
			{
				set_dhudmessage(random(256), random(256), random(256), -1.0, 0.26, 2, 6.0, 12.0)
	    		        show_dhudmessage(id, "%s The text when you write the command.",DHUDPrefix)
			}
		}
}

public cmd2(id)
{
		switch(get_pcvar_num(pCvar2))
		{
			case 0: CC_SendMessage(id, "^x04The text when you write the command.")
			case 1:
			{
				set_hudmessage(random(256), random(256), random(256), -1.0, 0.26, 2, 6.0, 12.0)
	    		        show_hudmessage(id, "%s The text when you write the command.",HudPrefix)
    		   }
			case 2:
			{
				set_dhudmessage(random(256), random(256), random(256), -1.0, 0.26, 2, 6.0, 12.0)
	    		        show_dhudmessage(id, "%s The text when you write the command.",DHUDPrefix)
			    }
		}
}
Знам, че плъгина е елементарен, но колкото мога - толкова.

Ако има интерес към плъгина бих му правил ъпдейти с радост.

Formatin библиотеката:

Server Commands v1.0

Публикувано на: 17 Сеп 2018, 18:55
от Huehue
Оправи кода да не е центриран.
Таск-а който си сложил е глобален, демек няма index за играч.
Оправи проверката за кваровете.

Server Commands v1.0

Публикувано на: 06 Окт 2018, 11:29
от illusion
Оправено.
Update!

V1.1 Changelog:

Код за потвърждение: Избери целия код

- Добавени 2 нови константи за командите, които да се пишат в чата.
- Променен е else на switch.
- Добавен е нов define за времето, в което да се показва съобщението за командите в чата (ADVERT_TIME).
- Добавен е prefix в чата (CC_SetPrefix).
- Добавена проверка дали се компилира плъгина под 1.8.3 версия или по-малка (служи за dhudmessage библиотеката).
Благодарности на JackEyedJones.

Скоро ще го оптимизирам още плъгина, за сега е това.

Server Commands v1.2

Публикувано на: 25 Мар 2019, 23:27
от illusion
Update!

V1.2 Changelog:
- Добавена нова команда - /scadvert. С нея може да включвате/изключвате рекламните съобщения в чата. - Добавен е нов cvar за времето (в секунди) през което да се показват рекламните съобщения ( amx_sc_advert_time ).

Server Commands v1.2

Публикувано на: 25 Мар 2019, 23:31
от hackera457

Код за потвърждение: Избери целия код

set_task(get_pcvar_float(cvar_time), "Advert", _,_,_, "b")

public Advert(id)
    if(g_AdvertMessage)
    {
	    CC_SendMessage(0, "^x03Write in the  chat &x01%s &x03or &x01%s &x03to view the commands information&x01.",firstcommand, secondcommand);
    }
Таска за реклама ти е глобален, а ти залагаш като параметър id. От сега ти казвам няма да работи, като е глобален таск, обходи всички играчи и токава задавай съобщението

Код за потвърждение: Избери целия код

if(is_user_connected(id))
Напълно излишно в cmd1 и cmd2

Server Commands v1.2

Публикувано на: 25 Мар 2019, 23:41
от illusion
Така?

Код за потвърждение: Избери целия код

#include <amxmodx>
#include <formatin>
#include <cromchat>
#if AMXX_VERSION_NUM < 183
	#include <dhudmessage>
#endif

// Defines
#define AUTHOR "summertime vibes"
#define VERSION "1.2"

#define HudPrefix "[HUD Prefix]"
#define DHUDPrefix "[DHUD PREFIX]"

#define firstcommand "/command1"
#define secondcommand "/command2"

// New
new pCvar, pCvar2, cvar_time
new bool:g_AdvertMessage = true

// New Const
new const g_iCommand[] = { "/command1" }
new const g_iCommandTwo[] = { "/command2" }
new const g_iCommandAdvert[] = { "/scadvert" }

public plugin_init()
{
	register_plugin("Server Commands", VERSION, AUTHOR)

	for(new i; i<sizeof(g_iCommand); i++)
	{
		register_clcmd(formatin("say %s", g_iCommand[i]), "cmd1")
		register_clcmd(formatin("say_team %s", g_iCommand[i]), "cmd1")
	}

	for(new i; i<sizeof(g_iCommandTwo); i++)
	{
		register_clcmd(formatin("say %s", g_iCommandTwo[i]), "cmd2")
		register_clcmd(formatin("say_team %s", g_iCommandTwo[i]), "cmd2")
	}

	for(new i; i<sizeof(g_iCommandAdvert); i++)
	{
		register_clcmd(formatin("say %s", g_iCommandAdvert[i]), "advertcmd")
		register_clcmd(formatin("say_team %s", g_iCommandAdvert[i]), "advertcmd")
	}

	pCvar = register_cvar("amx_sc_message", "0") // 0 - chat ; 1 - hud ; 2 - dhud
	pCvar2 = register_cvar("amx_sc_message2", "0") // 0 - chat ; 1 - hud ; 2 - dhud
	cvar_time = register_cvar("amx_sc_advert_time", "300.0")

	set_task(get_pcvar_float(cvar_time), "Advert", _,_,_, "b");

	CC_SetPrefix("&x04[Server Commands]")
}

public Advert()
    if(g_AdvertMessage)
    {
	    CC_SendMessage(0, "^x03Write in the  chat &x01%s &x03or &x01%s &x03to view the commands information&x01.",firstcommand, secondcommand);
	    return
    }

public advertcmd(id)
{
	g_AdvertMessage = !g_AdvertMessage
	CC_SendMessage(id, "&x01Advert Messages have been &x03%s&x01.", g_AdvertMessage ? "enabled" : "disabled" );
}	    

public cmd(id)
{
		switch(get_pcvar_num(pCvar))
		{
			case 0: CC_SendMessage(id, "^x04The text when you write the command.")
			case 1:
			{
				set_hudmessage(random(256), random(256), random(256), -1.0, 0.26, 2, 6.0, 12.0)
	    	                show_hudmessage(id, "%s The text when you write the command.",HudPrefix)
    		}
			case 2:
			{
				set_dhudmessage(random(256), random(256), random(256), -1.0, 0.26, 2, 6.0, 12.0)
	    		        show_dhudmessage(id, "%s The text when you write the command.",DHUDPrefix)
			}
		}
}

public cmd2(id)
{
		switch(get_pcvar_num(pCvar2))
		{
			case 0: CC_SendMessage(id, "^x04The text when you write the command.")
			case 1:
			{
				set_hudmessage(random(256), random(256), random(256), -1.0, 0.26, 2, 6.0, 12.0)
	    		        show_hudmessage(id, "%s The text when you write the command.",HudPrefix)
    		   }
			case 2:
			{
				set_dhudmessage(random(256), random(256), random(256), -1.0, 0.26, 2, 6.0, 12.0)
	    		        show_dhudmessage(id, "%s The text when you write the command.",DHUDPrefix)
			    }
		}
}

Server Commands v1.2

Публикувано на: 25 Мар 2019, 23:44
от <VeCo>
Кромчата приема индекс 0 за всички играчи, не е съществен проблем, въпреки, че наистина няма смисъл от id параметър горе, ако не го използваш (и в случая ще е 0 винаги така или иначе).

bool:g_AdvertMessage трябва да ти е масив, защото така който напише командата ще спира съобщенията за всички играчи (но като цяло май няма много смисъл от такава команда).

Също е добре да стартираш таска от plugin_cfg, след като amxx.cfg се е заредил, защото иначе времето няма да се промени на първия мап след стартиране на сървъра.

Код за потвърждение: Избери целия код

#define firstcommand "/command1"
#define secondcommand "/command2"
Тия директиви май са останали от стара версия.

Дай линк към formatin библиотеката в първия пост.

Server Commands v1.2

Публикувано на: 25 Мар 2019, 23:47
от illusion
Да, това с индекса го оправих. Беше с id параметър, защото преди това пробвах едно нещо да направя с плъгина и забравих да махна id.

Ако bool-a трябва да е с масив не трябва ли и advert съобщението да е с id параметър или ?

Това с plugin_cfg ще го оправя.

Server Commands v1.2

Публикувано на: 25 Мар 2019, 23:49
от <VeCo>
summertime vibes написа: 25 Мар 2019, 23:47 Ако bool-a трябва да е с масив не трябва ли и advert съобщението да е с id параметър или ?
Е да, в такъв случай ще ти трябва цикъл да обходиш всички играчи и да им го покажеш през техния индекс.

Server Commands v1.2

Публикувано на: 25 Мар 2019, 23:54
от illusion
Сега малко безсмислен въпрос..

Код за потвърждение: Избери целия код

public plugin_cfg()
{
	set_task(get_pcvar_float(cvar_time), "Advert", _,_,_, "b");
}
Тук има грешка, но не виждам как да я оправя. Plugin_cfg си е без параметър, а advert е с ID.. смисъл така правилно ли е, след като advert ще е с ID или?