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

[TF2] - Test


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Stropy
Senior Member
Join Date: Feb 2016
Old 05-28-2017 , 03:24   [TF2] - Test
Reply With Quote #1

Hello,
I was curious if it is possible to make a test plugin that will automatically lock BLU/RED team, and if the user tries to join one of the locked teams, the plugin would say something like "You didn't pass the test! Type !test to start the test". If the user sucesfully passes the test, the locked team is unlocked to him and he can play freely. If he chooses one answer wrong, the test goes on and in the end it says something like "You had 9 out of 10 correctly" and the user would have to do the whole test again without knowing which answer he chose wrong. The test could be actived by chat trigger, for exapmle !test.

Thanks for any help,
Stropy
Stropy is offline
zyox123cc
Senior Member
Join Date: Jul 2016
Location: spycrab
Old 05-28-2017 , 19:59   Re: [TF2] - Test
Reply With Quote #2

try this
__________________
sv_downloadurl Recommended FREE website
000webhost(File is too big (max. 32MB)! Upload will be skipped.)
rejetto
(Local_computer_host)
Getting material/model paths easy way (Windows)
steam profile
Youtube
zyox123cc is offline
Stropy
Senior Member
Join Date: Feb 2016
Old 05-29-2017 , 08:38   Re: [TF2] - Test
Reply With Quote #3

Quote:
Originally Posted by zyox123cc View Post
It can be used to lock the teams, but the test past is missing, which is quite important for this whole idea/request.
Stropy is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 06-06-2017 , 08:42   Re: [TF2] - Test
Reply With Quote #4

I'm not saying this is a terrible plugin idea but what use is this for?
ThatKidWhoGames is offline
WatchDogs
Senior Member
Join Date: Oct 2015
Location: Iran
Old 06-06-2017 , 09:26   Re: [TF2] - Test
Reply With Quote #5

It's possible but what are the questions?

How many correct answers should player have to unlock the teams ?
WatchDogs is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-06-2017 , 11:59   Re: [TF2] - Test
Reply With Quote #6

You can try this, not tested. My random answer code should be edited to be faster and more efficient.
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>

#pragma newdecls required

#define PLUGIN_AUTHOR     "Arkarr"
#define PLUGIN_VERSION    "1.00"
#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);
    
    
ReadConfigFile();
}

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

public 
Action CMD_TheTest(int clientint args)
{
    if(
questionNumber[client] != 0)
    {
        
PrintToChat(client"[SM] Finish the Test firstly.");
    }
    else
    {
        
questionNumber[client] = 0;
        
HasFailed[client] = false;
        
        
DisplayTheTest(client);
    }
        
    return 
Plugin_Handled;
}

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

    
char answers[10];
    
char answerID[10];
    
    while(
answerAdded != 5)
    {
        
int randomAnswer GetRandomInt(04);
        
IntToString(randomAnsweranswerIDsizeof(answerID));
        while(
StrContains(answersanswerID) != -1)
        {
            
randomAnswer GetRandomInt(04);
            
PrintToServer("%i"answerAdded);
        }
            
        
Format(answerssizeof(answers), "%s%s"answersanswerID);
        
Format(answerIDsizeof(answerID), "answer%s"answerID);
        
GetTrieString(questionInfosanswerIDa1sizeof(a1));
        
        if(!
StrEqual(a1"-"))
        {
            if(
randomAnswer == 1)
                
AddMenuItem(menu"Y"a1);
            else
                
AddMenuItem(menu"N"a1);
        }
        else
        {
            
BlankAnswer++;
        }
        
        
answerAdded++;
    }
        
    while(
BlankAnswer != 0)
    {
        
AddMenuItem(menu"N""-"ITEMDRAW_DISABLED);
        
BlankAnswer--;
    }
    
    
SetMenuExitBackButton(menufalse);
    
DisplayMenu(menuclientMENU_TIME_FOREVER);
}

