Well I originally thought of doing it that way, but then thought with multiple weapons a it would be better to check in switch_model. But then again there aren't really many of those so which would you guys prefer?
Code:
// DARTH MAUL! evil Sith apprentice from Star Wars - Episode I: The Phantom Menace. Double Bladed Lightsaber is his trademark.
/* CVARS - copy and paste to shconfig.cfg
//Darth Maul
darth_level 6
darth_healpoints 10 // the #of HP healed per second
darth_knifespeed 400 // speed of Darth Maul in knife mode
darth_knifemult 2.70 // multiplier for knife damage...
*/
/*
* v1.4 - vittu - 3/10/11
* - Changed model change method to use Ham_Item_Deploy instead of the CurWeapon event.
*
* v1.3 - vittu - 3/8/11
* - Updated to SH 1.2.0.14 or above.
* - Added define to disable use of weapon models.
*
* v1.2 - vittu - 6/19/05
* - Minor code clean up.
* - Added p_ knife model.
*
* v1.1 - vittu - 12/21/04
* -SH mod 1.17.6 and up only
* -Model name and location changed (to follow new standard)
* -Also only needed one of the models not both (deleted useless second model)
* -Now heals past 100hp if you have more
* -Fixed extra speed to use knife
*
* Darth Maul based on {HOJ}Batman's wolverine hero which is where most of the credit should go
*/
//---------- User Changeable Defines --------//
// Comment out to force not using the model, will result in a very small reduction in code/checks
// Note: If you change anything here from default setting you must recompile the plugin
#define USE_WPN_MODEL
//------- Do not edit below this point ------//
#include <superheromod>
// GLOBAL VARIABLES
new gHeroID
new bool:gHasDarthMaul[SH_MAXSLOTS+1]
new gPcvarHealPoints
#if defined USE_WPN_MODEL
new const gModelKnifeV[] = "models/shmod/darthmaul_knife.mdl"
new const gModelKnifeP[] = "models/shmod/darthmaul_p_knife.mdl"
new bool:gModelLoaded
#endif
//----------------------------------------------------------------------------------------------
public plugin_init()
{
// Plugin Info
register_plugin("SUPERHERO Darth Maul", "1.4", "Chivas2973")
// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
new pcvarLevel = register_cvar("darth_level", "6")
new pcvarKnifeSpeed = register_cvar("darth_knifespeed", "400")
new pcvarKnifeMult = register_cvar("darth_knifemult", "2.70")
gPcvarHealPoints = register_cvar("darth_healpoints", "10")
// FIRE THE EVENT TO CREATE THIS SUPERHERO!
gHeroID = sh_create_hero("Darth Maul", pcvarLevel)
sh_set_hero_info(gHeroID, "Sith Lightsaber & Regen", "Get a Sith Double Bladed Lightsaber with more Damage and Speed, also regenerate HP")
sh_set_hero_speed(gHeroID, pcvarKnifeSpeed, {CSW_KNIFE})
sh_set_hero_dmgmult(gHeroID, pcvarKnifeMult, CSW_KNIFE)
#if defined USE_WPN_MODEL
// REGISTER EVENTS THIS HERO WILL RESPOND TO!
if ( gModelLoaded ) {
RegisterHam(Ham_Item_Deploy, "weapon_knife", "Ham_Knife_Deploy_Post", 1)
}
#endif
// HEAL LOOP
set_task(1.0, "darth_loop", _, _, _, "b")
}
//----------------------------------------------------------------------------------------------
#if defined USE_WPN_MODEL
public plugin_precache()
{
// Method servers 2 purposes, moron check and optional way to not use the model
// Seperate checks so the model that is missing can be reported
gModelLoaded = true
if ( file_exists(gModelKnifeV) ) {
precache_model(gModelKnifeV)
}
else {
sh_debug_message(0, 0, "Aborted loading ^"%s^", file does not exist on server", gModelKnifeV)
gModelLoaded = false
}
if ( file_exists(gModelKnifeP) ) {
precache_model(gModelKnifeP)
}
else {
sh_debug_message(0, 0, "Aborted loading ^"%s^", file does not exist on server", gModelKnifeP)
gModelLoaded = false
}
}
#endif
//----------------------------------------------------------------------------------------------
public sh_hero_init(id, heroID, mode)
{
if ( gHeroID != heroID ) return
switch(mode) {
case SH_HERO_ADD: {
gHasDarthMaul[id] = true
#if defined USE_WPN_MODEL
if ( gModelLoaded && get_user_weapon(id) == CSW_KNIFE ) {
switch_model_knife(id)
}
#endif
}
case SH_HERO_DROP: {
gHasDarthMaul[id] = false
}
}
}
//----------------------------------------------------------------------------------------------
public darth_loop()
{
if ( !sh_is_active() ) return
static players[SH_MAXSLOTS], playerCount, player, i, healPoints
get_players(players, playerCount, "ah")
healPoints = get_pcvar_num(gPcvarHealPoints)
for ( i = 0; i < playerCount; i++ ) {
player = players[i]
if ( gHasDarthMaul[player] ) {
sh_add_hp(player, healPoints)
}
}
}
//----------------------------------------------------------------------------------------------
#if defined USE_WPN_MODEL
public Ham_Knife_Deploy_Post(wpnEntId)
{
// Who is the owner of this weapon entity?
new owner = pev(wpnEntId, pev_owner)
switch_model_knife(owner)
return HAM_IGNORED
}
//----------------------------------------------------------------------------------------------
switch_model_knife(id)
{
if ( !sh_is_active() || !is_user_alive(id) || !gHasDarthMaul[id] ) return
// If user has a shield do not change model, since we don't have one with a shield
if ( cs_get_user_shield(id) ) return
set_pev(id, pev_viewmodel2, gModelKnifeV)
set_pev(id, pev_weaponmodel2, gModelKnifeP)
}
//----------------------------------------------------------------------------------------------
#endif
This thread has gone offtopic, should really be a separate thread.