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

Please help me with a very simple plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hazdogga
New Member
Join Date: Apr 2015
Old 04-14-2015 , 01:33   Please help me with a very simple plugin
Reply With Quote #1

Hi guys,

I am trying to ease my way into the land of source mod scripting and was hoping you might be able to help me out...

I'm trying to Start small and learn gradually, so I'm trying to complete a plugin for CS:GO that writes the scores for each team to a text file each time the round ends.

I'll include my code.. There's two issues here:
1) The text file are not actually being created at all. My belief if that the text files will be created in the sourcemod root folder.
2) I don't know how to concatenate strings in Sourcemod. For example, I essentially want to know how to do this type of thing:
Code:
WriteFileLine(fileHandle1,"Counter Terrorists: " + GetTeamScore(3));
(is this valid?)

Here's my code.. I compiled it into a .SMX and put it in the plugins folder of my server but alas, no text files are created.
Code:
/* Plugin Template generated by Pawn Studio */

#include <sourcemod>
#include <sdktools>

public Plugin:myinfo = 
{
	name = "ScoreCheck",
	author = "Harry",
	description = "Gets the scores of the teams.",
	version = "1.0",
	url = "<- None ->"
}

public OnPluginStart()
{
	HookEventEx("round_start",Event_RoundStart);
	HookEventEx("round_end",Event_RoundEnd);
}

public Event_RoundStart(Handle:event,const String:name[],bool:dontBroadcast) {
	decl String:path[PLATFORM_MAX_PATH];
	BuildPath(Path_SM,path,PLATFORM_MAX_PATH,"Status.txt");
	OpenFile(path,"w");
	new Handle:fileHandle = OpenFile(path,"w");
	WriteFileLine(fileHandle,"RoundStarted");
	CloseHandle(fileHandle);
}

public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast) {
	decl String:path[PLATFORM_MAX_PATH];
	BuildPath(Path_SM,path,PLATFORM_MAX_PATH,"Status.txt");
	OpenFile(path,"w");
	new Handle:fileHandle = OpenFile(path,"w");
	WriteFileLine(fileHandle,"RoundEnded");
	
	decl String:path1[PLATFORM_MAX_PATH];
	BuildPath(Path_SM,path1,PLATFORM_MAX_PATH,"Scores.txt");
	OpenFile(path1,"w");
	new Handle:fileHandle1 = OpenFile(path1,"w");
	WriteFileLine(fileHandle1,"Counter Terrorists");
	WriteFileLine(fileHandle1,"Terrorists");
	CloseHandle(fileHandle1);
}
I'd totally appreciate any assistance you can offer!

Warm regards,
Harry.

Edit: The files seem to have created, but do not have anything in them. Hmmm

Last edited by hazdogga; 04-14-2015 at 01:50.
hazdogga is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 04-14-2015 , 06:17   Re: Please help me with a very simple plugin
Reply With Quote #2

This is the amxmodx section. You might be luckier posting into the sourcemod sections.
mottzi is offline
Send a message via MSN to mottzi
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 04-14-2015 , 06:20   Re: Please help me with a very simple plugin
Reply With Quote #3

Code:
WriteFileLine(fileHandle1,"Counter Terrorists: %d", GetTeamScore(3));
why are you using openfile 2 times in a row?
Code:
OpenFile(path,"w");
	new Handle:fileHandle = OpenFile(path,"w");
you're opening the file with a write mode, is it what you really want?
http://www.cplusplus.com/reference/cstdio/fopen/
Code:
write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.
also you really should post this under sourcemod section if you want real help. this scripting help is for amxmodx
jimaway is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-15-2015 , 22:30   Re: Please help me with a very simple plugin
Reply With Quote #4

Moved to SM section.
__________________
Bugsy is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 04-16-2015 , 07:27   Re: Please help me with a very simple plugin
Reply With Quote #5

Quote:
Originally Posted by hazdogga View Post
2) I don't know how to concatenate strings in Sourcemod. For example, I essentially want to know how to do this type of thing:
Code:
WriteFileLine(fileHandle1,"Counter Terrorists: " + GetTeamScore(3));
(is this valid?)
https://sm.alliedmods.net/api/index....ad=show&id=643
Miu is offline
splewis
Veteran Member
Join Date: Feb 2014
Location: United States
Old 04-16-2015 , 16:17   Re: Please help me with a very simple plugin
Reply With Quote #6

While that will help him concatenate, there is no need for it here.

Code:
WriteFileLine(fileHandle1, "Counter Terrorists: %d", GetTeamScore(3));
You also might find it easier to use LogToFile and pass the file path rather than dealing with file handles everywhere.

Additionally, add a
Code:
#include <cstrike>
and you can use CS_TEAM_T and CS_TEAM_CT instead of magic 2/3 values.
__________________
splewis is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 04-16-2015 , 16:30   Re: Please help me with a very simple plugin
Reply With Quote #7

Does GetTeamScore even work for CS:GO? I just assumed it didn't, which is why CS_GetTeamScore exists.
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 19:06.


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