Raised This Month: $32 Target: $400
 8% 

How To Make a Gun Hero


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KingJTellem
Member
Join Date: Dec 2011
Old 06-24-2014 , 10:13   How To Make a Gun Hero
Reply With Quote #1

Hi how do i make a gun hero with only damage & level. I got the V,W & P model juat need to make it for a hero.

Fx:
//Gun
Gun_level 0
Gun_gunmult 2.0 //Gun damage
KingJTellem is offline
anon12
Member
Join Date: Aug 2013
Old 06-24-2014 , 16:18   Re: How To Make a Gun Hero
Reply With Quote #2

There's a few tutorial on how to create a hero (including guns)
https://forums.alliedmods.net/showthread.php?t=54155
https://forums.alliedmods.net/showthread.php?t=120051

Or you could rip some heroes off by changing the name and the weapon model.
anon12 is offline
KingJTellem
Member
Join Date: Dec 2011
Old 06-25-2014 , 11:50   Re: How To Make a Gun Hero
Reply With Quote #3

So if i make this would it be a hero with gun ?

Quote:
//Yeah, we include superheromod for this one
#include <superheromod>

new gHeroID
new gHeroName[] = "super" //creates a string varr to hold the hero name
new bool:gHasSuperPower[SH_MAXSLOTS+1] //creates a varr with an aray, with 1 slot per player

public plugin_init()
{
//This registers the plugin with amx mod x. This is what is shown when you type amx_plugins in console
register_plugin("SUPERHERO super", "1.0", "Jelle")

//now we register the cvars
//you can make the "pcvarLevel" to what ever you want, but make sure it matches this each time you use it
new pcvarLevel = register_cvar("super_level", "0") //this is what level the hero should be avalible at

//This is what creates the hero remember the pcvarLevel is pointing at the level for the hero
gHeroID = sh_create_hero(gHeroName, pcvarLevel)
//This is setting the hero info. It pretty much explains itself
sh_set_hero_info(gHeroID, "short decription", "long decription")

//if you were used to the old method you will notice that there is no need to register the init anymore therefor nothing more is required
}

public sh_hero_init(id, heroID, mode)
{
//if no power return
if (gHeroID != heroID) return

//This is what runs when someone drops or picks the hero
switch(mode)
{
//if the hero is added
case SH_HERO_ADD:
{
//it is true that client has the hero
gHasSuperPower[id] = true
}
//if the hero is dropped
case SH_HERO_DROP:
{
//it is false that the client has the hero
gHasSuperPower[id] = false
}
}
}
public plugin_init()
{
//the code you already made should be here
//Be sure to set the cvars as the first thing in your plugin
//you now add a cvar for multiplier:
new pcvarMult = register_cvar("super_mult", "5")

//and now you set the hero power. Remember this should be after you create the hero with sh_create_hero!
//with this native I set the hero multiplier accordingly to the multiplier cvar
sh_set_hero_dmgmult(gHeroID, pcvarMult, CSW_M4A1)
}
public plugin_init()
{
//the code you already made should be here
//Be sure to set the cvars as the first thing in your plugin
//you now add a cvar for multiplier:
new pcvarMult = register_cvar("super_mult", "5")

//and now you set the hero power. Remember this should be after you create the hero with sh_create_hero!
//with this native I set the hero multiplier accordingly to the multiplier cvar
sh_set_hero_dmgmult(gHeroID, pcvarMult, CSW_M4A1)
}
//now we make a new global variable to hold the path of the gun model
new const gSuperWeapon[] = "models/shmod/v_super_m4a1.mdl"

public plugin_init()
{
//all the plugin_init stuff should be here. All the cvars you made so far and the hero creating etc goes here

//and now we can register the CurWeapon event. This runs each time the user changes his weapon
register_event("CurWeapon", "weapon_change", "be", "1=1")
}
public sh_hero_init(id, heroID, mode)
{
//you should now know what should be going here

//again we are using the hero init to set the weapon model if the hero is picked
switch (mode)
{
//You know what this is
case SH_HERO_ADD:
{
gHasSuperPower[id] = true
//this is what is new
//this tells that we are going to super_weapons to give out a free weapon
super_weapon(id)
//here when the hero is picked we also go to set the weapon model or he will first get it when he spawn next time
switch_model(id)
}
//You know what this is
case SH_HERO_DROP:
{
gHasSuperPower[id] = false
//now we check if the user is alive if user drops this hero while alive he should not be able to use the gun
if (is_user_alive(id))
{
//this drops the weapon
sh_drop_weapon(id, CSW_M4A1, true)
//the true value I set means that when the weapon is dropped it disappears so user cannot just pick it up again
}
}
}
}

