Raised This Month: $51 Target: $400
 12% 

Solved Problem with CreateTimer: function prototyps do not match


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dasbunny
Junior Member
Join Date: May 2019
Location: Vorarlberg, Austria
Old 07-28-2019 , 10:40   Problem with CreateTimer: function prototyps do not match
Reply With Quote #1

Hello,
I'm trying to create a plugin that moves a demo file to another folder. My server (CSGO) is running the Get5 Plugin by splewis, which is setting up 5v5 matches and automaticially records demos to the csgo folder on the server. This causes two problems:
1. Demos are stuck on the server and clan members cannot retrieve them without getting acess the the server files, which I do not want to do
2. The demo names include the map and the date of recording (yy-mm-dd-hh) but there could be multiple matches started in the same hour, so the previous demo gets overwritten

My attempted solution is a plugin that moves the demo file to another folder (/csgo/demos in this case) where another program running on the server can take care of it. The Get5 plugin provides a Forward that is called when demo recording is finished.
When I tested my plugin without a timer it did find a file (using FileExists) at 'oldpath' but it didn't move it to 'newpath'. I think that the Forward is called before the demo is properly saved, so the file cannot be acessed by RenameFile(). I now want to add a timer to wait a few seconds until the demo is hopefully saved and can be moved.

This is the server console print when the demo recording finishes. The underlined lines are from my plugin. As you can see there are two more lines after that, I assume that the demo is finished after those are printed.
Quote:
[Quixz 5v5] An admin force ended the match.
2019-07-28_16_de_overpass.dem
19-07-28-16-22-de_overpass.dem

addons/sourcemod/../../2019-07-28_16_de_overpass.dem
addons/sourcemod/../../Demos/19-07-28-16-22-de_overpass.dem
Completed GOTV demo "2019-07-28_16_de_overpass.dem", recording time 32.4
StopRecording: 1023 frames flushed in 0.25 seconds
When I compile the code below I get 'error 100: function prototypes do not match' in the line where I use CreateTimer.
What is causing this error?
Is my theory about the demo file not being saved in time correct?

Thank you for you help in advance!
Code:
#include <sourcemod>
#include <sdktools>
#include <timers.inc>

public Plugin myinfo = 
{
	name = "Demo mover",
	author = "dasBunny",
	description = "Moves demos once a Get5 matches finish",
	version = "1.0",
	url = "quixz.eu"
};

public void OnPluginStart(){
	
}

public void Get5_OnDemoFinished(const char[] filename){
	CreateTimer(5.0, MoveFile, filename); 			//	<--- Error is in this line
}

public Action MoveFile(Handle timer, const char[] filename){
	new String:oldpath[256], String:newpath[256], String:newname[256], String:map[64];
	PrintToServer(filename);
	
	//Creating a new filename with more detailed timestamp
	int stamp=GetTime();
	FormatTime(newname,sizeof(newname),"%y-%m-%d-%H-%M-%S-",stamp);
	GetCurrentMap(map, sizeof(map));
	StrCat(newname, sizeof(newname), map);
	StrCat(newname, sizeof(newname), ".dem");
	PrintToServer(newname);
	
	//Building the paths and moving the file
	BuildPath(Path_SM,oldpath,sizeof(oldpath),"../../%s",filename);
	BuildPath(Path_SM,newpath,sizeof(newpath),"../../demos/%s",newname);
	PrintToServer(oldpath);
	PrintToServer(newpath);
	RenameFile(newpath, oldpath);
	return Plugin_Handled;
}

Last edited by dasbunny; 07-29-2019 at 16:00. Reason: Added Solved tag
dasbunny is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 07-28-2019 , 11:21   Re: Problem with CreateTimer: function prototyps do not match
Reply With Quote #2

You can't pass array on Timer.
Do something like this:

Code:
public void Get5_OnDemoFinished(const char[] filename){
	DataPack hPack = new DataPack();
	hPack.WriteString(filename);
	CreateTimer(5.0, MoveFile, hPack);
}

public Action MoveFile(Handle timer, DataPack hPack)
{
	char filename[256];

	hPack.Reset();
	hPack.ReadString(filename);
	hPack.Close();

	// old code
}
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...

Last edited by CrazyHackGUT; 07-28-2019 at 11:21.
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
Cruze
Veteran Member
Join Date: May 2017
Old 07-28-2019 , 11:26   Re: Problem with CreateTimer: function prototyps do not match
Reply With Quote #3

Quote:
Originally Posted by CrazyHackGUT View Post
Code:
public void Get5_OnDemoFinished(const char[] filename){
	DataPack hPack = new DataPack();
	hPack.WriteString(filename);
	CreateDataTimer(5.0, MoveFile, hPack);
}

public Action MoveFile(Handle timer, DataPack hPack)
{
	char filename[256];

	hPack.Reset();
	hPack.ReadString(filename);
	hPack.Close();

	// old code
}
Little thing you missed out.
__________________
Taking paid private requests! Contact me
Cruze is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 07-28-2019 , 11:57   Re: Problem with CreateTimer: function prototyps do not match
Reply With Quote #4

Quote:
Originally Posted by Cruze View Post
Little thing you missed out.
It'll will work properly anyways (tough I think it's better using when passing DataPacks), also if CreateDataTimer is used, you don't need to initialize the DataPack variable, as well as closing it in the timer callback.


https://wiki.alliedmods.net/Timers_(...ng)#Data_Packs
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!

Last edited by Papero; 07-28-2019 at 11:58.
Papero is offline
dasbunny
Junior Member
Join Date: May 2019
Location: Vorarlberg, Austria
Old 07-28-2019 , 16:58   Re: Problem with CreateTimer: function prototyps do not match
Reply With Quote #5

Thank you for your help, the compile error is gone and the timer is working fine.
However the file still does not get moved. Maybe this is a general problem with the plugin not being allowed to write anything to the directory. Another plugin on the server has also not created a config file it's supposed to create. Are there issues like this known?
dasbunny is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-29-2019 , 13:56   Re: Problem with CreateTimer: function prototyps do not match
Reply With Quote #6

Its because you have to create the timer before writing
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311
I am inevitable is offline
Reply



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 00:49.


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