Not tested, neither I've ever used the CS_* functions...
Tested and here it's working
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#pragma semicolon 1
#pragma newdecls required
#define PLUGIN_NAME "DropWeapon"
#define PLUGIN_VERSION "1.0"
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = "Hexah",
description = "",
version = PLUGIN_VERSION,
url = "csitajb.it"
};
public void OnPluginStart()
{
RegConsoleCmd("sm_drop", Cmd_Drop);
}
public Action Cmd_Drop(int client, int args)
{
if (!IsPlayerAlive(client))
{
ReplyToCommand(client, "[SM] You can't this command now!");
}
char sAlias[64];
GetCmdArg(1, sAlias, sizeof(sAlias));
PrintToChatAll(sAlias);
CSWeaponID weapon = GetWeaponID(sAlias);
PrintToChatAll(sAlias);
if (!CS_IsValidWeaponID(weapon))
{
ReplyToCommand(client, "[SM] Invalid weapon");
return Plugin_Handled;
}
int price = CS_GetWeaponPrice(client, weapon);
int money = GetEntProp(client, Prop_Send, "m_iAccount");
if (price > money)
{
ReplyToCommand(client, "[SM] You haven't got enought money!");
return Plugin_Handled;
}
Format(sAlias, sizeof(sAlias), "weapon_%s", sAlias);
int ent = CreateEntityByName(sAlias);
if (ent == -1)
{
ReplyToCommand(client, "[SM] An error occured, try again");
return Plugin_Handled;
}
float vPos[3];
float vAng[3];
float vFinal[3];
GetClientEyePosition(client, vPos);
GetClientEyeAngles(client, vAng);
TR_TraceRayFilter(vPos, vAng, MASK_SOLID, RayType_Infinite, Trace_DontHitSelf, client);
if (TR_DidHit())
{
TR_GetEndPosition(vFinal);
vFinal[2] += 10.0;
}
else
{
for (int i = 0; i <= sizeof(vPos); i++)
vFinal[i] = vPos[i];
}
TeleportEntity(ent, vFinal, NULL_VECTOR, NULL_VECTOR);
DispatchSpawn(ent);
SetEntProp(client, Prop_Send, "m_iAccount", money - price);
return Plugin_Handled;
}
CSWeaponID GetWeaponID(const char[] sAlias)
{
char sWeapon[64];
CS_GetTranslatedWeaponAlias(sAlias, sWeapon, sizeof(sWeapon));
return CS_AliasToWeaponID(sWeapon);
}
public bool Trace_DontHitSelf(int entity, int contentsMask, any client)
{
return entity != client;
}
__________________