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

[CS:GO] Timer malfunction


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
andrept4
Senior Member
Join Date: Dec 2012
Location: Portugal
Old 08-05-2020 , 06:54   [CS:GO] Timer malfunction
Reply With Quote #1

So, I'm creating a Timer everytime a client is put in the server so I can give him credits (Zephyrus Store) deppending on his situation (if he's in our steam group and if he's VIP)

So far so good, giving the credits is working, all the logic I added is working too. The only problem is the timer, first of all, I'm using 300.0 seconds (5 minutes) as the first paramater and it gives credits to players from 100 to 200 seconds, after that it gives them more credits 5-10 seconds passed. I can't understand whats going on, (my thought is that there is more than 1 timer, maybe add a singleton?).

Here's the code:

Code:
#pragma semicolon 1

#define PLUGIN_AUTHOR "GelaPT"
#define PLUGIN_VERSION "1.00"

#include <sourcemod>
#include <SteamWorks>
#include <store>

#pragma newdecls required

ConVar IDGrupo;
bool b_isMember[MAXPLAYERS + 1];

public Plugin myinfo = 
{
	name = "Creditos de Grupo",
	author = PLUGIN_AUTHOR,
	description = "Dá créditos para quem está no grupo",
	version = PLUGIN_VERSION,
	url = "servers.ftw.pt"
};

public void OnPluginStart()
{
	IDGrupo = CreateConVar("sm_ftw_id_grupo", "0000000", "Steam Group ID", FCVAR_NOTIFY);
	RegAdminCmd("sm_ftw_admin_teste", TesteAdmin, ADMFLAG_RESERVATION, "[FTW] Teste de admin!");
}

public void OnClientPutInServer(int client) {
	CreateTimer(300.0, VerificarJogador, GetClientSerial(client));
}

public Action TesteAdmin(int client, int args) {
	PrintToChat(client, "\x01 \x02[FWT] \x01Teste!");
}

public Action VerificarJogador(Handle timer, int serial) {
	int client = GetClientFromSerial(serial);
	
	if (client == 0) // The serial is no longer valid, the player must have disconnected
    {
        return Plugin_Stop;
    }
	
	if(!IsFakeClient(client) && IsClientConnected(client)) {
		if(IsClientInGame(client) && b_isMember[client]) {
			if(GetClientTeam(client) != 1) {
				if(CheckCommandAccess(client, "sm_ftw_admin_teste", ADMFLAG_RESERVATION)) {
					Store_SetClientCredits(client, Store_GetClientCredits(client) + 5);
					PrintToChat(client, "\x01 \x02[FTW] \x01Recebeste \x035 créditos\x01 por seres \x03VIP \x01e um membro do nosso \x02Grupo\x01!");
				} else {
					Store_SetClientCredits(client, Store_GetClientCredits(client) + 1);
					PrintToChat(client, "\x01 \x02[FTW] \x01Recebeste \x031 crédito\x01 por seres um membro do nosso \x02Grupo\x01!");	
				}
			} else {
				PrintToChat(client, "\x01 \x02[FTW] \x01Não recebeste créditos por estares a espetador!");
			}
		} else if(!b_isMember[client]) {
			PrintToChat(client, "\x01 \x02[FTW] \x01Não recebeste créditos por não seres um membro do nosso \x02Grupo\x01! Faz \x02!grupo\x01");
		}
	}
	
	return Plugin_Continue;
}

public void OnClientPostAdminCheck(int client) {
	b_isMember[client] = false;
	if(!IsFakeClient(client)) {
		if(!SteamWorks_GetUserGroupStatus(client, IDGrupo.IntValue)) {
			LogError("[Creditos] Nao consegui arranjar o steam group de: %N", client);
		}
	}
}

public int SteamWorks_OnClientGroupStatus(int authid, int groupAccountID, bool isMember, bool isOfficer)
{
	int client = UserAuthGrab(authid);
	if (client != -1 && isMember)
	{
		b_isMember[client] = true;
	}
	return;
}

int UserAuthGrab(int authid)
{
	char charauth[64], authchar[64];
	for (int i = 1; i <= MaxClients; i++)
	{
		if(IsClientInGame(i) && GetClientAuthId(i, AuthId_Steam3, charauth, sizeof(charauth)))
		{
			IntToString(authid, authchar, sizeof(authchar));
			if(StrContains(charauth, authchar) != -1)
			{
				return i;
			}
		}
	}
	
	return -1;
}
__________________
andrept4 is offline
bklol
Member
Join Date: May 2019
Location: on my chair
Old 08-05-2020 , 09:21   Re: [CS:GO] Timer malfunction
Reply With Quote #2

I think maybe you should kill the timer when client disconnet or mapchange?
bklol is offline
andrept4
Senior Member
Join Date: Dec 2012
Location: Portugal
Old 08-05-2020 , 13:10   Re: [CS:GO] Timer malfunction
Reply With Quote #3

Quote:
Originally Posted by bklol View Post
I think maybe you should kill the timer when client disconnet or mapchange?
That's a must! But it doesn't fix the randomness of the timer ticking
__________________
andrept4 is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 08-05-2020 , 18:32   Re: [CS:GO] Timer malfunction
Reply With Quote #4

The timer in Zephyrus Store will also give credits. If you don't want that to happen you should disable the timer in Zephyrus store.
PC Gamer is offline
Cruze
Veteran Member
Join Date: May 2017
Old 08-06-2020 , 00:16   Re: [CS:GO] Timer malfunction
Reply With Quote #5

CreateTimer(300.0, VerificarJogador, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE);
}
__________________
Taking paid private requests! Contact me
Cruze is offline
andrept4
Senior Member
Join Date: Dec 2012
Location: Portugal
Old 08-06-2020 , 11:24   Re: [CS:GO] Timer malfunction
Reply With Quote #6

Quote:
Originally Posted by PC Gamer View Post
The timer in Zephyrus Store will also give credits. If you don't want that to happen you should disable the timer in Zephyrus store.
I already did that, the credits I'm recieving are from my own plugin. For example, if it gives from 5 min to 5 min, and the map has 20 mins, I'm supposed to recieve 4 times the ammount. In this case I recieve from 10 to 20 to 30 times, it's always random! I can't tell what's the problem here.
__________________
andrept4 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 10:20.


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