give weapon plugin sourcemod for OC

C++ Got ya down? Half-Life 2 Coding Related.
Post Reply
kem008
Vertex
Vertex
Posts: 9
Joined: Tue Jan 24, 2012 3:25 pm
Location: Hungary
Contact:

give weapon plugin sourcemod for OC

Post by kem008 »

Hi all,

I just try to make this plugin but I stuck on custom weapons adding because they are not in the original engine and I dont know how to get them.
I' am not the original creater I just rewrote the whole plugin.

Code: Select all

#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

#define MAX_WEAPONS		18

public Plugin:myinfo = {
	name = "Give Weapon",
	author = "ICEMAN",
	description = "Give a weapon by type the name of the weapon if you want to give it to your self miss <target>",
	version = "0.2",
	url = "http://www.sourcemod.net/"
};

new const String:g_weapons[MAX_WEAPONS][] = {
	"weapon_crowbar", "weapon_stunstick", "weapon_physcannon", "weapon_healer", "weapon_pistol", "weapon_357", "weapon_alyxgun", "weapon_smg1", "custom_oicw", "weapon_ar2", "custom_m4a1", "weapon_shotgun", "weapon_crossbow", "weapon_gauss", "weapon_sniperrifle", "weapon_frag", "weapon_slam", "weapon_rpg"
};

public OnPluginStart()
{
	RegAdminCmd("sm_give", smGive, ADMFLAG_BAN, "- <target> <weaponname>");
	RegAdminCmd("sm_weaponslist", smWeaponsList, ADMFLAG_BAN, "- list of the weapon names");
}

public Action:smGive(id, args)
{
	if(args < 2)
	{
		ReplyToCommand(id, "[SM] Usage: sm_give <name | #userid> <weaponname>");
		return Plugin_Handled;
	}
	
	decl String:sArg[256];
	decl String:sTempArg[32];
	decl String:sWeaponName[32];
	decl String:sWeaponNameTemp[32];
	decl iL;
	decl iNL;
	
	GetCmdArgString(sArg, sizeof(sArg));
	iL = BreakString(sArg, sTempArg, sizeof(sTempArg));
	
	if((iNL = BreakString(sArg[iL], sWeaponName, sizeof(sWeaponName))) != -1)
		iL += iNL;
	
	new i;
	new iValid = 0;
	
	if(StrContains(sWeaponName, "weapon_") == -1)
	{
		FormatEx(sWeaponNameTemp, 31, "weapon_");
		StrCat(sWeaponNameTemp, 31, sWeaponName);
		
		strcopy(sWeaponName, 31, sWeaponNameTemp);
	}
	
	for(i = 0; i < MAX_WEAPONS; ++i)
	{
		if(StrEqual(sWeaponName, g_weapons[i]))
		{
			iValid = 1;
			break;
		}
	}
	
	if(!iValid)
	{
		ReplyToCommand(id, "[SM] The weaponname (%s) isn't valid", sWeaponName);
		return Plugin_Handled;
	}
	
	decl String:sTargetName[MAX_TARGET_LENGTH];
	decl sTargetList[1];
	decl bool:bTN_IsML;
	
	new iTarget = -1;
	
	if(ProcessTargetString(sTempArg, id, sTargetList, 1, COMMAND_FILTER_ALIVE|COMMAND_FILTER_NO_MULTI, sTargetName, sizeof(sTargetName), bTN_IsML) > 0)
		iTarget = sTargetList[0];
	
	if(iTarget != -1 && !IsFakeClient(iTarget))
		GivePlayerItem(iTarget, sWeaponName);
	
	return Plugin_Handled;
}

public Action:smWeaponsList(id, args)
{
	new i;
	for(i = 0; i < MAX_WEAPONS; ++i)
		ReplyToCommand(id, "%s", g_weapons[i]);
	
	ReplyToCommand(id, "");
	ReplyToCommand(id, "* No need to put weapon_ in the <weaponname>");
	
	return Plugin_Handled;
}
------------------------
------000--------------
-----0----0------------
------------0-----------
--------------0---------
----------------0-------
------------------0-----
-------------------0--0-
---------------------0--
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Re: give weapon plugin sourcemod for OC

Post by Neico »

You just need to add support for the "custom_" prefix where you can find "weapon_".
A list of all custom weapons can be obtained by searching "scripts/customweapons",
which involves a lot of restructuring on that plugin as it's pretty static code with that MAX_WEAPONS, the array and such (I'd look for "weapon_" files in the scripts folder to get the exact amount with a more dynamic approach...)
Image
Post Reply