public sh_client_spawn(id)
{
//check if they have the power
if (gHasSuperPower[id])
{
//go and give free gun if it is true that the user has the hero
super_weapon(id)
}
}

//yes now we actually give the free gun
super_weapon(id)
{
//before we just handle the gun out to this crazy maniac we have to check if sh is actually running and that the user is alive and he has the hero
if (sh_is_active() && is_user_alive(id) && gHasSuperPower[id] )
{
//if all this is true we can safely give him his gun
sh_give_weapon(id, CSW_M4A1)
}
}

//now we use the registered event
public weapon_change(id)
{
//do nothing if client does not have hero or sh is off
if ( !sh_is_active() || !gHasSuperPower[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_M4A1) return

//now we checked if the user does not have the m4a1 out. If he does not the code stops here
//if he does have m4a1 out then we continue so now we set the weapon model for the m4a1 since he is having that gun out
//yes we are going to do it in switch_models since that makes most sense
switch_model(id)

//now, we do not want the guy to run out of ammo so we just give him an unlimited amout of it
//this is reading how many bullets there are left in the gun
if (read_data(3) == 0)
{
//so if he is out of ammo just reload it
sh_reload_ammo(id, 1)
/*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*/
}
}

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) || !gHasSuperPower[id] ) return

//and now we check again if he still has the m4a1 out
if (get_user_weapon(id) == CSW_M4A1)
{
//now he has all the requirements to have the weapon model so we also need to give it to him
set_pev(id, pev_viewmodel2, gSuperWeapon)
}
}
//now we make a new global variable to hold the path of the gun model
new const gSuperWeapon2[] = "models/shmod/p_super_m4a1.mdl"

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) || !gHasSuperPower[id] ) return

//and now we check again if he still has the m4a1 out
if (get_user_weapon(id) == CSW_M4A1)
{
//now he has all the requirements to have the weapon model so we also need to give it to him
set_pev(id, pev_weaponmodel2, gSuperWeapon2)
}
}
KingJTellem is offline
anon12
Member
Join Date: Aug 2013
Old 06-25-2014 , 16:51   Re: How To Make a Gun Hero
Reply With Quote #4

u cant have more than 2 plugins_init at once

