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

command every round only 1 time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alphaearth
Senior Member
Join Date: Feb 2018
Location: Turkey
Old 10-15-2018 , 17:12   command every round only 1 time
Reply With Quote #1

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;
}
__________________
alphaearth is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-15-2018 , 17:33   Re: command every round only 1 time
Reply With Quote #2

You mean, "Player can use this command one time per round" ?
Bacardi is offline
alphaearth
Senior Member
Join Date: Feb 2018
Location: Turkey
Old 10-15-2018 , 17:59   Re: command every round only 1 time
Reply With Quote #3

Yes
__________________

Last edited by alphaearth; 10-15-2018 at 19:12. Reason: edit
alphaearth is offline
P4UL
AlliedModders Donor
Join Date: Apr 2017
Location: Netherlands
Old 10-16-2018 , 03:49   Re: command every round only 1 time
Reply With Quote #4

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;  
}
P4UL is offline
alphaearth
Senior Member
Join Date: Feb 2018
Location: Turkey
Old 10-16-2018 , 12:14   Re: command every round only 1 time
Reply With Quote #5

I tested it in the CS:GO. Its work perfectly. Thank you for everything.
__________________
alphaearth is offline
alphaearth
Senior Member
Join Date: Feb 2018
Location: Turkey
Old 10-17-2018 , 09:11   Re: command every round only 1 time
Reply With Quote #6

You do what i want, can you edit it to disable with cvar code?
__________________
alphaearth is offline
P4UL
AlliedModders Donor
Join Date: Apr 2017
Location: Netherlands
Old 10-17-2018 , 12:47   Re: command every round only 1 time
Reply With Quote #7

You mean just a cvar which allows you to disable the once per round in the config?
P4UL is offline
alphaearth
Senior Member
Join Date: Feb 2018
Location: Turkey
Old 10-17-2018 , 18:49   Re: command every round only 1 time
Reply With Quote #8

Yes
__________________
alphaearth is offline
P4UL
AlliedModders Donor
Join Date: Apr 2017
Location: Netherlands
Old 10-18-2018 , 02:25   Re: command every round only 1 time
Reply With Quote #9

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;  
}
P4UL 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 09:38.


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