public 
int MenuHandler_Question(Handle menuMenuAction menuActionint clientint menuItemID)
{
    
char correct[10];
    
GetMenuItem(menumenuItemIDcorrectsizeof(correct));
    
    if(!
StrEqual(correct"Y"))
        
HasFailed[client] = true;
        
    
questionNumber[client]++;
    
    if(
questionNumber[client] < GetArraySize(ARRAY_Questions))
    {
        
DisplayTheTest(client);
    }
    else
    {
        if(
HasFailed[client])
        {
            
PrintToChat(client"Sucess ! You have passed the Test !");
        }
        else
        {
            
PrintToChat(client"Fail ! You didn't passed the Test !");
            
SlapPlayer(client0true);
            
SlapPlayer(client0true);
            
SlapPlayer(client0true);
        }
        
    }
    
    if (
menuAction == MenuAction_End)
        
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)
        {
            
TF2_ChangeClientTeam(clientTFTeam_Blue);
        }
        else if(
team == TFTeam_Blue && BLULocked)
        {
            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-07-2017 , 14:58   Re: [TF2] - Test
Reply With Quote #7

Quote:
Originally Posted by ThatKidWhoGames View Post
I'm not saying this is a terrible plugin idea but what use is this for?
Well, i am running a jailbreak server, and there are tons of new players to the server coming everyday. And since I don't want freekilling players in blu team, this is one of the options to prevent it, atleast to some degree.

Quote:
Originally Posted by WatchDogs View Post
It's possible but what are the questions?

How many correct answers should player have to unlock the teams ?
The best would be if the answers would be configurable - you can have as many as you want, or with limit 10 for example. And all of them should be correct.

Last edited by Stropy; 06-07-2017 at 15:08.
Stropy is offline
Stropy
Senior Member
Join Date: Feb 2016
Old 06-07-2017 , 14:59   Re: [TF2] - Test
Reply With Quote #8

Quote:
Originally Posted by Arkarr View Post
-snip-
I'll try it out and let you know how it works. Thanks for help
Stropy is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-08-2017 , 07:53   Re: [TF2] - Test
Reply With Quote #9

Quote:
Originally Posted by Stropy View Post
I'll try it out and let you know how it works. Thanks for help
I just tested it. Doesn't work properly yet. I failed my random, I'll fix it later.
__________________
Arkarr is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-08-2017 , 13:33   Re: [TF2] - Test
Reply With Quote #10

Tested and worked.
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>

#pragma newdecls required

#define PLUGIN_AUTHOR     "Arkarr"
#define PLUGIN_VERSION    "1.00"
#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);
    
    
ReadConfigFile();
}

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

public 
Action CMD_TheTest(int clientint args)
{
    if(
questionNumber[client] != 0)
    {
        
PrintToChat(client"[SM] Finish the Test firstly.");
    }
    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])
            {
                
PrintToChat(client"Sucess ! You have passed the Test !");
            }
            else
            {
                
PrintToChat(client"Fail ! You didn't passed the Test !");
                
SlapPlayer(client0true);
                
SlapPlayer(client0true);
                
SlapPlayer(client0true);
            }
        }
    }
    else if (
menuAction == MenuAction_End)
    {
        
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)
        {
            
TF2_ChangeClientTeam(clientTFTeam_Blue);
        }
        else if(
team == TFTeam_Blue && BLULocked)
        {
            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);

Create a config file configs/TheTest.cfg and insert that code :
PHP Code:
"Questions"
{
    
"Select the number '1'"
    
{
        
"answer1"     "1"
        "answer2"     "3" 
        "answer3"    "5432"
        "answer4"    "5"
        "answer5"    "6"
    
}
    
"Select the number '2'"
    
{
        
"answer1"     "2"
        "answer2"     "3" 
        "answer3"    "1"
        "answer4"    "5"
        "answer5"    "6"
    
}
    
    
"Select the number '3'"
    
{
        
"answer1"     "3"
        "answer2"     "4" 
        "answer3"    "1"
        "answer4"    "5"
        "answer5"    "6"
    
}

The first answer (answer1) is the correct one. Answers are randomized each time in the menu.

Have fun !
__________________
Arkarr 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 16:10.


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