Thread: Knife API v2.2
View Single Post
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-12-2014 , 12:46   Re: Knife API
Reply With Quote #2

Examples top
Example #1: Default CS knife with custom sprite - don't use without #define DEFAULT_HANDS (Tested, works)
PHP Code:
#include <amxmodx>
#include <knifeapi>
#include <cstrike>

new g_Knife

new const VMODEL[] = "models/v_knife.mdl"
new const PMODEL[] = "models/p_knife.mdl"

const KNIFE_PRICE 300

public plugin_precache()
{
    
precache_model(VMODEL)
    
precache_model(PMODEL)
    
    
// we precache the custom sprite .txt and .spr files
    
precache_generic("sprites/weapon_superknife.txt")
    
precache_generic("sprites/superknife.spr")
    
    
// ALWAYS precache your files. If you don't, the server will crash, knife API doesn't do it for you
}

public 
plugin_init()
{
    
register_plugin("Knife API example""1.0""idiotstrike")
    
    
    
g_Knife Knife_Register(
        .
WeaponName =  "Default Knife",
        .
VModel =      VMODEL,
        .
PModel =      PMODEL
    
)
    
    
// additional properties (for a list of all properties, see knifeapi.inc):
    
    // we make the knife droppable
    
Knife_SetProperty(g_KnifeKN_CLL_Droppabletrue)
    
    
// since we want to use a custom sprite, we set this to the .txt filename without extension.
    // if you don't want to use a custom sprite, don't change the KN_STR_SpriteName property!
    
Knife_SetProperty(g_KnifeKN_STR_SpriteName"weapon_superknife")
    
    
// we can also change the primary range to 60.0 to make it more unrealistic
    //Knife_SetProperty(g_Knife, KN_CLL_PrimaryRange, 60.0)
    
    
register_clcmd("say /buyknife""CmdBuyKnife")
}

public 
CmdBuyKnife(id)
{
    if(!
is_user_alive(id))
    {
        
client_print(idprint_chat"You need to be alive.")
    }
    else if(
Knife_PlayerHas(idg_Knife))
    {
        
client_print(idprint_chat"You already have this knife. Switch to knife and press R to see it.")
    }
    else
    {
        new 
Money cs_get_user_money(id)
        
        if(
Money KNIFE_PRICE)
        {
            
client_print(idprint_center"You have insufficient funds.")
        }
        else
        {
            
Knife_PlayerGive(idg_Knife)
            
cs_set_user_money(idMoney KNIFE_PRICE)
        }
    }
    
    return 
PLUGIN_HANDLED

weapon_superknife.txt:
Spoiler


Plugins using this top

Support me top
If you think that my work is worth something, I certainly wouldn't mind any kind of a donation


Or, add me on Steam and give me some trading cards or a TF2 key
__________________
Currently busy working on a very large scale anime database project.

Last edited by Backstabnoob; 07-16-2014 at 20:31.
Backstabnoob is offline