Quote:
Originally Posted by Desktop
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
For example:
PHP Code:
public Action EventOnPlayerConnectedFull(Event event, char[] name, bool dontBroadcast){
int client = GetClientOfUserId(GetEventInt(event, "userid"));
RequestFrame(view_as<RequestFrameCallback>(MoveToSpectator), client);
}
public Action MoveToSpectator(any data){
ChangeClientTeam(data, CS_TEAM_NONE);
}
|
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[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
RequestFrame(Frame_ChangeTeam, client);
}
public void Frame_ChangeTeam(any client)
{
ChangeClientTeam(client, CS_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.