Hi all,
I'm having trouble replacing weapons on left 4 dead 2.
I've had a look through some other mods, such as frustian (for l4d1) and seen how they did it, and used that as a basis. However, I just can't get it to work.
My code is below, and I have commented the functions that are/aren't working. If someone could possibly show me how they would accomplish this, or point me in the right direction, that would be awesome!
PHP Code:
//sdk tools
#include <sourcemod>
#include <sdktools>
//plugin version
#define PLUGIN_VERSION "0"
//plugin info
public Plugin:myinfo =
{
name = "Jackpf's Test",
author = "jackpf",
description = "Testing",
version = PLUGIN_VERSION,
url = "http://jackpf.co.uk"
}
//plugin setup
public OnPluginStart()
{
//console cmds
RegAdminCmd("sm_test", test, ADMFLAG_BAN);
RegAdminCmd("sm_test2", test2, ADMFLAG_BAN);
}
public Action:test(client, args)
{
/*
This should replace all kits/defibs with pills - this works!!
*/
new string:EdictName[128];
for(new i = 0; i <= GetEntityCount(); i++)
{
if(IsValidEntity(i))
{
GetEdictClassname(i, EdictName, sizeof(EdictName));
if( StrContains(EdictName, "weapon_first_aid_kit", false) != -1 ||
StrContains(EdictName, "weapon_defibrillator", false) != -1)
{
new index = CreateEntityByName("weapon_pain_pills_spawn");
if(index != -1)
{
new Float:Angle[3];
new Float:Location[3];
GetEntPropVector(i, Prop_Send, "m_angRotation", Angle);
GetEntPropVector(i, Prop_Send, "m_vecOrigin", Location);
TeleportEntity(index, Location, Angle, NULL_VECTOR);
DispatchSpawn(index);
}
AcceptEntityInput(i, "Kill");
}
}
}
return Plugin_Handled;
}
public Action:test2(client, args)
{
/*
This should replace all auto shotguns with pump shotguns.
However, it only removes shotguns that have been picked up, and not spawned ones.
I tried adding the line (line 80) StrContains(EdictName, "weapon_autoshotgun_spawn", false) != -1
But this crashes my server for some reason :/
*/
new string:EdictName[128];
for(new i = 0; i <= GetEntityCount(); i++)
{
if(IsValidEntity(i))
{
GetEdictClassname(i, EdictName, sizeof(EdictName));
if( StrContains(EdictName, "weapon_autoshotgun", false) != -1 ||
StrContains(EdictName, "weapon_autoshotgun_spawn", false) != -1)
{
new index = CreateEntityByName("weapon_pumpshotgun_spawn");
if(index != -1)
{
new Float:Angle[3];
new Float:Location[3];
GetEntPropVector(i, Prop_Send, "m_angRotation", Angle);
GetEntPropVector(i, Prop_Send, "m_vecOrigin", Location);
TeleportEntity(index, Location, Angle, NULL_VECTOR);
DispatchSpawn(index);
}
AcceptEntityInput(i, "Kill");
}
}
}
return Plugin_Handled;
}
Any help is much appreciated.
Thanks,
Jack.