PDA

View Full Version : Calling a timer into a function?


Ibanezez
10-05-2014, 22:05
My code:

public OnPluginStart()
{
RegAdminCmd("sm_playsound", playsound, ADMFLAG_GENERIC, "Emit Crab Notify");
RegAdminCmd("sm_toggle", toggle, ADMFLAG_GENERIC, "Toggle on/off mass crab mode");

CreateTimer(5.0, fivesecondtimer);

PrecacheSound(CRAB_BELL);
}

public Action:fivesecondtimer(Handle:timer)
{

}

if(StrEqual(szScenefile, "scenes/player/spy/low/taunt05.vcd"))
{
new client = GetEntPropEnt(entity, Prop_Data, "m_hOwner");
fivesecondtimer(Handle:timer)

PrintToChat(client, "You have spycrabbed!");
}


I was just wondering how I can call it into a function, so it waits 5 seconds before it sends the message.

With what I have right now, I'm getting the error that when I'm calling fivesecondtimer, (Handle:timer) "timer" is not a defined symbol.

Thanks! :D

ddhoward
10-05-2014, 22:18
if(StrEqual(szScenefile, "scenes/player/spy/low/taunt05.vcd"))
{
new client = GetEntPropEnt(entity, Prop_Data, "m_hOwner");
fivesecondtimer(Handle:timer)

PrintToChat(client, "You have spycrabbed!");
}



I truly have no idea what you are trying to do here.

"Timer" is not a variable that you have defined anywhere in the calling "function."

What function is this IF statement contained in? You haven't even put this if block anywhere. It's just floating out there in the global code, outside any function.

Where is szScenefile?

What is "entity"? It doesn't appear to be a variable available to any function listed.

fivesecondtimer(Handle:timer)
What is this even?

You need to look up some programming basics that are not Sourcepawn-specific.

Ibanezez
10-05-2014, 23:01
Oh sorry about that, I was copying parts of a bigger script into there, and that probably looked a bit weird. :P

Here is a better example:

#include <sourcemod>

public OnPluginStart()
{
RegConsoleCmd("sm_welcome", Command_Welcome, "");
CreateTimer(5.0, fivesecondtimer);
}

public Action:fivesecondtimer(Handle:timer)
{
PrintToServer("\n");
}

public Action:Command_Welcome(client, args)
{
fivesecondtimer(Handle:timer)
PrintToChat(client, "Welcome!");
}


Basically my goal is that when you type !welcome, it will wait 5 seconds then give you a welcome message.

arthurdead
10-05-2014, 23:03
#include <sourcemod>

public OnPluginStart()
{
RegConsoleCmd("sm_welcome", Command_Welcome, "");
}

public Action:fivesecondtimer(Handle:timer, any:client)
{
PrintToChat(client, "Welcome!");
}

public Action:Command_Welcome(client, args)
{
CreateTimer(5.0, fivesecondtimer, client); //serial or userid here i am lazy
}

ddhoward
10-05-2014, 23:06
public OnPluginStart()
{
RegConsoleCmd("sm_welcome", Command_Welcome, "");
}

public Action:fivesecondtimer(Handle:timer, any:userID)
{
new client = GetClientOfUserId(userID);
if (client > 0) {
PrintToChat(client, "Welcome!");
}
}

public Action:Command_Welcome(client, args)
{
CreateTimer(5.0, fivesecondtimer, GetClientUserId(client));
}

As I pointed out to you before, in another thread you posted with this same question, you need to place the CreateTimer instruction at the point in time at which you want to create and start the timer...

Ibanezez
10-05-2014, 23:22
Yeah, I was getting an error with the other one (thread), but I have it fixed now.

LambdaLambda
10-06-2014, 04:06
What the hell? I have posted you a method on using Timers few days ago, my friend.