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

Editing a plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
weeeishy
Senior Member
Join Date: Jul 2015
Location: Kuwait
Old 07-26-2016 , 07:23   Editing a plugin
Reply With Quote #1

Hello,


I'm currently using this JailShop https://forums.alliedmods.net/showthread.php?t=247917


It would be awesome if someone could modify this math credits plugin by arkarr to make it compatible with the shop version above.

https://forums.alliedmods.net/showthread.php?t=264848

Thank you!
__________________

Last edited by weeeishy; 07-26-2016 at 07:23.
weeeishy is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 07-26-2016 , 12:57   Re: Editing a plugin
Reply With Quote #2

OK.

EDIT:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <clientprefs>
#include <scp>

#define PLUGIN_NAME         "[ANY] Math Credits"
#define PLUGIN_DESCRIPTION     "Give credits on correct math answer."
#define PLUGIN_AUTHOR         "Arkarr"
#define PLUGIN_VERSION         "1.00"
#define PLUGIN_TAG            "[QUIZZ]"
#define PLUS                "+"
#define MINUS                "-"
#define DIVISOR                "/"
#define MULTIPL                "*"

bool inQuizz;
bool pluginEnabled;

char op[32];
char operators[4][2] = {"+""-""/""*"};

int nbrmin;
int nbrmax;
int credits;
int maxcredits;
int mincredits;
int questionResult;

Handle timerQuestionEnd;

Handle COOKIE_Credit;

Handle CVAR_MinimumNumber;
Handle CVAR_MaximumNumber;
Handle CVAR_MaximumCredits;
Handle CVAR_MinimumCredits;
Handle CVAR_TimeBetweenQuestion;
Handle CVAR_TimeAnswer;

public 
Plugin myinfo 
{
    
name PLUGIN_NAME,
    
author PLUGIN_AUTHOR,
    
description PLUGIN_DESCRIPTION,
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net"
};

public 
void OnPluginStart()
{
    
inQuizz false;
    
    
CVAR_MinimumNumber CreateConVar("sm_MathCredits_minimum_number""1""What should be the minimum number for questions ?");
    
CVAR_MaximumNumber CreateConVar("sm_MathCredits_maximum_number""100""What should be the maximum number for questions ?");
    
CVAR_MaximumCredits CreateConVar("sm_MathCredits_maximum_credits""50""What should be the maximum number of credits earned for a correct answers ?");
    
CVAR_MinimumCredits CreateConVar("sm_MathCredits_minimum_credits""5""What should be the minimum number of credits earned for a correct answers ?");
    
CVAR_TimeBetweenQuestion CreateConVar("sm_MathCredits_time_between_questions""50""Time in seconds between each questions.");
    
CVAR_TimeAnswer CreateConVar("sm_MathCredits_time_answer_questions""10""Time in seconds to give a answer to a question.");
    
    
COOKIE_Credit FindClientCookie("Creditos");
    
    if(
COOKIE_Credit == INVALID_HANDLE)
    {
        
SetFailState("JailShop not found ! Plugin disabled ! Required Plugin : https://forums.alliedmods.net/showthread.php?t=247917");
        
pluginEnabled false;
    }
    
    
AutoExecConfig(true"MathCredits");
}

