I got it working by creating the folder/mapname.cfg (blank) on my computer then put it on manually since there was a problem with creating it. Also did the code differently.
Code:
/*
Evil Deagle.
*/
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.2"
public Plugin:myinfo =
{
name = "Evil Deagle",
author = "meng",
version = PLUGIN_VERSION,
description = "special deagle for CSS",
url = ""
};
new bool:enabled;
new Handle:ED_spawns;
new Handle:CvarEfxColor;
new Handle:CvarRecoilMul;
new Float:RecoilMul;
new EDdc;
new EDindex;
new EDpwner;
new Float:LastEDpwnerPos[3];
new WeaponParent;
new iClip1;
new RingColor[4];
new BeamSprite;
new HaloSprite;
new GlowSprite;
new bool:EndEDH;
new String:mapcfgpath[PLATFORM_MAX_PATH];
public OnPluginStart()
{
/* offsets */
WeaponParent = FindSendPropOffs("CBaseCombatWeapon", "m_hOwnerEntity");
iClip1 = FindSendPropOffs("CBaseCombatWeapon", "m_iClip1");
/* convars */
CreateConVar("sm_evildeagle_version", PLUGIN_VERSION, "Evil Deagle Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
CvarEfxColor = CreateConVar("sm_evildeagle_efxcolor", "0");
CvarRecoilMul = CreateConVar("sm_evildeagle_recoil", "400");
HookConVarChange(CvarRecoilMul, OnSettingChanged);
/* admin cmds */
RegAdminCmd("sm_evildeagle", EDControl, ADMFLAG_BAN);
RegAdminCmd("sm_evildeagle_sp", CommandSavePos, ADMFLAG_BAN);
/* create the plugins cfg dir if it doesn't exist already */
decl String:configspath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, configspath, sizeof(configspath), "configs/evildeagle");
if (!DirExists(configspath))
CreateDirectory(configspath, 0x0265);
/* adt array for saving spawn positions */
ED_spawns = CreateArray(3);
/* hook events */
HookEvent("round_start", EventRoundStart, EventHookMode_PostNoCopy);
HookEvent("weapon_fire", EventWeaponFire);
HookEvent("player_hurt", EventPlayerHurt);
HookEvent("player_death", EventPlayerDeath);
HookEvent("round_end", EventRoundEnd, EventHookMode_PostNoCopy);
}
public OnMapStart()
{
/* get map and read its cfg */
decl String:map[64];
GetCurrentMap(map, sizeof(map));
BuildPath(Path_SM, mapcfgpath, sizeof(mapcfgpath), "configs/evildeagle/%s.cfg", map);
ReadConfig();
/* precache needed materials */
BeamSprite = PrecacheModel("materials/sprites/laser.vmt");
HaloSprite = PrecacheModel("materials/sprites/halo01.vmt");
if (!FileExists(mapcfgpath))
{
new Handle:fh = OpenFile(mapcfgpath, "w+");
CloseHandle(fh);
}
}
public OnConfigsExecuted()
{
if (GetConVarInt(CvarEfxColor))
{
RingColor = {150, 125, 0, 255};
GlowSprite = PrecacheModel("sprites/yellowglow1.vmt");
}
else
{
RingColor = {255, 25, 15, 255};
GlowSprite = PrecacheModel("sprites/redglow3.vmt");
}
RecoilMul = -1.0*GetConVarFloat(CvarRecoilMul);
}
public OnSettingChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
if (convar == CvarRecoilMul)
RecoilMul = -1.0*StringToFloat(newValue);
}
/* map end, clear the spawn points array */
public OnMapEnd(){ClearArray(ED_spawns);}
/* admin command handler to turn the plugin on/off */
public Action:EDControl(client, args)
{
if (args != 1)
{
ReplyToCommand(client, "[SM] Usage: sm_evildeagle <0/1>");
return Plugin_Handled;
}
decl String:info[8], Switch;
GetCmdArg(1, info, sizeof(info)); Switch = StringToInt(info);
switch (Switch)
{
case 0:
{
enabled = false;
ReplyToCommand(client, "[Evil Deagle] Plugin DISABLED");
}
/* if enabling, make sure we have stored e.d. spawns, if not, dont enable */
case 1:
{
if (GetArraySize(ED_spawns) < 1)
{
enabled = false;
ReplyToCommand(client, "[Evil Deagle] No saved spawn positions. Plugin DISABLED");
}
else
{
enabled = true;
ReplyToCommand(client, "[Evil Deagle] Plugin ENABLED");
}
}
}
return Plugin_Handled;
}
/* admin command handler for saving e.d. spawn positions */
public Action:CommandSavePos(client, args)
{
/* if the map cfg file doesn't exist, create it */
/* open the map file and store the new keyvalues entry */
new Handle:kv = CreateKeyValues("EDSP");
new arraysize = GetArraySize(ED_spawns);
decl Float:vec[3], String:buff[8];
GetClientAbsOrigin(client, vec);
Format(buff, sizeof(buff), "sp%d", arraysize+1);
if (FileToKeyValues(kv, mapcfgpath))
{
KvSetVector(kv, buff, vec);
KeyValuesToFile(kv, mapcfgpath);
PushArrayArray(ED_spawns, _:vec);
ReplyToCommand(client, "[Evil Deagle] Spawn position saved! New total: %d", arraysize+1);
}
else
ReplyToCommand(client, "[Evil Deagle] Error saving spawn position. Missing map config file.");
CloseHandle(kv);
return Plugin_Handled;
}
/* read the map keyvalues file and store the positions in the adt array */
ReadConfig()
{
new Handle:kv = CreateKeyValues("EDSP");
if (FileToKeyValues(kv, mapcfgpath))
{
new num = 1;
decl String:buff[8], Float:vec[3];
Format(buff, sizeof(buff), "sp%d", num);
KvGetVector(kv, buff, vec);
while (vec[0] != 0.0)
{
PushArrayArray(ED_spawns, vec);
num++;
Format(buff, sizeof(buff), "sp%d", num);
KvGetVector(kv, buff, vec);
}
}
CloseHandle(kv);
if (GetArraySize(ED_spawns) < 1)
enabled = false;
}
/* round_start. initialize, create point_hurt, start e.d. handler */
public EventRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
if (enabled)
{
EndEDH = false;
EDindex = -1;
EDpwner = -1;
LastEDpwnerPos[0] = 0.0;
new entity = CreateEntityByName("point_hurt");
if (DispatchSpawn(entity))
EDdc = entity;
else
EDdc = -1;
CreateTimer(1.0, EDHandler, INVALID_HANDLE, TIMER_REPEAT);
}
}
/* round_end. set bool so the e.d. handler stops itself */
public EventRoundEnd(Handle:event, const String:name[], bool:dontBroadcast){EndEDH = true;}
SpawnNewED(spott)
{
new entity = CreateEntityByName("weapon_deagle");
DispatchSpawn(entity);
decl Float:vec[3];
switch (spott)
{
case 0: /* spawn from saved positions */
{
new arraysize = GetArraySize(ED_spawns);
GetArrayArray(ED_spawns, GetRandomInt(0, arraysize-1), vec);
}
case 1: /* spawn at last owners position */
vec = LastEDpwnerPos;
}
TeleportEntity(entity, vec, NULL_VECTOR, NULL_VECTOR);
SetEntData(entity, iClip1, 1);
EDindex = entity;
}
/* the e.d. handler. a repeating timer that makes sure its still in the game, keeps track of who owns it
and makes sure it has the correct ammo count */
public Action:EDHandler(Handle:timer)
{
static owner, iAmmo, Float:EDvec[3];
if (EndEDH)
return Plugin_Stop;
if (!IsValidEntity(EDindex))
{
SpawnNewED(LastEDpwnerPos[0] == 0.0 ? 0 : 1);
return Plugin_Continue;
}
if ((owner = GetEntDataEnt2(EDindex, WeaponParent)) != -1)
{
EDpwner = owner;
if (GetEntData(EDindex, iClip1) > 1)
SetEntData(EDindex, iClip1, 1);
iAmmo = FindDataMapOffs(owner, "m_iAmmo")+(1*4);
if (GetEntData(owner, iAmmo) > 1)
SetEntData(owner, iAmmo, 0);
}
else
{
EDpwner = -1;
if (GetEntData(EDindex, iClip1) < 1)
SetEntData(EDindex, iClip1, 1);
GetEntPropVector(EDindex, Prop_Data, "m_vecOrigin", EDvec);
TE_SetupGlowSprite(EDvec, GlowSprite, 1.0, 0.7, 217);
TE_SendToAll();
EDvec[2] += 3;
TE_SetupBeamRingPoint(EDvec, 8.0, 36.0, BeamSprite, HaloSprite, 0, 10, 1.0, 7.0, 1.0, RingColor, 7, 0);
TE_SendToAll();
}
return Plugin_Continue;
}
/* if the e.d. is fired, give it another bullet. */
public EventWeaponFire(Handle:event,const String:name[],bool:dontBroadcast)
{
if (enabled)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (client == EDpwner)
{
decl String:weapon[16];
GetEventString(event, "weapon", weapon, sizeof(weapon));
if (StrEqual(weapon, "deagle"))
{
new c_iAmmo = FindDataMapOffs(client, "m_iAmmo")+(1*4);
SetEntData(client, c_iAmmo, 1);
if (GetEntData(EDindex, iClip1) == 1)
CreateTimer(0.01, Recoil, client);
}
}
}
}
/* using a timer for the recoil effect, otherwise it seems to hurt accuracy */
public Action:Recoil(Handle:timer, any:client)
{
static Float:PlayerAng[3], Float:PlayerVel[3], Float:Push[3];
GetClientEyeAngles(client, PlayerAng);
GetEntPropVector(client, Prop_Data, "m_vecVelocity", PlayerVel);
PlayerAng[0] *= -1.0;
PlayerAng[0] = DegToRad(PlayerAng[0]);
PlayerAng[1] = DegToRad(PlayerAng[1]);
Push[0] = RecoilMul*Cosine(PlayerAng[0])*Cosine(PlayerAng[1])+PlayerVel[0];
Push[1] = RecoilMul*Cosine(PlayerAng[0])*Sine(PlayerAng[1])+PlayerVel[1];
Push[2] = RecoilMul*Sine(PlayerAng[0])+PlayerVel[2];
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Push);
}
/* if hurt by the e.d., kill. */
public EventPlayerHurt(Handle:event,const String:name[],bool:dontBroadcast)
{
if (enabled)
{
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
if (attacker && attacker == EDpwner)
{
decl String:weapon[16];
GetEventString(event, "weapon", weapon, sizeof(weapon));
if (StrEqual(weapon, "deagle"))
{
if (IsValidEntity(EDdc))
{
new victim = GetClientOfUserId(GetEventInt(event,"userid"));
/* teleporting the point hurt entity to the attacker position
creates a great physics push on the victim in the correct direction */
decl Float:attackerPos[3];
GetClientAbsOrigin(attacker, attackerPos);
TeleportEntity(EDdc, attackerPos, NULL_VECTOR, NULL_VECTOR);
DispatchKeyValue(victim, "targetname", "hurt");
DispatchKeyValue(EDdc, "DamageTarget", "hurt");
DispatchKeyValue(EDdc, "Damage", "317");
DispatchKeyValue(EDdc, "DamageType", "0");
AcceptEntityInput(EDdc, "Hurt", attacker);
DispatchKeyValue(victim, "targetname", "nohurt");
}
else
LogError("Invalid EDdc");
}
}
}
}
/* if the e.d. owner died, store position incase the e.d. handler needs to spawn a new e.d.. */
public EventPlayerDeath(Handle:event,const String:name[],bool:dontBroadcast)
{
if (enabled)
{
new client = GetClientOfUserId(GetEventInt(event,"userid"));
if (client == EDpwner)
GetClientAbsOrigin(client, LastEDpwnerPos);
}
}