Thread: !drop weapons
View Single Post
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 02-08-2018 , 16:40   Re: !drop weapons
Reply With Quote #2

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 clientint args)
{
    if (!
IsPlayerAlive(client))
    {
        
ReplyToCommand(client"[SM] You can't this command now!");
    }
    
char sAlias[64];
    
GetCmdArg(1sAliassizeof(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(clientweapon);
    
int money GetEntProp(clientProp_Send"m_iAccount");
    
    if (
price money)
    {
        
ReplyToCommand(client"[SM] You haven't got enought money!");
        return 
Plugin_Handled;
    }
    
    
Format(sAliassizeof(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(clientvPos);
    
GetClientEyeAngles(clientvAng);
    
TR_TraceRayFilter(vPosvAngMASK_SOLIDRayType_InfiniteTrace_DontHitSelfclient);
    
    if (
TR_DidHit())
    {
        
TR_GetEndPosition(vFinal);
        
vFinal[2] += 10.0;
    }
    else
    {
        for (
int i 0<= sizeof(vPos); i++)
            
vFinal[i] = vPos[i];
    }
    
    
TeleportEntity(entvFinalNULL_VECTORNULL_VECTOR);

    
DispatchSpawn(ent);
    
SetEntProp(clientProp_Send"m_iAccount"money price);
    return 
Plugin_Handled;
}

CSWeaponID GetWeaponID(const char[] sAlias)
{
    
char sWeapon[64];
    
CS_GetTranslatedWeaponAlias(sAliassWeaponsizeof(sWeapon));
    return 
CS_AliasToWeaponID(sWeapon);
}  

public 
bool Trace_DontHitSelf(int entityint contentsMaskany client)
{
    return 
entity != client;

__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!

Last edited by Papero; 02-10-2018 at 13:34. Reason: Update plugin
Papero is offline