AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=43)
-   -   2 switchmodel in the same code (https://forums.alliedmods.net/showthread.php?t=336009)

Arje 01-21-2022 12:13

2 switchmodel in the same code
 
Hello, I would like to be able to make two model changes in this code

PHP Code:



register_event
("CurWeapon""weapon_change""be""1=1")
register_event("Damage""batman_damage""b""2!0")


//----------------------------------------------------------------------------
public sh_hero_init(idheroIDmode)
{
    if ( 
gHeroID != heroID ) return

    switch(
mode) {
        case 
SH_HERO_ADD: {
            
gHasBatman[id] = true
            batman_giveweapons
(id)
            
switch_model(id)
        }
        case 
SH_HERO_DROP: {
            
gHasBatman[id] = false
            batman_dropweapons
(id)
        }
    }

    
sh_debug_message(id1"%s %s"gHeroNamemode "ADDED" "DROPPED")
}

//------------------------------------------------------------------
public weapon_change(id)
{
    
//do nothing if client does not have hero or sh is off
    
if ( !sh_is_active() || !gHasBatman[id] ) return
    
    new 
weaponID read_data(2)
    if (
weaponID !=CSW_KNIFE) return
        
switch_model(id)
        
    
//the read data is reading the weapon the client has out
    
new weaponID read_data(2)
    
//and if the client does not have the m4a1 out just do nothing
    
if (weaponID !=CSW_XM1014) return
        
switch_model(id)
        
    if (
read_data(3) == 0)
        {
        
sh_reload_ammo(id1)
        }
}
//---------------------------------------------------------------------
switch_model(id)
{
    
//if the sh mod is off the client is dead or he does not have the hero we do not want to let him have the weapon model!
    
if (!sh_is_active() || !is_user_alive(id) || !gHasBatman[id] ) return
    
    
//and now we check again if he still has the m4a1 out
    
if (get_user_weapon(id) == CSW_XM1014)
    {
        
//now he has all the requirements to have the weapon model so we also need to give it to him
    
set_pev(idpev_viewmodel2gBatItaca)
    
set_pev(idpev_weaponmodel2gBatItaca2)
    }    
    
    if (
get_user_weapon(id) == CSW_KNIFE)
    {
    
set_pev(idpev_viewmodel2gBatKnife)    
    }



heliumdream 02-26-2022 11:13

Re: 2 switchmodel in the same code
 
unclear on what your problem is;

i would refer to an existing model swap code to make sure you do it right, like master chief here:
https://forums.alliedmods.net/showpo...&postcount=140

be sure you are precaching and defining the new models earlier in the code. i dont see those in your snippet here.

Arje 02-26-2022 18:40

Re: 2 switchmodel in the same code
 
I had also fixed this at the time, what I wanted to do was put two different weapon models of different weapons on the same hero, what worked for me was the following:
PHP Code:

// Const de Models para ponerse
new const gBatItaca[] = "models/shmod/bat_itaca_v.mdl"
new const gBatItaca2[] = "models/shmod/bat_itaca_p.mdl"
new const gBatKnife[] = "models/shmod/batmanknife_v.mdl"


public plugin_init()
{
     
register_event("CurWeapon""weapon_change1""be""1=1")
    
register_event("CurWeapon""weapon_change2""be""1=1")
}

public 
plugin_precache()
{
    
precache_model("models/shmod/batmanknife_v.mdl")
    
precache_model("models/shmod/bat_itaca_v.mdl")
    
precache_model("models/shmod/bat_itaca_p.mdl")
}

public 
weapon_change1(id)
{
    
//do nothing if client does not have hero or sh is off
    
if ( !sh_is_active() || !gHasBatman[id] ) return    
    
//the read data is reading the weapon the client has out
    
new weaponID read_data(2)
    
//and if the client does not have the m4a1 out just do nothing
    
if (weaponID !=CSW_XM1014) return
    
switch_model(id)
        
    if (
read_data(3) == 0) {
        
//so if he is out of ammo just reload it
        
sh_reload_ammo(id2)
        
/*after the id I made a 1 number
        look at the superheromod.inc and you will see this
        0 - follow server sh_reloadmode CVAR
        1 - continuous shooting, no reload
        2 - fill the backpack (must reload)
        3 - drop the gun and get a new one with full clip
        That should explain it*/
    
}
}

public 
weapon_change2(id)
{
    if ( !
sh_is_active() || !gHasBatman[id] ) return    
    
// esto es para qe no se pongan el model si usamos el escuditos de putos
    
new v_mdl[32]
    
Entvars_Get_String(idEV_SZ_viewmodelv_mdl31)
    if ( 
containi(v_mdl"v_shield_") != -) return
    
    new 
kweaponID read_data(2)
    
//and if the client does not have the m4a1 out just do nothing
    
if (kweaponID !=CSW_KNIFE) return
    
switch_model(id)    
}

switch_model(id)
{
    
//if the sh mod is off the client is dead or he does not have the hero we do not want to let him have the weapon model!
    
if (!sh_is_active() || !is_user_alive(id) ) return
    
    
//and now we check again if he still has the m4a1 out
    
if (get_user_weapon(id) == CSW_XM1014) {
        
//now he has all the requirements to have the weapon model so we also need to give it to him
        
set_pev(idpev_viewmodel2gBatItaca)
        
set_pev(idpev_weaponmodel2gBatItaca2)
        }

    if (
get_user_weapon(id) == CSW_KNIFE) {
        
//now he has all the requirements to have the weapon model so we also need to give it to him
        
set_pev(idpev_viewmodel2gBatKnife)
        }


shorten the code, to put only what I did, but the solution was to add another curweapon event, it is the solution that I found at the moment I don't know if there is another way


All times are GMT -4. The time now is 13:42.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.