Hello,
I'm trying to code my own KillReward plugin and I want to register the user points inside individuals .txt files.
Code:
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "JPTRON"
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <sdktools>
#include <files>
#include <string>
#pragma newdecls required
public Plugin myinfo =
{
name = "KillReward",
author = PLUGIN_AUTHOR,
description = "Receive points when killing someone.",
version = PLUGIN_VERSION,
url = ""
};
public void OnPluginStart()
{
HookEvent("player_death", Event_PlayerDeath);
}
public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) {
int victim = event.GetInt("userid");
int attacker = event.GetInt("attacker");
char str[40], attackerStr[40];
IntToString(attacker, attackerStr, sizeof(attackerStr));
Format(str, sizeof(str), "/players/%s.txt", attackerStr);
if(victim == attacker || attacker == 0){
return;
}
Handle attackerFile = OpenFile(str, "r+");
if(!attackerFile){
WriteFileLine(attackerFile, "10");
}
CloseHandle(attackerFile);
attackerFile = OpenFile(str, "w+");
int attackerPoints;
attackerPoints = ReadFileLine(attackerFile, attackerStr, sizeof(attackerStr));
attackerPoints += 10;
IntToString(attackerPoints, attackerStr, sizeof(attackerStr));
WriteFileLine(attackerFile, attackerStr);
CloseHandle(attackerFile);
}
Code:
L 06/06/2020 - 09:40:57: "JPTRON<2><STEAM_1:0:151314112><CT>" [1514 -126 -148] killed "Matt<11><BOT><TERRORIST>" [1575 -116 -84] with "taser"
L 06/06/2020 - 09:40:57: [SM] Exception reported: invalid handle 0 (error: 4)
L 06/06/2020 - 09:40:57: [SM] Blaming: points.smx
L 06/06/2020 - 09:40:57: [SM] Call stack trace:
L 06/06/2020 - 09:40:57: [SM] [0] WriteFileLine
L 06/06/2020 - 09:40:57: [SM] [1] Line 53, C:\Users\joaopf\AppData\Roaming\spedit\sourcepawn\scripts\points.sp::Event_PlayerDeath