Don't need to write anything, just try to drop your knife with default drop key.
The only thing you have to edit in code is models :
PHP Code:
new szModels[][] =
{
"custom_weapons/v_knife1.mdl", // don't put cstrike/models/ in path
"custom_weapons/v_knife2.mdl",
"custom_weapons/v_knife3.mdl"
}
PHP Code:
/* Formatright © 2011, ConnorMcLeod
knives models is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cs1.5 knife; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define VERSION "0.2.0"
const MAX_PLAYERS = 32
const KNIFE_DRAW = 3
const FIRST_PERSON_VIEW = 4
const XO_WEAPON = 4
const m_pPlayer = 41
const m_iId = 43
const m_flDeployedTime = 76 // m_flDecreaseShotsFired ? w/e nvm works
const XO_PLAYER = 5
const m_pActiveItem = 373
const DEFAULT_MODEL = -1
new g_iPlayerModel[MAX_PLAYERS+1]
new Array:g_aKnivesModelsAllocated
new g_iKnivesNum
public plugin_precache()
{
new szModels[][] =
{
"custom_weapons/v_knife1.mdl", // don't put cstrike/models/ in path
"custom_weapons/v_knife2.mdl",
"custom_weapons/v_knife3.mdl"
}
g_aKnivesModelsAllocated = ArrayCreate(1,1)
new szFullModel[64]
for(new i; i<sizeof(szModels); i++)
{
formatex(szFullModel, charsmax(szFullModel), "models/%s", szModels[i])
precache_model(szFullModel)
ArrayPushCell(g_aKnivesModelsAllocated, engfunc(EngFunc_AllocString, szFullModel))
}
g_iKnivesNum = ArraySize(g_aKnivesModelsAllocated)
}
public plugin_init()
{
register_plugin("knives models", VERSION, "ConnorMcLeod")
RegisterHam(Ham_Item_Deploy, "weapon_knife", "Knife_Deploy", 1)
register_clcmd("drop", "ClientCommand_Drop")
}
public client_putinserver(id)
{
g_iPlayerModel[id] = DEFAULT_MODEL
}
public Knife_Deploy( iKnife )
{
new id = get_pdata_cbase(iKnife, m_pPlayer, XO_WEAPON)
new iModel = g_iPlayerModel[id]
if( iModel != DEFAULT_MODEL )
{
set_pev(id, pev_viewmodel, ArrayGetCell(g_aKnivesModelsAllocated, iModel))
}
}
public ClientCommand_Drop( id )
{
if( is_user_alive(id) )
{
new iWeapon = get_pdata_cbase(id, m_pActiveItem, XO_PLAYER)
if( get_pdata_int(iWeapon, m_iId, XO_WEAPON) == CSW_KNIFE )
{
new iModel = g_iPlayerModel[id]
if( ++iModel >= g_iKnivesNum )
{
iModel = DEFAULT_MODEL
}
g_iPlayerModel[id] = iModel
if( get_gametime() - get_pdata_float(iWeapon, m_flDeployedTime, XO_WEAPON) <= 1.5 )
{
new iPlayers[MAX_PLAYERS], iNum, iPlayer, iBody = pev(id,pev_body)
get_players(iPlayers, iNum, "bh")
for(--iNum; iNum>=0; iNum--)
{
iPlayer = iPlayers[iNum]
if( pev(iPlayer, pev_iuser2) == id && pev(iPlayer, pev_iuser1) == FIRST_PERSON_VIEW )
{
message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player=iPlayer)
{
write_byte(KNIFE_DRAW)
write_byte(iBody)
}
message_end()
}
}
message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player=id)
{
write_byte(KNIFE_DRAW)
write_byte(iBody)
}
message_end()
}
ExecuteHamB(Ham_Item_Deploy, iWeapon)
return PLUGIN_HANDLED
}
}
return PLUGIN_CONTINUE
}
__________________