Raised This Month: $51 Target: $400
 12% 

question plugin bugged


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
The RaiD.
Member
Join Date: Jul 2019
Old 09-25-2020 , 13:34   question plugin bugged
Reply With Quote #1

I need help with this plugin if i ask a question and someone write the right answer its not detect (always) the right answer? i dont know why?! Sometimes it works sometimes its not work
Code:
#include <amxmodx>
#include <regex>
#include <WPMGPrintChatColor>

#define VERSION "1.0"

#define TASKID_QUEST 123

new const g_szRegexPattern[] = "\/quest (.+?\?)\s*(.+)";
new Regex:g_QuestRegexPattern;

new g_szUserQuestion[33][128], g_szUserAnswer[33][32];
new g_szQuestion[128], g_szAnswer[32];

new gp_QuestHoldTime;
new g_iUnused, g_szUnused[2];

public plugin_init()
{
	register_plugin("Admin Question", VERSION, "AMXX-BG.info");
	register_cvar("admin_quest", VERSION, FCVAR_SPONLY | FCVAR_SERVER | FCVAR_UNLOGGED);
	
	register_clcmd("say", "CommandSayTyped");

	register_clcmd("Question", "QuestionTyped");
	register_clcmd("Answer", "AnswerTyped");

	gp_QuestHoldTime = register_cvar("quest_holdtime", "20");

	g_QuestRegexPattern = regex_compile(g_szRegexPattern, g_iUnused, g_szUnused, charsmax(g_szUnused));
}

public QuestionTyped(id, lvl, cmdId)
{
	if (!get_user_flags(id) & ADMIN_IMMUNITY)
	{
		return PLUGIN_CONTINUE;
	}
	if (read_argc() < 2)
	{
		return PLUGIN_HANDLED;
	}

	read_args(g_szUserQuestion[id], charsmax(g_szUserQuestion[]));
	remove_quotes(g_szUserQuestion[id]);
	ShowQuestMenu(id);

	return PLUGIN_HANDLED;
}

public AnswerTyped(id)
{
	if (read_argc() < 2)
	{
		return PLUGIN_HANDLED;
	}

	read_args(g_szUserAnswer[id], charsmax(g_szUserAnswer[]));
	remove_quotes(g_szUserAnswer[id]);
	ShowQuestMenu(id);

	return PLUGIN_HANDLED;
}

public CommandSayTyped(id)
{
	new szSaid[156];
	read_args(szSaid, charsmax(szSaid));
	remove_quotes(szSaid);

	if (equali(szSaid, "/quest", 6))
	{
		if (!get_user_flags(id) & ADMIN_IMMUNITY)
		{
			return PLUGIN_HANDLED;
		}

		if (regex_match_c(szSaid, g_QuestRegexPattern, g_iUnused) > 0)
		{
			new szQuestion[128], szAnswer[32];
			regex_substr(g_QuestRegexPattern, 1, szQuestion, charsmax(szQuestion));
			regex_substr(g_QuestRegexPattern, 2, szAnswer, charsmax(szAnswer));

			trim(szQuestion);
			trim(szAnswer);

			StartQuest(id, szQuestion, szAnswer);
		}
		else
		{
			ShowQuestMenu(id);
		}

		return PLUGIN_HANDLED;
	}

	if (!task_exists(TASKID_QUEST))
	{
		return PLUGIN_CONTINUE;
	}

	if (equali(szSaid, g_szAnswer) && get_user_team(id) == 1 && is_user_alive(id))
	{
		EndQuest(TASKID_QUEST + id);
	}

	return PLUGIN_CONTINUE;
}

ShowQuestMenu(id)
{
	new iMenu = menu_create("Quest Game", "QuestGameHandler");

	new szQuestionItem[156], szAnswerItem[64];
	formatex(szQuestionItem, charsmax(szQuestionItem), "Question \y%s", g_szUserQuestion[id]);
	formatex(szAnswerItem, charsmax(szAnswerItem), "Answer \y%s", g_szUserAnswer[id]);

	menu_additem(iMenu, szQuestionItem);
	menu_additem(iMenu, szAnswerItem);
	menu_addblank(iMenu, 0);
	menu_additem(iMenu, "Start the quest");

	menu_display(id, iMenu);
}

public QuestGameHandler(id, iMenu, Item)
{
	if (Item == MENU_EXIT)
	{
		menu_destroy(iMenu);
		return;
	}

	switch (Item)
	{
		case 0: client_cmd(id, "messagemode Question");
		case 1: client_cmd(id, "messagemode Answer");
		case 2:
		{
			StartQuest(id, g_szUserQuestion[id], g_szUserAnswer[id]);
			menu_destroy(iMenu);
			return;
		}
	}

	menu_destroy(iMenu);
	ShowQuestMenu(id);
}

StartQuest(id, szQuestion[], szAnswer[])
{
	if (strlen(szQuestion) == 0 || strlen(szAnswer) == 0)
	{
		PrintChatColor(id, PRINT_COLOR_PLAYERTEAM, "!g[!tQuest!g]!y You must type a valid question and answer in order to start the game!");
		return;
	}

	copy(g_szQuestion, charsmax(g_szQuestion), szQuestion);
	copy(g_szAnswer, charsmax(g_szAnswer), szAnswer);

	copy(g_szUserAnswer[id], charsmax(g_szUserAnswer[]), "");
	copy(g_szUserQuestion[id], charsmax(g_szUserQuestion[]), "");

	new szName2[32]
	get_user_name(id, szName2, charsmax(szName2))

	PrintChatColor(0, PRINT_COLOR_PLAYERTEAM, "!g[!tQuest!g]!y Admin !g%s !ystarted the quest game! You have !t%d seconds !yto answer the question!", szName2, get_pcvar_num(gp_QuestHoldTime));
	PrintChatColor(0, PRINT_COLOR_PLAYERTEAM, "!g[!tQuest!g]!y Question: !g%s", g_szQuestion);

	set_task(get_pcvar_float(gp_QuestHoldTime), "EndQuest", TASKID_QUEST);
}

public EndQuest(taskid)
{
	new id = taskid - TASKID_QUEST;

	if (!is_user_connected(id))
	{
		PrintChatColor(0, PRINT_COLOR_PLAYERTEAM, "!g[!tQuest!g]!y No one answered the question. The answer is!t %s", g_szAnswer);
	}
	else
	{
		new szName[32];
		get_user_name(id, szName, charsmax(szName));
		PrintChatColor(0, PRINT_COLOR_PLAYERTEAM, "!g[!tQuest!g]!g %s!y has won the game! The answer is!t %s", szName, g_szAnswer);
	}

	copy(g_szAnswer, charsmax(g_szAnswer), "");
	copy(g_szQuestion, charsmax(g_szQuestion), "");

	remove_task(TASKID_QUEST);
}
The RaiD. is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 09-25-2020 , 14:57   Re: question plugin bugged
Reply With Quote #2

Check error log file
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-25-2020 , 23:50   Re: question plugin bugged
Reply With Quote #3

What doesn't work? Are there any errors? Please describe your problem with as many details as possible. Also, it is always advised to first ask the author of the plugin since they know it the best.
__________________
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:42.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode