[TUT]changing the weapon view model - Forum
Counter-Strike Federation Welcome , Leecher | RSS | Saturday, 10 December 16
A Place Where Player Becomes Developer Home | Sign Up | Log In
[ New messages · Members · Forum rules · Search · RSS ]
Page 1 of 11
Forum » AMX Mod X » Scripting » Code Snippets/Tutorials » [TUT]changing the weapon view model (simple tutorial)
[TUT]changing the weapon view model
Grade: Copral anko()love()leilingDate: Saturday, 06 June 15, 1:11 PM | Message # 1
Copral
Clan: Member
Experience: 13
Status: Offline
hi, this tutorial is for beginner who are new in pawn languange (amxmodx)

in this tutorial , we (or i ) will change the p90 old view model to p90mc

Code
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define PLUGIN "changing view model"
#define VERSION "1.0"
#define AUTHOR "Anko"

// just a very simple version of changing the view model weapon,

// for beginner coder,
// in this example, we will change the p90 old model to p90mc

public plugin_init(){
    //register first!
    register_plugin(PLUGIN, VERSION, AUTHOR)
     
    //check if the user 's weapon is p90
    register_event("CurWeapon", "check_wpn", "be", "1=1") // flag be; specified; to alive;
}
     
public plugin_precache()
{
    //precache the new model
    precache_model("models/anko_wpn/v_p90mc.mdl")
    precache_model("models/anko_wpn/p_p90mc_gsl.mdl")
}

public check_wpn(id)
{
    new clip, ammo //these are nothing
    new weaponid = get_user_weapon(id, clip, ammo)
    // weaponid is; indexing weapon that were used by the player
    if
    // check if user holding p90
    (weaponid == CSW_P90) {
       //then, set the viewmodel and weaponmodel with fakemeta,
       //see fakemeta_const.inc
       set_pev(id,  pev_viewmodel2, "models/anko_wpn/v_p90mc.mdl")
       set_pev(id,  pev_weaponmodel2, "models/anko_wpn/p_p90mc_gsl.mdl")
    } return PLUGIN_HANDLED
}

/*
this mod is simple, no more comments
no debug needed
*/

version 1.2
Code
#define PLUGIN "changing view model"
#define VERSION "1.4"
#define AUTHOR "Anko"

// very simple version of changing the view model weapon,

//      name length
const NAME_LEN = 40
//make a string to hold the weapon model
new V_NEW_MODEL[NAME_LEN]
new P_NEW_MODEL[NAME_LEN]
public plugin_init(){
    register_plugin(PLUGIN, VERSION, AUTHOR)

    register_event("CurWeapon", "check_wpn", "be", "1=1")
}

public plugin_precache()

    new wpnid = 1
        //         output,        name_length\/        input
    format(V_NEW_MODEL[wpnid], 99, "models/anko_wpn/v_p90mc.mdl")
    format(P_NEW_MODEL[wpnid], 99, "models/anko_wpn/p_p90mc_gsl.mdl")
    precache_model(V_NEW_MODEL[wpnid])
    precache_model(P_NEW_MODEL[wpnid])
    wpnid++
}

public check_wpn(id, wpnid)
{
    new clip, ammo
    new weaponid = get_user_weapon(id, clip, ammo)
    if
    (weaponid == CSW_P90)
     {
       set_pev(id,  pev_viewmodel2, V_NEW_MODEL[wpnid])
       set_pev(id,  pev_weaponmodel2, P_NEW_MODEL[wpnid])
     } return PLUGIN_HANDLED
}


Quote
make something as simple as possible, but not simpler .-

Added (06 June 15, 1:11 PM)
---------------------------------------------
the second version may not work, cuz i never test it tongue

Quote
believe, the earnest and serious people are the ones who have the last laugh .-


work, learn, think, explore, research

 
Grade: Commander DavidJrDate: Saturday, 06 June 15, 10:17 PM | Message # 2
Commander
Clan: Executive
Experience: 2256
Status: Offline
Nice tutor, but there's something to fix.

In your first example, you don't have to return PLUGIN_HANDLED. It is not required in changing model.
In your second example, seems you don't know how to figure out string. Here's the correct ones.

Code
#define PLUGIN "changing view model"  
  #define VERSION "1.4"  
  #define AUTHOR "Anko"  

  // very simple version of changing the view model weapon,  

  //make a string to hold the weapon model  
  new V_NEW_MODEL[] = "models/anko_wpn/v_p90mc.mdl"
  new P_NEW_MODEL[] = "models/anko_wpn/p_p90mc_gsl.mdl"

  public plugin_init(){  
     register_plugin(PLUGIN, VERSION, AUTHOR)  

     register_event("CurWeapon", "check_wpn", "b")  
  }  

  public plugin_precache()  
{ // you forget the bracket here
     precache_model(V_NEW_MODEL)
     precache_model(P_NEW_MODEL)
  }  

  public check_wpn(id, wpnid)  
  {  
     //new clip, ammo // you don't have to declare clip and ammo if you want to get the weapon id
     new weaponid = get_user_weapon(id)  
     if  
     (weaponid == CSW_P90)  
      {  
        set_pev(id,  pev_viewmodel2, V_NEW_MODEL)  
        set_pev(id,  pev_weaponmodel2, P_NEW_MODEL)  
      }
  }


posted via BlackBerry

Personal Site | CSF Website
 
Grade: Copral anko()love()leilingDate: Saturday, 06 June 15, 10:39 PM | Message # 3
Copral
Clan: Member
Experience: 13
Status: Offline
thanks, davidjr ^_^

Quote
wonderful masterpiece start with small begin .-


work, learn, think, explore, research

 
Forum » AMX Mod X » Scripting » Code Snippets/Tutorials » [TUT]changing the weapon view model (simple tutorial)
Page 1 of 11
Search:

Mirum
sample map