Raised This Month: $32 Target: $400
 8% 

[TF2]Delaying commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EasyE
Junior Member
Join Date: Oct 2016
Old 02-19-2017 , 22:09   [TF2]Delaying commands
Reply With Quote #1

I've recently gotten back into sourcemod coding, and my first real plugin is going to be an event plugin.

However, I've hitten a stump where I need to wait for a player to respawn. I've found other threads about using CreateTimer(). I checked the sourcemod api for syntax, and it says that I have to call another function.
Is there any way I can not call another function, and just have the plugin continue running after the timer? I've heard of using CloseHandle(), but I'm not sure if that will do what I'm looking for, and even then I'm getting a "Number of arguments does not match definition error".
If someone could help me out with this, it would be very much appreciated.
EasyE is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-19-2017 , 22:51   Re: [TF2]Delaying commands
Reply With Quote #2

I'm having trouble understanding what the event plugin entails. Could you explain the underlying problem that you're having?

If you want to hook a player respawn, you can use the following:

Code:
public void OnPluginStart() {
    HookEvent("player_spawn", OnPlayerSpawn);
}

public void OnPlayerSpawn(Event event, const char[] name, bool dontBroadcast) {
    int client = GetClientOfUserId(event.GetInt("userid"));
    
    if (client) {
        // spawn timer, etc.
    }
}
For Timers and the like, you do have to provide a callback function that gets called when the timer interval has elapsed.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
EasyE
Junior Member
Join Date: Oct 2016
Old 02-19-2017 , 23:35   Re: [TF2]Delaying commands
Reply With Quote #3

In hindsight, event plugin might have been a bit confusing actually. When I said event plugin, I meant as a spy crab event or something of the sort.
Code:
public void OnPluginStart()
{
	RegAdminCmd("sm_startevent", Command_StartEvent, ADMFLAG_GENERIC,"Starts the event");
	RegAdminCmd("sm_stopevent", Command_StopEvent, ADMFLAG_GENERIC, "Closes the joining time for the event");
	RegAdminCmd("sm_eventlocation", Command_EventLocation, ADMFLAG_GENERIC, "Set's the location where players will teleport to");
	RegConsoleCmd("sm_joinevent", Command_JoinEvent, "When an event is started, use this to join it!");
}
int eLocationSet = 0;
int eventStart = 0;
new Float:eLocation[3];


public Action Command_StartEvent(int client, int args)
{
	if (eventStart == 0 && eLocationSet == 1) {
		eventStart = 1;
		PrintToChatAll("\x04[Event]The spycrab event has been started, do !JoinEvent to join!");
		return Plugin_Handled;
	}
	else {
		PrintToChat(client, "\x04[Event]There's already an event running!")	
		return Plugin_Handled;
	}
}

public Action Command_StopEvent(int client, int args) {
	if ( eventStart == 1) {
		PrintToChatAll("\x04[Event]The event joining time is over.");
		eventStart = 0;
		return Plugin_Handled;
	}
	else {
		PrintToChat(client, "\x04[Event]There is no event to stop.");
		return Plugin_Handled;
	}
	
}

public Action Command_EventLocation(int client, int args) {
	GetClientAbsOrigin(client, eLocation);
	eLocationSet = 1;
	PrintToChat(client, "\x04[Event] Location has been set.");
	return Plugin_Handled;
}
//This is the part where I'm having trouble

public Action Command_JoinEvent(int client, int args) {
	if (eventStart == 1) {
		TF2_ChangeClientTeam(client, TFTeam_Blue);
		TF2_SetPlayerClass(client, TFClass_Spy);
		TF2_RespawnPlayer(client);
		return Plugin_Handled;
	}
	else {
		PrintToChat(client, "\x04[Event]There is no event currently going");
		return Plugin_Handled;
	}
}

Last edited by EasyE; 02-19-2017 at 23:36.
EasyE is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-19-2017 , 23:48   Re: [TF2]Delaying commands
Reply With Quote #4

I don't recall any issues with teleporting a player immediately after respawning.

Just add a TeleportEntity right after it and make sure you have the appropriate files included (#include <tf2_stocks> has everything necessary). Here's a copy with the stuff added in.

I also tested it out and it seems to work fine.
Attached Files
File Type: sp Get Plugin or Get Source (event_gathering.sp - 265 views - 1.9 KB)
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 02-19-2017 at 23:48.
nosoop is offline
EasyE
Junior Member
Join Date: Oct 2016
Old 02-20-2017 , 00:02   Re: [TF2]Delaying commands
Reply With Quote #5

I got rid of the teleport entity line because it wasn't working and expected to make another function for the timer.

But for some odd reason, your version instantly respawned the player and the teleport then worked.
Thanks for the help

Edit: Hold on I think it stopped working again
It teleports me to the set location and changes my team/class, but then I die.
This means that players on the red team have to type the command twice

Last edited by EasyE; 02-20-2017 at 00:08.
EasyE is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:55.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode