Raised This Month: $28 Target: $400
 7% 

[TF2] - Test


Post New Thread Reply   
 
Thread Tools Display Modes
Stropy
Senior Member
Join Date: Feb 2016
Old 06-08-2017 , 15:56   Re: [TF2] - Test
Reply With Quote #11

Nice! I'll test it asap. Just a question, does it save SteamIDs which already paassed the test or user has to pass the test on each connect?
Stropy is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-08-2017 , 16:29   Re: [TF2] - Test
Reply With Quote #12

You didn't mentiond that before. Also this feature Will require a database. The local one can be usued through. Maybe I'll do it tomorow.

EDIT: I forgot to say that you don't need to specify 5 possible answers. At least one is required, 5 is the max.
__________________

Last edited by Arkarr; 06-08-2017 at 16:33.
Arkarr is offline
Stropy
Senior Member
Join Date: Feb 2016
Old 06-09-2017 , 04:34   Re: [TF2] - Test
Reply With Quote #13

Quote:
Originally Posted by Arkarr View Post
You didn't mentiond that before. Also this feature Will require a database. The local one can be usued through. Maybe I'll do it tomorow.

EDIT: I forgot to say that you don't need to specify 5 possible answers. At least one is required, 5 is the max.
Oh, sorry. Hope it is not a big problem.
I found an issue - when player goes trough the test and the round ends during the test, the menu is closed. If the user wants to make the test again, it writes "Finish the test.." and he has to reconnect to be able to do it again.
Also, can you add a message which is displayed when player (who didn't pass the test) joins the locked team so he knows what to do?

Last edited by Stropy; 06-09-2017 at 04:46.
Stropy is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-09-2017 , 05:30   Re: [TF2] - Test
Reply With Quote #14

Meh.... don't feel like doing SQL now.
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>
#include <multicolors>

#pragma newdecls required

#define PLUGIN_AUTHOR     "Arkarr"
#define PLUGIN_VERSION    "1.00"
#define PLUGIN_TAG        "{yellow}[The Test]{default}"
#define FIELD_QUESTION    "question"
#define FIELD_ANSWER1    "answer1"
#define FIELD_ANSWER2    "answer2"
#define FIELD_ANSWER3    "answer3"
#define FIELD_ANSWER4    "answer4"
#define FIELD_ANSWER5    "answer5"

Handle ARRAY_Questions;
Handle CVAR_LockedTeam;

bool REDLocked;
bool BLULocked;
bool HasFailed[MAXPLAYERS 1];

char question[100];
char a1[100];
char a2[100];
char a3[100];
char a4[100];
char a5[100];

int questionNumber[MAXPLAYERS 1];

public 
Plugin myinfo 
{
    
name "[TF2] The Test",
    
author PLUGIN_AUTHOR,
    
description "Make player pass a test to unlock a team.",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net"
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_test"CMD_TheTest"Pop the menu with the Test.");
    
    
CVAR_LockedTeam CreateConVar("sm_thetest_lockedteam""RED""Set wich team are locked until a player complete the test. Valid value : RED or RED,BLU or BLU");

    
HookEvent("player_spawn"EVENT_TeamChangeEventHookMode_Post);
}

public 
void OnConfigsExecuted()
{
    
char lockedTeams[45];
    
GetConVarString(CVAR_LockedTeamlockedTeamssizeof(lockedTeams));
    
    
REDLocked = (StrContains(lockedTeams"RED") == -false true);
    
BLULocked = (StrContains(lockedTeams"BLU") == -false true);
    
    for (
int i 0MAXPLAYERS 1i++)
        
HasFailed[i] = true;
    
    
ReadConfigFile();
}

public 
void OnClientConnected(int client)
{
    
HasFailed[client] = true;
    
questionNumber[client] = 0;
}

public 
Action CMD_TheTest(int clientint args)
{
    if(
client == 0)
    {
        
CPrintToChat(client"%s In game command only !""[SM]");
        return 
Plugin_Handled;
    }

    if(
questionNumber[client] != 0)
    {
        
CPrintToChat(client"%s Finish the Test firstly."PLUGIN_TAG);
    }
    else
    {
        
questionNumber[client] = 0;
        
HasFailed[client] = false;
        
        
DisplayTheTest(client);
    }
        
    return 
Plugin_Handled;
}

public 
void DisplayTheTest(int client)
{
    
Handle menu CreateMenu(MenuHandler_Question);
    
Handle questionInfos GetArrayCell(ARRAY_QuestionsquestionNumber[client]);
    
    
GetTrieString(questionInfosFIELD_QUESTIONquestionsizeof(question));
        
    
SetMenuTitle(menuquestion);

    
int blank 5;
    
char answer[45];
    
char answerID[10];
    
int answerCount 0;
    

    
int randomAnswer GetRandomInt(04);
    while(
answerCount != 5)
    {
        
IntToString(randomAnswer+1answerIDsizeof(answerID));
            
        
Format(answerIDsizeof(answerID), "answer%s"answerID);
        
GetTrieString(questionInfosanswerIDanswersizeof(answer));
        
        if(!
StrEqual(answer"-"))
        {
            if(
randomAnswer == 0)
                
AddMenuItem(menu"Y"answer);
            else
                
AddMenuItem(menu"N"answer);
            
            
blank--;
        }
        
        
randomAnswer++;
        if(
randomAnswer 4)
            
randomAnswer 0;
            
        
answerCount++;
    }
    
    while(
blank 0)
    {
        
AddMenuItem(menu"N""-"ITEMDRAW_DISABLED);
        
blank--;
    }

    
SetMenuExitBackButton(menufalse);
    
DisplayMenu(menuclientMENU_TIME_FOREVER);
}

public 
int MenuHandler_Question(Handle menuMenuAction menuActionint clientint menuItemID)
{
    if(
menuAction == MenuAction_Select)
    {
        
char correct[10];
        
GetMenuItem(menumenuItemIDcorrectsizeof(correct));

        if(!
StrEqual(correct"Y"))
            
HasFailed[client] = true;
            
        
questionNumber[client]++;
        
        if(
questionNumber[client] < GetArraySize(ARRAY_Questions))
        {
            
DisplayTheTest(client);
        }
        else
        {
            
questionNumber[client] = 0;
            if(!
HasFailed[client])
            {
                
CPrintToChat(client"%s Sucess ! You have passed the Test !"PLUGIN_TAG);
            }
            else
            {
                
CPrintToChat(client"%s Fail ! You didn't passed the Test !"PLUGIN_TAG);
                
SlapPlayer(client0true);
                
SlapPlayer(client0true);
                
SlapPlayer(client0true);
            }
        }
    }
    else if (
menuAction == MenuAction_End)
    {
        
questionNumber[client] = 0;
        
CloseHandle(menu);
    }
}

public 
Action EVENT_TeamChange(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
TFTeam team TF2_GetClientTeam(client);

    if(
client && HasFailed[client] && IsClientInGame(client) && !IsFakeClient(client) && (team == TFTeam_Red || team == TFTeam_Blue))
    {
        if(
team == TFTeam_Red && REDLocked)
        {
            
CPrintToChat(client"%s {green}You have to finish the test firstly ! Use {red}!test{green} !"PLUGIN_TAG);
            
TF2_ChangeClientTeam(clientTFTeam_Blue);
        }
        else if(
team == TFTeam_Blue && BLULocked)
        {
            
CPrintToChat(client"%s {green}You have to finish the test firstly ! Use {red}!test{green} !"PLUGIN_TAG);

            if(
REDLocked)
                
TF2_ChangeClientTeam(clientTFTeam_Spectator);
            else
                
TF2_ChangeClientTeam(clientTFTeam_Red);
        }
    }
}

stock bool ReadConfigFile()
{
    
ARRAY_Questions CreateArray();
    
    
char path[100];
    
Handle kv CreateKeyValues("Questions");
    
BuildPath(Path_SMpathsizeof(path), "/configs/TheTest.cfg");
    
FileToKeyValues(kvpath);
    
    if (!
KvGotoFirstSubKey(kv))
        return;
    
    do
    {
        
KvGetSectionName(kvquestionsizeof(question));
        
KvGetString(kvFIELD_ANSWER1a1sizeof(a1), "-");
        
KvGetString(kvFIELD_ANSWER2a2sizeof(a2), "-");
        
KvGetString(kvFIELD_ANSWER3a3sizeof(a3), "-");
        
KvGetString(kvFIELD_ANSWER4a4sizeof(a4), "-");
        
KvGetString(kvFIELD_ANSWER5a5sizeof(a5), "-");
        
        
Handle tmpTrie CreateTrie();
        
SetTrieString(tmpTrieFIELD_QUESTIONquestionfalse);
        
SetTrieString(tmpTrieFIELD_ANSWER1a1false);
        
SetTrieString(tmpTrieFIELD_ANSWER2a2false);
        
SetTrieString(tmpTrieFIELD_ANSWER3a3false);
        
SetTrieString(tmpTrieFIELD_ANSWER4a4false);
        
SetTrieString(tmpTrieFIELD_ANSWER5a5false);
        
        
PushArrayCell(ARRAY_QuestionstmpTrie);
    } while (
KvGotoNextKey(kv));
    
    
CloseHandle(kv);

__________________
Arkarr is offline
Stropy
Senior Member
Join Date: Feb 2016
Old 06-26-2017 , 10:54   Re: [TF2] - Test
Reply With Quote #15

Still bugs a bit when the round finishes during the test. Any progress on the database? (Sorry if I am annonying)

E: Also, the push on test failed can be easily abused to get to some places

Last edited by Stropy; 06-26-2017 at 11:02.
Stropy is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-29-2017 , 05:17   Re: [TF2] - Test
Reply With Quote #16

Hopefully all bugs are fixed. Also, I added a way to save test results. A bad way, but it should work.
Not tested as I don't have a PC nor a server now.

I would appreciate to know if it works.

PHP Code:
#include <sourcemod> 
#include <sdktools> 
#include <tf2> 
#include <tf2_stocks> 
#include <morecolors> 
#include <clientprefs>

#pragma newdecls required 

#define PLUGIN_AUTHOR     "Arkarr" 
#define PLUGIN_VERSION    "1.00" 
#define PLUGIN_TAG        "{yellow}[The Test]{default}" 
#define FIELD_QUESTION    "question" 
#define FIELD_ANSWER1    "answer1" 
#define FIELD_ANSWER2    "answer2" 
#define FIELD_ANSWER3    "answer3" 
#define FIELD_ANSWER4    "answer4" 
#define FIELD_ANSWER5    "answer5" 

Handle ARRAY_Questions;
Handle CVAR_LockedTeam;
Handle COOKIE_TestPassed;

bool REDLocked;
bool BLULocked;
bool HasFailed[MAXPLAYERS 1];

char question[100];
char a1[100];
char a2[100];
char a3[100];
char a4[100];
char a5[100];

int questionNumber[MAXPLAYERS 1];

public 
Plugin myinfo 
{
    
name "[TF2] The Test"
    
author PLUGIN_AUTHOR
    
description "Make player pass a test to unlock a team."
    
version PLUGIN_VERSION
    
url "http://www.sourcemod.net"
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_test"CMD_TheTest"Pop the menu with the Test.");
    
    
CVAR_LockedTeam CreateConVar("sm_thetest_lockedteam""RED""Set wich team are locked until a player complete the test. Valid value : RED or RED,BLU or BLU");
    
COOKIE_TestPassed RegClientCookie("TestPassed""Define if the user have passed the test or not."CookieAccess_Private);
    
    
HookEvent("player_spawn"EVENT_TeamChangeEventHookMode_Post);
    
HookEvent("teamplay_round_win"EVENT_RoundEnd);
    
    for (
int i MaxClients0; --i)
    {
        if (!
AreClientCookiesCached(i))
        {
            continue;
        }
        
        
OnClientCookiesCached(i);
    }
}

public 
void OnClientCookiesCached(int client)
{
    
char sValue[8];
    
GetClientCookie(clientCOOKIE_TestPassedsValuesizeof(sValue));
    
    
HasFailed[client] = !(sValue[0] != '\0' && StringToInt(sValue));
}  

public 
void OnConfigsExecuted()
{
    
char lockedTeams[45];
    
GetConVarString(CVAR_LockedTeamlockedTeamssizeof(lockedTeams));
    
    
REDLocked = (StrContains(lockedTeams"RED") == -false true);
    
BLULocked = (StrContains(lockedTeams"BLU") == -false true);
    
    for (
int i 0MAXPLAYERS 1i++)
    
HasFailed[i] = true;
    
    
ReadConfigFile();
}

public 
void OnClientConnected(int client)
{
    
HasFailed[client] = true;
    
questionNumber[client] = 0;
}

public 
Action CMD_TheTest(int clientint args)
{
    if (
client == 0)
    {
        
CPrintToChat(client"%s In game command only !""[SM]");
        return 
Plugin_Handled;
    }
    
    if (
questionNumber[client] != 0)
    {
        
CPrintToChat(client"%s Finish the Test firstly."PLUGIN_TAG);
    }
    else
    {
        
questionNumber[client] = 0;
        
HasFailed[client] = false;
        
        
DisplayTheTest(client);
    }
    
    return 
Plugin_Handled;
}

public 
void DisplayTheTest(int client)
{
    
Handle menu CreateMenu(MenuHandler_Question);
    
Handle questionInfos GetArrayCell(ARRAY_QuestionsquestionNumber[client]);
    
    
GetTrieString(questionInfosFIELD_QUESTIONquestionsizeof(question));
    
    
SetMenuTitle(menuquestion);
    
    
int blank 5;
    
char answer[45];
    
char answerID[10];
    
int answerCount 0;
    
    
    
int randomAnswer GetRandomInt(04);
    while (
answerCount != 5)
    {
        
IntToString(randomAnswer 1answerIDsizeof(answerID));
        
        
Format(answerIDsizeof(answerID), "answer%s"answerID);
        
GetTrieString(questionInfosanswerIDanswersizeof(answer));
        
        if (!
StrEqual(answer"-"))
        {
            if (
randomAnswer == 0)
                
AddMenuItem(menu"Y"answer);
            else
                
AddMenuItem(menu"N"answer);
            
            
blank--;
        }
        
        
randomAnswer++;
        if (
randomAnswer 4)
            
randomAnswer 0;
        
        
answerCount++;
    }
    
    while (
blank 0)
    {
        
AddMenuItem(menu"N""-"ITEMDRAW_DISABLED);
        
blank--;
    }
    
    
SetMenuExitBackButton(menufalse);
    
DisplayMenu(menuclientMENU_TIME_FOREVER);
}

public 
int MenuHandler_Question(Handle menuMenuAction menuActionint clientint menuItemID)
{
    if (
menuAction == MenuAction_Select)
    {
        
char correct[10];
        
GetMenuItem(menumenuItemIDcorrectsizeof(correct));
        
        if (!
StrEqual(correct"Y"))
            
HasFailed[client] = true;
        
        
questionNumber[client]++;
        
        if (
questionNumber[client] < GetArraySize(ARRAY_Questions))
        {
            
DisplayTheTest(client);
        }
        else
        {
            
questionNumber[client] = 0;
            if (!
HasFailed[client])
            {
                
CPrintToChat(client"%s Sucess ! You have passed the Test !"PLUGIN_TAG);
                
SetClientCookie(clientCOOKIE_TestPassed"1");
            }
            else
            {
                
CPrintToChat(client"%s Fail ! You didn't passed the Test !"PLUGIN_TAG);
                while(
IsPlayerAlive(client))
                    
SlapPlayer(client20);
            }
        }
    }
    else if (
menuAction == MenuAction_End)
    {
        
questionNumber[client] = 0;
        
CloseHandle(menu);
    }
}

public 
Action EVENT_RoundEnd(Handle event, const char[] namebool dontBroadcast)
{
    for (
int i 0MAXPLAYERS 1i++)
    
questionNumber[i] = true;
}

public 
Action EVENT_TeamChange(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
TFTeam team TF2_GetClientTeam(client);
    
    if (
client && HasFailed[client] && IsClientInGame(client) && !IsFakeClient(client) && (team == TFTeam_Red || team == TFTeam_Blue))
    {
        if (
team == TFTeam_Red && REDLocked)
        {
            
CPrintToChat(client"%s {green}You have to finish the test firstly ! Use {red}!test{green} !"PLUGIN_TAG);
            
TF2_ChangeClientTeam(clientTFTeam_Blue);
        }
        else if (
team == TFTeam_Blue && BLULocked)
        {
            
CPrintToChat(client"%s {green}You have to finish the test firstly ! Use {red}!test{green} !"PLUGIN_TAG);
            
            if (
REDLocked)
                
TF2_ChangeClientTeam(clientTFTeam_Spectator);
            else
                
TF2_ChangeClientTeam(clientTFTeam_Red);
        }
    }
}

stock bool ReadConfigFile()
{
    
ARRAY_Questions CreateArray();
    
    
char path[100];
    
Handle kv CreateKeyValues("Questions");
    
BuildPath(Path_SMpathsizeof(path), "/configs/TheTest.cfg");
    
FileToKeyValues(kvpath);
    
    if (!
KvGotoFirstSubKey(kv))
        return;
    
    do
    {
        
KvGetSectionName(kvquestionsizeof(question));
        
KvGetString(kvFIELD_ANSWER1a1sizeof(a1), "-");
        
KvGetString(kvFIELD_ANSWER2a2sizeof(a2), "-");
        
KvGetString(kvFIELD_ANSWER3a3sizeof(a3), "-");
        
KvGetString(kvFIELD_ANSWER4a4sizeof(a4), "-");
        
KvGetString(kvFIELD_ANSWER5a5sizeof(a5), "-");
        
        
Handle tmpTrie CreateTrie();
        
SetTrieString(tmpTrieFIELD_QUESTIONquestionfalse);
        
SetTrieString(tmpTrieFIELD_ANSWER1a1false);
        
SetTrieString(tmpTrieFIELD_ANSWER2a2false);
        
SetTrieString(tmpTrieFIELD_ANSWER3a3false);
        
SetTrieString(tmpTrieFIELD_ANSWER4a4false);
        
SetTrieString(tmpTrieFIELD_ANSWER5a5false);
        
        
PushArrayCell(ARRAY_QuestionstmpTrie);
    } while (
KvGotoNextKey(kv));
    
    
CloseHandle(kv);

__________________

Last edited by Arkarr; 06-29-2017 at 05:17.
Arkarr is offline
Stropy
Senior Member
Join Date: Feb 2016
Old 06-29-2017 , 08:48   Re: [TF2] - Test
Reply With Quote #17

Will check right now, thank you.
Stropy is offline
Stropy
Senior Member
Join Date: Feb 2016
Old 06-29-2017 , 09:15   Re: [TF2] - Test
Reply With Quote #18

After passing the test, I can still open the test, then, if I fail, it kicks me out from locked team. After joining the server back it is okay and lets me join, because I passed the test before
The bug on round end still persists - test kicks me from locked team, I start going trough the test, and then, when the win panel is shown, If I press any question, the menu goes away and then - You have to finish the firstly. Also, the finish the test firstly is global to all players.
Stropy is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-29-2017 , 09:47   Re: [TF2] - Test
Reply With Quote #19

Quote:
Originally Posted by Stropy View Post
After passing the test, I can still open the test, then, if I fail, it kicks me out from locked team. After joining the server back it is okay and lets me join, because I passed the test before
The bug on round end still persists - test kicks me from locked team, I start going trough the test, and then, when the win panel is shown, If I press any question, the menu goes away and then - You have to finish the firstly. Also, the finish the test firstly is global to all players.
Well.... I'll check that later. In about 3 weeks.
__________________
Arkarr is offline
PBFliX
Member
Join Date: Apr 2017
Location: United Kingdom
Old 06-29-2017 , 10:04   Re: [TF2] - Test
Reply With Quote #20

Quote:
Originally Posted by Stropy View Post
After passing the test, I can still open the test, then, if I fail, it kicks me out from locked team. After joining the server back it is okay and lets me join, because I passed the test before
The bug on round end still persists - test kicks me from locked team, I start going trough the test, and then, when the win panel is shown, If I press any question, the menu goes away and then - You have to finish the firstly. Also, the finish the test firstly is global to all players.
If you want people to be stopped from joining blue if they repeat the test and fail just change these lines to this
Code:
            questionNumber[client] = 0;
            if (!HasFailed[client])
            {
                CPrintToChat(client, "%s Sucess ! You have passed the Test !", PLUGIN_TAG);
                SetClientCookie(client, COOKIE_TestPassed, "1");
            }
            else
            {
                CPrintToChat(client, "%s Fail ! You didn't passed the Test !", PLUGIN_TAG);
                SetClientCookie(client, COOKIE_TestPassed, "0");
                while(IsPlayerAlive(client))
                    SlapPlayer(client, 20);
            }
__________________

Last edited by PBFliX; 06-29-2017 at 10:04. Reason: Can't tab, it posted it.
PBFliX is offline
Reply


Thread Tools
Display Modes

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 06:47.


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