View Single Post
Maxximou5
AlliedModders Donor
Join Date: Feb 2013
Old 02-20-2020 , 16:36   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #24

Quote:
Originally Posted by Desktop View Post
I think it would be nice to add the usage of RequestFrame instead of CreateTimer with 0.1 seconds to execution as a good practice.
Spoiler
It would depend on the use case, you could be using a repeat timer. Though for the instance you are probably mentioning, it would be a one time with an immediate response. That would be a great use of RequestFrame as it's that's what it should be used for. Though, I would say it would better to have a complete example, along with the newest method of usage. Such as -

PHP Code:
#include <cstrike>

public void OnPluginStart()
{
    
HookEvent("player_connect_full"Event_PlayerConnectFull);
}

public 
void Event_PlayerConnectFull(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
RequestFrame(Frame_ChangeTeamclient);
}

public 
void Frame_ChangeTeam(any client)
{
    
ChangeClientTeam(clientCS_TEAM_NONE)

It should be mentioned that there are scenarios were RequestFrame and using a timer delay are different enough that something such as when a player is spawning and not creating a delay will cause a function to not work. Case scenarios I believe exist, like equipping a weapon, dropping a weapon, or cycling and stripping certain weapons, are such examples.

Of course, correct me if I am wrong, but this was such issues I had awhile ago.
Maxximou5 is offline