View Single Post
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