AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   [TF2] - Test (https://forums.alliedmods.net/showthread.php?t=297943)

Stropy 05-28-2017 03:24

[TF2] - Test
 
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

zyox123cc 05-28-2017 19:59

Re: [TF2] - Test
 
try this

Stropy 05-29-2017 08:38

Re: [TF2] - Test
 
Quote:

Originally Posted by zyox123cc (Post 2524335)

It can be used to lock the teams, but the test past is missing, which is quite important for this whole idea/request.

ThatKidWhoGames 06-06-2017 08:42

Re: [TF2] - Test
 
I'm not saying this is a terrible plugin idea but what use is this for?

WatchDogs 06-06-2017 09:26

Re: [TF2] - Test
 
It's possible but what are the questions?

How many correct answers should player have to unlock the teams ?

Arkarr 06-06-2017 11:59

Re: [TF2] - Test
 
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);



Stropy 06-07-2017 14:58

Re: [TF2] - Test
 
Quote:

Originally Posted by ThatKidWhoGames (Post 2526553)
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 (Post 2526567)
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.

Stropy 06-07-2017 14:59

Re: [TF2] - Test
 
Quote:

Originally Posted by Arkarr (Post 2526597)
-snip-

I'll try it out and let you know how it works. Thanks for help

Arkarr 06-08-2017 07:53

Re: [TF2] - Test
 
Quote:

Originally Posted by Stropy (Post 2526897)
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 06-08-2017 13:33

Re: [TF2] - Test
 
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 !


All times are GMT -4. The time now is 03:39.

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