AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   command every round only 1 time (https://forums.alliedmods.net/showthread.php?t=311387)

alphaearth 10-15-2018 17:12

command every round only 1 time
 
in add ins command every round only 1 time how do I set up for use? can you help?
thank you so much in advance

Code:

#include <sourcemod>
#include <store>
#include <renkler>

#pragma semicolon 1
#pragma newdecls required

#define VERSION "1.2"

char prefix[] = "{green}[Yazı Tura] {default}";

int waitTime[MAXPLAYERS + 1];

ConVar maxCredits;
ConVar minBet;
ConVar winRatio;
ConVar waitTimeLength;

public Plugin myinfo =
{
        name = "[STORE] Coinflip",
        author = "Hypr",
        description = "Ability to coinflip",
        version = VERSION,
        url = "https://forums.alliedmods.net/showthread.php?t=276677"
};

public void OnPluginStart() {
       
        LoadTranslations("coinflip.phrases.txt");
        SetGlobalTransTarget(LANG_SERVER);
       
        RegConsoleCmd("sm_flip", sm_flip);
        RegConsoleCmd("sm_yazitura", sm_flip);
       
        AutoExecConfig(true, "store.coinflip");
       
        maxCredits = CreateConVar("sm_coinflip_max", "50", "What's the maximum amounts of credits a user can bet at once", FCVAR_NOTIFY, true, 1.0);
        winRatio = CreateConVar("sm_coinflip_winratio", "0.5", "The amount of the betted coins that the client wins. (Betted credits * 0.5)", FCVAR_NOTIFY, true, 0.1);
        minBet = CreateConVar("sm_coinflip_min", "5", "What's the minimum amount of credits a player is allowed to bet?", FCVAR_NOTIFY, true, 0.1);
        waitTimeLength = CreateConVar("sm_coinflip_waittime", "120", "In seconds, how long does a player have to wait inbetween bets?\nSet to 0 to disable.", FCVAR_NOTIFY);
}

public Action sm_flip(int client, int args) {

        if (!IsValidClient(client)) { // invalid client
                ReplyToCommand(client, "%s %t", prefix, "Invalid Client");
                return Plugin_Handled;
        }
       
        if (args != 1) { // invalid argument count
                CPrintToChat(client, "%s %t", prefix, "Invalid Arguments");
                return Plugin_Handled;
        }
               
        if (waitTime[client] > GetTime()) { // still in cooldown
                CPrintToChat(client, "%s %t", prefix, "Wait Time");
                return Plugin_Handled;
        }
       
        char betAmount[64];
        GetCmdArg(1, betAmount, sizeof(betAmount));
       
        int curCredits = Store_GetClientCredits(client);
        int betCredits = StringToInt(betAmount);

        if (curCredits < betCredits) { // not enough credits
                CPrintToChat(client, "%s %t", prefix, "Not Enough Credits", curCredits);
                return Plugin_Handled;
        }
       
        if (betCredits < minBet.IntValue) { // bet is too small
                CPrintToChat(client, "%s %t", prefix, "Too Few Credits", minBet.IntValue);
                return Plugin_Handled;
        }
       
        if (betCredits > maxCredits.IntValue) { // bet is too big
                CPrintToChat(client, "%s %t", prefix, "Too Many Credits", maxCredits.IntValue);
                return Plugin_Handled;
        }
       
       
        // If configured, put client into wait time
        if(waitTimeLength.IntValue > 0) {
                waitTime[client] = GetTime() + waitTimeLength.IntValue;
        }
       
        switch (GetRandomInt(0, 1))
        {
                case 0:
                {
                        CPrintToChat(client, "%s %t", prefix, "Client Lost");
                       
                        Store_SetClientCredits(client, (Store_GetClientCredits(client) - betCredits));
                }
               
                case 1:
                {
                        float wonCredits = betCredits * winRatio.FloatValue;
                       
                        CPrintToChat(client, "%s %t", prefix, "Client Won", RoundToFloor(wonCredits));
                        CPrintToChatAll("%s %t", prefix, "Client Won Announce", client, RoundToFloor(wonCredits));
                       
                        Store_SetClientCredits(client, (Store_GetClientCredits(client) + RoundToFloor(wonCredits)));
                }
        }
       
        return Plugin_Handled;
}

bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
{
        if(!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
        {
                return false;
        }
        return true;
}


Bacardi 10-15-2018 17:33

Re: command every round only 1 time
 
You mean, "Player can use this command one time per round" ?

alphaearth 10-15-2018 17:59

Re: command every round only 1 time
 
Yes

P4UL 10-16-2018 03:49

Re: command every round only 1 time
 
Have not tested it

Code:

#include <sourcemod>
#include <store>
#include <renkler>
#include <sdkhooks>

#pragma semicolon 1
#pragma newdecls required

#define VERSION "1.2"

char prefix[] = "{green}[Yazı Tura] {default}";

bool allowBet[MAXPLAYERS + 1] = {true, ...};

int waitTime[MAXPLAYERS + 1];

ConVar maxCredits;
ConVar minBet;
ConVar winRatio;
ConVar waitTimeLength;

public Plugin myinfo =
{
        name = "[STORE] Coinflip",
        author = "Hypr",
        description = "Ability to coinflip",
        version = VERSION,
        url = "https://forums.alliedmods.net/showthread.php?t=276677"
};

public void OnPluginStart() {
       
        LoadTranslations("coinflip.phrases.txt");
        SetGlobalTransTarget(LANG_SERVER);
       
        RegConsoleCmd("sm_flip", sm_flip);
        RegConsoleCmd("sm_yazitura", sm_flip);
       
        AutoExecConfig(true, "store.coinflip");
       
        HookEvent("round_start", Event_RoundStart);
       
        maxCredits = CreateConVar("sm_coinflip_max", "50", "What's the maximum amounts of credits a user can bet at once", FCVAR_NOTIFY, true, 1.0);
        winRatio = CreateConVar("sm_coinflip_winratio", "0.5", "The amount of the betted coins that the client wins. (Betted credits * 0.5)", FCVAR_NOTIFY, true, 0.1);
        minBet = CreateConVar("sm_coinflip_min", "5", "What's the minimum amount of credits a player is allowed to bet?", FCVAR_NOTIFY, true, 0.1);
        waitTimeLength = CreateConVar("sm_coinflip_waittime", "120", "In seconds, how long does a player have to wait inbetween bets?\nSet to 0 to disable.", FCVAR_NOTIFY);
}

public Action sm_flip(int client, int args) {

        if (!IsValidClient(client)) { // invalid client
                ReplyToCommand(client, "%s %t", prefix, "Invalid Client");
                return Plugin_Handled;
        }
       
        if (args != 1) { // invalid argument count
                CPrintToChat(client, "%s %t", prefix, "Invalid Arguments");
                return Plugin_Handled;
        }
               
        if (waitTime[client] > GetTime()) { // still in cooldown
                CPrintToChat(client, "%s %t", prefix, "Wait Time");
                return Plugin_Handled;
        }
       
        char betAmount[64];
        GetCmdArg(1, betAmount, sizeof(betAmount));
       
        int curCredits = Store_GetClientCredits(client);
        int betCredits = StringToInt(betAmount);

        if (curCredits < betCredits) { // not enough credits
                CPrintToChat(client, "%s %t", prefix, "Not Enough Credits", curCredits);
                return Plugin_Handled;
        }
       
        if (betCredits < minBet.IntValue) { // bet is too small
                CPrintToChat(client, "%s %t", prefix, "Too Few Credits", minBet.IntValue);
                return Plugin_Handled;
        }
       
        if (betCredits > maxCredits.IntValue) { // bet is too big
                CPrintToChat(client, "%s %t", prefix, "Too Many Credits", maxCredits.IntValue);
                return Plugin_Handled;
        }
       
        if (allowBet[client] == false) { // already used
                CPrintToCHat(client, "%s %t", prefix, "Already Used");
                return Plugin_Handled;
        }
       
       
        // If configured, put client into wait time
        if(waitTimeLength.IntValue > 0) {
                waitTime[client] = GetTime() + waitTimeLength.IntValue;
        }
       
        switch (GetRandomInt(0, 1))
        {
                case 0:
                {
                        CPrintToChat(client, "%s %t", prefix, "Client Lost");
                       
                        Store_SetClientCredits(client, (Store_GetClientCredits(client) - betCredits));
                }
               
                case 1:
                {
                        float wonCredits = betCredits * winRatio.FloatValue;
                       
                        CPrintToChat(client, "%s %t", prefix, "Client Won", RoundToFloor(wonCredits));
                        CPrintToChatAll("%s %t", prefix, "Client Won Announce", client, RoundToFloor(wonCredits));
                       
                        Store_SetClientCredits(client, (Store_GetClientCredits(client) + RoundToFloor(wonCredits)));
                }
        }
        allowBet[client] = false;
       
        return Plugin_Handled;
}

bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
{
        if(!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
        {
                return false;
        }
        return true;
}

public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
        for(int i = 1; i < MaxClients; i++) allowBet[i] = true; 
}


alphaearth 10-16-2018 12:14

Re: command every round only 1 time
 
I tested it in the CS:GO. Its work perfectly. Thank you for everything.

alphaearth 10-17-2018 09:11

Re: command every round only 1 time
 
You do what i want, can you edit it to disable with cvar code?

P4UL 10-17-2018 12:47

Re: command every round only 1 time
 
You mean just a cvar which allows you to disable the once per round in the config?

alphaearth 10-17-2018 18:49

Re: command every round only 1 time
 
Yes

P4UL 10-18-2018 02:25

Re: command every round only 1 time
 
Code:

#include <sourcemod>
#include <store>
#include <renkler>
#include <sdkhooks>

#pragma semicolon 1
#pragma newdecls required

#define VERSION "1.2"

char prefix[] = "{green}[Yazı Tura] {default}";

bool allowBet[MAXPLAYERS + 1] = {true, ...};

int waitTime[MAXPLAYERS + 1];

ConVar maxCredits;
ConVar minBet;
ConVar winRatio;
ConVar waitTimeLength;
ConVar enableRoundLimit;

public Plugin myinfo =
{
        name = "[STORE] Coinflip",
        author = "Hypr",
        description = "Ability to coinflip",
        version = VERSION,
        url = "https://forums.alliedmods.net/showthread.php?t=276677"
};

public void OnPluginStart() {
       
        LoadTranslations("coinflip.phrases.txt");
        SetGlobalTransTarget(LANG_SERVER);
       
        RegConsoleCmd("sm_flip", sm_flip);
        RegConsoleCmd("sm_yazitura", sm_flip);
       
        AutoExecConfig(true, "store.coinflip");
       
        HookEvent("round_start", Event_RoundStart);
       
        maxCredits = CreateConVar("sm_coinflip_max", "50", "What's the maximum amounts of credits a user can bet at once", FCVAR_NOTIFY, true, 1.0);
        winRatio = CreateConVar("sm_coinflip_winratio", "0.5", "The amount of the betted coins that the client wins. (Betted credits * 0.5)", FCVAR_NOTIFY, true, 0.1);
        minBet = CreateConVar("sm_coinflip_min", "5", "What's the minimum amount of credits a player is allowed to bet?", FCVAR_NOTIFY, true, 0.1);
        waitTimeLength = CreateConVar("sm_coinflip_waittime", "120", "In seconds, how long does a player have to wait inbetween bets?\nSet to 0 to disable.", FCVAR_NOTIFY);
        enableRoundLimit = CreateConVar("sm_enable_roundlimit", "1", "Enable/Disable once per round.", FCVAR_NOTIFY);
}

public Action sm_flip(int client, int args) {

        if (!IsValidClient(client)) { // invalid client
                ReplyToCommand(client, "%s %t", prefix, "Invalid Client");
                return Plugin_Handled;
        }
       
        if (args != 1) { // invalid argument count
                CPrintToChat(client, "%s %t", prefix, "Invalid Arguments");
                return Plugin_Handled;
        }
               
        if (waitTime[client] > GetTime()) { // still in cooldown
                CPrintToChat(client, "%s %t", prefix, "Wait Time");
                return Plugin_Handled;
        }
       
        char betAmount[64];
        GetCmdArg(1, betAmount, sizeof(betAmount));
       
        int curCredits = Store_GetClientCredits(client);
        int betCredits = StringToInt(betAmount);

        if (curCredits < betCredits) { // not enough credits
                CPrintToChat(client, "%s %t", prefix, "Not Enough Credits", curCredits);
                return Plugin_Handled;
        }
       
        if (betCredits < minBet.IntValue) { // bet is too small
                CPrintToChat(client, "%s %t", prefix, "Too Few Credits", minBet.IntValue);
                return Plugin_Handled;
        }
       
        if (betCredits > maxCredits.IntValue) { // bet is too big
                CPrintToChat(client, "%s %t", prefix, "Too Many Credits", maxCredits.IntValue);
                return Plugin_Handled;
        }
       
        if (allowBet[client] == false && GetConVarInt(enableRoundLimit) == 1) { // already used
                CPrintToChat(client, "%s %t", prefix, "Already Used");
                return Plugin_Handled;
        }
       
       
        // If configured, put client into wait time
        if(waitTimeLength.IntValue > 0) {
                waitTime[client] = GetTime() + waitTimeLength.IntValue;
        }
       
        switch (GetRandomInt(0, 1))
        {
                case 0:
                {
                        CPrintToChat(client, "%s %t", prefix, "Client Lost");
                       
                        Store_SetClientCredits(client, (Store_GetClientCredits(client) - betCredits));
                }
               
                case 1:
                {
                        float wonCredits = betCredits * winRatio.FloatValue;
                       
                        CPrintToChat(client, "%s %t", prefix, "Client Won", RoundToFloor(wonCredits));
                        CPrintToChatAll("%s %t", prefix, "Client Won Announce", client, RoundToFloor(wonCredits));
                       
                        Store_SetClientCredits(client, (Store_GetClientCredits(client) + RoundToFloor(wonCredits)));
                }
        }
        allowBet[client] = false;
       
        return Plugin_Handled;
}

bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
{
        if(!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
        {
                return false;
        }
        return true;
}

public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
        for(int i = 1; i < MaxClients; i++) allowBet[i] = true; 
}



All times are GMT -4. The time now is 15:31.

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