public 
void OnMapStart()
{
    if(
pluginEnabled)
        
CreateTimer(GetConVarFloat(CVAR_TimeBetweenQuestion) + GetConVarFloat(CVAR_TimeAnswer), CreateQuestion_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public 
void OnConfigsExecuted()
{
    
nbrmin GetConVarInt(CVAR_MinimumNumber);
    
nbrmax GetConVarInt(CVAR_MaximumNumber);
    
maxcredits GetConVarInt(CVAR_MaximumCredits);
    
mincredits GetConVarInt(CVAR_MinimumCredits);    
}

public 
Action EndQuestion(Handle timer)
{
    
SendEndQuestion(-1);
}

public 
Action CreateQuestion(Handle timer)
{
    
int nbr1 GetRandomInt(nbrminnbrmax);
    
int nbr2 GetRandomInt(nbrminnbrmax);
    
credits GetRandomInt(mincreditsmaxcredits);
    
    
Format(opsizeof(op), operators[GetRandomInt(0,3)]);
    
    if(
StrEqual(opPLUS))
    {
        
questionResult nbr1 nbr2;
    }
    else if(
StrEqual(opMINUS))
    {
        
questionResult nbr1 nbr2;
    }
    else if(
StrEqual(opDIVISOR))
    {
        do{
            
nbr1 GetRandomInt(nbrminnbrmax);
            
nbr2 GetRandomInt(nbrminnbrmax);
        }while(
nbr1 nbr2 != 0);
        
questionResult nbr1 nbr2;
    }
    else if(
StrEqual(opMULTIPL))
    {
        
questionResult nbr1 nbr2;
    }
    
    
PrintToChatAll("%s %i %s %i = ? >>>%i credits<<<"PLUGIN_TAGnbr1opnbr2credits);
    
inQuizz true;
    
    
timerQuestionEnd CreateTimer(GetConVarFloat(CVAR_TimeAnswer), EndQuestion);
}

public 
Action OnChatMessage(&authorHandle recipientschar[] namechar[] message)
{
    if(
inQuizz)
    {
        
char bit[1][5];
        
ExplodeString(message" "bitsizeof bitsizeof bit[]);

        if(
ProcessSolution(authorStringToInt(bit[0])))
            
SendEndQuestion(author);
    }
}

public 
bool ProcessSolution(clientint number)
{
    if(
questionResult == number)
    {        
        
char strValue[10];
        
GetClientCookie(clientCOOKIE_CreditstrValuesizeof(strValue));
        
        
Format(strValuesizeof(strValue), "%i"credits StringToInt(strValue));
        
        
SetClientCookie(clientCOOKIE_CreditstrValue);
        
        return 
true;
    }
    else
    {
        return 
false;
    }
}

public 
void SendEndQuestion(int client)
{
    if(
timerQuestionEnd != INVALID_HANDLE)
    {
        
KillTimer(timerQuestionEnd);
        
timerQuestionEnd INVALID_HANDLE;
    }
    
    
char answer[100];
    
    if(
client != -1)
        
Format(answersizeof(answer), "%s %N has given a correct answer and got +%i credits !"PLUGIN_TAGclientcredits);
    else
        
Format(answersizeof(answer), "%s Time end ! No answer."PLUGIN_TAG);
        
    
Handle pack CreateDataPack();
    
CreateDataTimer(0.3AnswerQuestionpack);
    
WritePackString(packanswer);
    
    
inQuizz false;
}

public 
Action AnswerQuestion(Handle timerHandle pack)
{
    
char str[100];
    
ResetPack(pack);
    
ReadPackString(packstrsizeof(str));
 
    
PrintToChatAll(str);

Not tested through.
__________________
Want to check my plugins ?

Last edited by Arkarr; 07-26-2016 at 13:51.
Arkarr is offline
weeeishy
Senior Member
Join Date: Jul 2015
Location: Kuwait
Old 07-26-2016 , 16:19   Re: Editing a plugin
Reply With Quote #3

Quote:
Originally Posted by Arkarr View Post
OK.

EDIT:
Code:
PHP Code:
#include <sourcemod>#include <sdktools>#include <clientprefs>#include <scp>#define PLUGIN_NAME         "[ANY] Math Credits"#define PLUGIN_DESCRIPTION     "Give credits on correct math answer."#define PLUGIN_AUTHOR         "Arkarr"#define PLUGIN_VERSION         "1.00"#define PLUGIN_TAG            "[QUIZZ]"#define PLUS                "+"#define MINUS                "-"#define DIVISOR                "/"#define MULTIPL                "*"bool inQuizz;bool pluginEnabled;char op[32];char operators[4][2] = {"+""-""/""*"};int nbrmin;int nbrmax;int credits;int maxcredits;int mincredits;int questionResult;Handle timerQuestionEnd;Handle COOKIE_Credit;Handle CVAR_MinimumNumber;Handle CVAR_MaximumNumber;Handle CVAR_MaximumCredits;Handle CVAR_MinimumCredits;Handle CVAR_TimeBetweenQuestion;Handle CVAR_TimeAnswer;public Plugin myinfo = {    name PLUGIN_NAME,    author PLUGIN_AUTHOR,    description PLUGIN_DESCRIPTION,    version PLUGIN_VERSION,    url "http://www.sourcemod.net"};public void OnPluginStart(){    inQuizz false;        CVAR_MinimumNumber CreateConVar("sm_MathCredits_minimum_number""1""What should be the minimum number for questions ?");    CVAR_MaximumNumber CreateConVar("sm_MathCredits_maximum_number""100""What should be the maximum number for questions ?");    CVAR_MaximumCredits CreateConVar("sm_MathCredits_maximum_credits""50""What should be the maximum number of credits earned for a correct answers ?");    CVAR_MinimumCredits CreateConVar("sm_MathCredits_minimum_credits""5""What should be the minimum number of credits earned for a correct answers ?");    CVAR_TimeBetweenQuestion CreateConVar("sm_MathCredits_time_between_questions""50""Time in seconds between each questions.");    CVAR_TimeAnswer CreateConVar("sm_MathCredits_time_answer_questions""10""Time in seconds to give a answer to a question.");        COOKIE_Credit FindClientCookie("Creditos");        if(COOKIE_Credit == INVALID_HANDLE)    {        SetFailState("JailShop not found ! Plugin disabled ! Required Plugin : https://forums.alliedmods.net/showthread.php?t=247917");        pluginEnabled false;    }        AutoExecConfig(true"MathCredits");}public void OnMapStart(){    if(pluginEnabled)        CreateTimer(GetConVarFloat(CVAR_TimeBetweenQuestion) + GetConVarFloat(CVAR_TimeAnswer), CreateQuestion_TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);}public void OnConfigsExecuted(){    nbrmin GetConVarInt(CVAR_MinimumNumber);    nbrmax GetConVarInt(CVAR_MaximumNumber);    maxcredits GetConVarInt(CVAR_MaximumCredits);    mincredits GetConVarInt(CVAR_MinimumCredits);    }public Action EndQuestion(Handle timer){    SendEndQuestion(-1);}public Action CreateQuestion(Handle timer){    int nbr1 GetRandomInt(nbrminnbrmax);    int nbr2 GetRandomInt(nbrminnbrmax);    credits GetRandomInt(mincreditsmaxcredits);        Format(opsizeof(op), operators[GetRandomInt(0,3)]);        if(StrEqual(opPLUS))    {        questionResult nbr1 nbr2;    }    else if(StrEqual(opMINUS))    {        questionResult nbr1 nbr2;    }    else if(StrEqual(opDIVISOR))    {        do{            nbr1 GetRandomInt(nbrminnbrmax);            nbr2 GetRandomInt(nbrminnbrmax);        }while(nbr1 nbr2 != 0);        questionResult nbr1 nbr2;    }    else if(StrEqual(opMULTIPL))    {        questionResult nbr1 nbr2;    }        PrintToChatAll("%s %i %s %i = ? >>>%i credits<<<"PLUGIN_TAGnbr1opnbr2credits);    inQuizz true;        timerQuestionEnd CreateTimer(GetConVarFloat(CVAR_TimeAnswer), EndQuestion);}public Action OnChatMessage(&authorHandle recipientschar[] namechar[] message){    if(inQuizz)    {        char bit[1][5];        ExplodeString(message" "bitsizeof bitsizeof bit[]);        if(ProcessSolution(authorStringToInt(bit[0])))            SendEndQuestion(author);    }}public bool ProcessSolution(clientint number){    if(questionResult == number)    {                char strValue[10];        GetClientCookie(clientCOOKIE_CreditstrValuesizeof(strValue));                Format(strValuesizeof(strValue), "%i"credits StringToInt(strValue));                SetClientCookie(clientCOOKIE_CreditstrValue);                return true;    }    else    {        return false;    }}public void SendEndQuestion(int client){    if(timerQuestionEnd != INVALID_HANDLE)    {        KillTimer(timerQuestionEnd);        timerQuestionEnd INVALID_HANDLE;    }        char answer[100];        if(client != -1)        Format(answersizeof(answer), "%s %N has given a correct answer and got +%i credits !"PLUGIN_TAGclientcredits);    else        Format(answersizeof(answer), "%s Time end ! No answer."PLUGIN_TAG);            Handle pack CreateDataPack();    CreateDataTimer(0.3AnswerQuestionpack);    WritePackString(packanswer);        inQuizz false;}public Action AnswerQuestion(Handle timerHandle pack){    char str[100];    ResetPack(pack);    ReadPackString(packstrsizeof(str));     PrintToChatAll(str);} 
Not tested through.
Thank you so much! I will update the post once I test it.
__________________

Last edited by weeeishy; 07-29-2016 at 14:18.
weeeishy 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 15:33.


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