View Single Post
Desktop
AlliedModders Donor
Join Date: Sep 2009
Location: C:\Users\Default\
Old 02-26-2020 , 08:43   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #25

Quote:
Originally Posted by Maxximou5 View Post
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.
Yes, you're right, that would be a correct case, as you said, sometimes you have to "let things happen" before calling a func to that, like the case when the player equips a weapon or while working with networked entities and you need them to exist first.

There are two ways of using this logic, one is firing a timer for example on a "Pre" event (Time) and the other is to request a frame in the "post" event (requestFrame), both should work similarly on most cases.
The difference is that on the "post" event, you can read/know all the data you need to work with the entity (because you are sure it already exists)
__________________
Massive Infection:: Piu-Games

Last edited by Desktop; 02-26-2020 at 08:50.
Desktop is offline