something like this: (from rolnaaba's code)
PHP Code:
#include <amxmodx>
#include <superheromod> 
#include <fakemeta>

new gHeroName[]="Hero Name" //creates a string varr to hold your hearo's name
new bool:gHasGun[SH_MAXSLOTS+1//creates a varr with an aray, with 1 slot per player 

new g_p_model//must be outside plugin_init so it can be global
new g_v_model;

public 
plugin_init() 
{
    
register_plugin("SUPERHERO Super""1.0""Rolnaaba"); //register plugin (you should know what this is)
    
    
register_cvar("Super_level""1"); //level required to select hero

    
shCreateHero(gHeroName"Gun Hero desc1""Gun Hero Desc2"false"Super_level"); 
    
//superheromod.inc: 
    //stock  shCreateHero(heroName[], heroPower[], heroHelp[], bool:requiresKeyEvents, heroLevel[])

    
register_srvcmd("Super_init""Super_init"); //register your hero's init function with server
    
    
shRegHeroInit(gHeroName"Super_init"); //register your hero's init with superheromod
    
    
register_event("Damage""Event_damage","b");
    
register_cvar("Supher_mult""1.5"); //how much damage to do (1.5 x normal_damage)

}
public 
plugin_precache() 
{   
    
g_p_model precache_model("models/shmod/Super/p_weapon_model.mdl"); //makes players download the model
    
g_v_model precache_model("models/shmod/Super/v_weapon_model.mdl");
}
public 
Super_init() 
{
    new 
temp[6]; //declare a temperary varriable
    
read_argv(1,temp,5); //reading the first argument will give you the id of the person who selected your hero
    
new id str_to_num(temp); //transfer the string returned into a number and store it as the id

    
read_argv(2,temp,5); //second argument is whether they have the power or not
    
    
new hasPowers str_to_num(temp);

    
gHasGun[id] = (hasPowers != 0); //(hasPowers != 0) will either return 1 (if it is true that hasPowers != 0), or 0 (if it is false that hasPowers != 0)
    
if(hasPowers) { //if they have power
        
Super_set_model(id//go to set model funciton
    
}
}
public 
Super_set_model(id
{
    if (!
shModActive() || !is_user_alive(id) || !gHasGun[id])  return;

    new 
clipammowpnid get_user_weapon(id,clip,ammo);

    if(
wpnid == CSW_AK47) {
        
set_pev(idpev_viewmodelengfunc(EngFunc_AllocStringg_v_model));//view model
        
set_pev(idpev_weaponmodelengfunc(EngFunc_AllocStringg_p_model));//player model
    
}
}
public 
Event_damage(id) {
    if (!
shModActive() || !is_user_alive(id)) return PLUGIN_CONTINUE;

    new 
damage read_data(2); //this is covered in my events tut. (in helpful links)
    
new weaponbodypartattacker get_user_attacker(idweaponbodypart//store what weapon used, bodypart hit, and attacker
    
new headshot bodypart == //this is just short for:
 

    
if(attacker <= || attacker SH_MAXSLOTS ) return PLUGIN_CONTINUE//checks ifs it was world that did the damage, and if so just end function.

    
if(gHasGun[attacker] && is_user_alive(id)) { //if alive and have power
        
    
new extraDamage floatround(damage get_cvar_float("Super_mult") - damage); //calculate extra damage ([damage done x multiplier] - damage done = extra damage)
    
    
if (extraDamage 0) {
        
shExtraDamageidattackerextraDamage"Super damage Mult"headshot ); //superheromod.inc: stock shExtraDamage(id, attacker, damage, weaponDescription[], headshot = 0);
    
}
    }
    return 
PLUGIN_HANDLED;

anon12 is offline
KingJTellem
Member
Join Date: Dec 2011
Old 06-25-2014 , 17:53   Re: How To Make a Gun Hero
Reply With Quote #5

Thanks how do i make the weapon spawn every time?
KingJTellem is offline
anon12
Member
Join Date: Aug 2013
Old 06-25-2014 , 18:18   Re: How To Make a Gun Hero
Reply With Quote #6

Something like this:
PHP Code:
#include <amxmodx> 
#include <superheromod>  
#include <fakemeta> 

new gHeroName[]="Hero Name" //creates a string varr to hold your hearo's name 
new bool:gHasGun[SH_MAXSLOTS+1//creates a varr with an aray, with 1 slot per player  

new g_p_model//must be outside plugin_init so it can be global 
new g_v_model

public 
plugin_init()  

    
register_plugin("SUPERHERO Super""1.0""Rolnaaba"); //register plugin (you should know what this is) 
     
    
register_cvar("Super_level""1"); //level required to select hero 

    
shCreateHero(gHeroName"Gun Hero desc1""Gun Hero Desc2"false"Super_level");  
    
//superheromod.inc:  
    //stock  shCreateHero(heroName[], heroPower[], heroHelp[], bool:requiresKeyEvents, heroLevel[]) 

    
register_srvcmd("Super_init""Super_init"); //register your hero's init function with server 
    
    
shRegHeroInit(gHeroName"Super_init"); //register your hero's init with superheromod 
     
    
register_event("Damage""Event_damage","b"); 
    
register_cvar("Supher_mult""1.5"); //how much damage to do (1.5 x normal_damage) 
    
register_event("ResetHUD""newSpawn""b")
    

public 
plugin_precache()  
{    
    
g_p_model precache_model("models/shmod/Super/p_weapon_model.mdl"); //makes players download the model 
    
g_v_model precache_model("models/shmod/Super/v_weapon_model.mdl"); 

public 
Super_init()  

    new 
temp[6]; //declare a temperary varriable 
    
read_argv(1,temp,5); //reading the first argument will give you the id of the person who selected your hero 
    
new id str_to_num(temp); //transfer the string returned into a number and store it as the id 

    
read_argv(2,temp,5); //second argument is whether they have the power or not 
     
    
new hasPowers str_to_num(temp); 

    
gHasGun[id] = (hasPowers != 0); //(hasPowers != 0) will either return 1 (if it is true that hasPowers != 0), or 0 (if it is false that hasPowers != 0) 
    
if(hasPowers) { //if they have power 
        
Super_set_model(id//go to set model funciton 
    


public 
newSpawn(id)
{
    if ( 
gHasGun[id] && is_user_alive(id) && shModActive() ) {
        
set_task(0.1"giveweapon"id)

        new 
clipammowpnid get_user_weapon(idclipammo)
        if ( 
wpnid != CSW_AK47 && wpnid ) {
            new 
wpn[32]
            
get_weaponname(wpnidwpn31)
            
engclient_cmd(idwpn)
        }
    }
}
public 
giveweapon(id)
{
    if ( 
is_user_alive(id) && shModActive() ) {
        
shGiveWeapon(id"weapon_ak47")
    }
}
//-----
public Super_set_model(id)  

    if (!
shModActive() || !is_user_alive(id) || !gHasGun[id])  return; 

    new 
clipammowpnid get_user_weapon(id,clip,ammo); 

    if(
wpnid == CSW_AK47) { 
        
set_pev(idpev_viewmodelengfunc(EngFunc_AllocStringg_v_model));//view model 
        
set_pev(idpev_weaponmodelengfunc(EngFunc_AllocStringg_p_model));//player model 
    


public 
Event_damage(id

    if (!
shModActive() || !is_user_alive(id)) return PLUGIN_CONTINUE

    new 
damage read_data(2); //this is covered in my events tut. (in helpful links) 
    
new weaponbodypartattacker get_user_attacker(idweaponbodypart//store what weapon used, bodypart hit, and attacker 
    
new headshot bodypart == //this is just short for: 
  

    
if(attacker <= || attacker SH_MAXSLOTS ) return PLUGIN_CONTINUE//checks ifs it was world that did the damage, and if so just end function. 

    
if(gHasGun[attacker] && is_user_alive(id)) { //if alive and have power 
         
    
new extraDamage floatround(damage get_cvar_float("Super_mult") - damage); //calculate extra damage ([damage done x multiplier] - damage done = extra damage) 
     
    
if (extraDamage 0) { 
        
shExtraDamageidattackerextraDamage"Super damage Mult"headshot ); //superheromod.inc: stock shExtraDamage(id, attacker, damage, weaponDescription[], headshot = 0); 
    

    } 
    return 
PLUGIN_HANDLED

I believe this is called every round so it will give the user the weapon
PHP Code:
register_event("ResetHUD""newSpawn""b"
PHP Code:
public newSpawn(id

    if ( 
gHasGun[id] && is_user_alive(id) && shModActive() ) { 
        
set_task(0.1"giveweapon"id

        new 
clipammowpnid get_user_weapon(idclipammo
        if ( 
wpnid != CSW_AK47 && wpnid ) { 
            new 
wpn[32
            
get_weaponname(wpnidwpn31
            
engclient_cmd(idwpn
        } 
    } 

public 
giveweapon(id

    if ( 
is_user_alive(id) && shModActive() ) { 
        
shGiveWeapon(id"weapon_ak47"
    } 


Last edited by anon12; 06-25-2014 at 18:20.
anon12 is offline
KingJTellem
Member
Join Date: Dec 2011
Old 06-25-2014 , 18:35   Re: How To Make a Gun Hero
Reply With Quote #7

Nice i get the weapon now but the P & V_model dosent show up just the normal ak47.
KingJTellem is offline
anon12
Member
Join Date: Aug 2013
Old 06-25-2014 , 18:37   Re: How To Make a Gun Hero
Reply With Quote #8

Oh right i forgot

Add this in the plugins_init():
PHP Code:
register_event("CurWeapon""weaponChange""be""1=1"
and somewhere below

PHP Code:
public plugin_precache()  
{    
    
g_p_model precache_model("models/shmod/Super/p_weapon_model.mdl"); //makes players download the model 
    
g_v_model precache_model("models/shmod/Super/v_weapon_model.mdl"); 

Add this:
PHP Code:
public weaponChange(id)
{
    if ( !
gHasGun[id] || !shModActive() ) return

    new 
wpnid read_data(2)
    new 
clip read_data(3)

    if ( 
wpnid != CSW_AK47 ) return

    
Super_set_model(id)

    
// Never Run Out of Ammo!
    
if ( clip == ) {
        
shReloadAmmo(id)
    }

anon12 is offline
KingJTellem
Member
Join Date: Dec 2011
Old 06-25-2014 , 18:45   Re: How To Make a Gun Hero
Reply With Quote #9

Okay now the server freeze and says this SV_ModelIndex: model {SUPERHERO Super not precached
KingJTellem is offline
anon12
Member
Join Date: Aug 2013
Old 06-25-2014 , 18:46   Re: How To Make a Gun Hero
Reply With Quote #10

Did you put these files in?
PHP Code:
   g_p_model precache_model("models/shmod/Super/p_weapon_model.mdl"); //makes players download the model  
   
g_v_model precache_model("models/shmod/Super/v_weapon_model.mdl"); 
anon12 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:33.


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