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

[Tutorial] Learn the new ways


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 02-28-2010 , 05:51   [Tutorial] Learn the new ways
Reply With Quote #1

Welcome to the beginner's Superhero Tutorial

As you might see, I used rolbaaba's tutorial to help setting this up.
If you have any questions about how to use a native you can always look it up in superheromod.inc in your include folder. In there each param in the native is explained.

Helpful links:

Important links
Make a superhero admin only (using the old method)
Good Programing Habits
Event Usage

Introduction/Prolouge
Beaware that anywhere you see "Super" or "Super Hero" should be changed to your hero's name.
Apparently many people is confused by this, so I write it here pretty quick. You should only have ONE plugin_init(), ONE sh_hero_init() and so on.
Also, many people, when dealing with health and armor makes two times sh_set_hero_hpap(). It is only needed to do that ONCE, not twice. You can add both hp AND ap in the same native.
Now before we begin these things you must know how to make a superhero:
First (conventionally) are your includes, basic includes for most heroes are as follows:

PHP Code:
#include<superheromod> 
if you need other includes besides this I will note them for you, otherwise these are always included in a superhero script.

Next you declare your glabal varriables which will include your hero's name, and if they have your hero's powers or not. (other varrs will be added later for special powers), in this tutorial the hero's name is: Super, but of course you will change Super to whatever you want your hero to be called.

PHP Code:
new gHeroID
new const 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 
Now comes the plugin_init this is where all registers go that will be used in your plugin:

PHP Code:
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(gHeroNamepcvarLevel)
    
//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

Now your Hero's Init function, this is called anytime someone picks your hero:

PHP Code:
public sh_hero_init(idheroIDmode)
{
    
//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
        
}
    }

Putting these together creates:

PHP Code:
//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(gHeroNamepcvarLevel)
    
//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(idheroIDmode)
{
    
//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
        
}
    }

This Hero doesnt do anything but let you select them so lets make it actually do something:

1. To create a hero with increased health simply do the following:

PHP Code:
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 health:
    
new pcvarHealth register_cvar("super_health""150")
    
    
//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 health accordingly to the cvar super_health. The "0" after pcvarHealth is the armor.
    //and since we did not add any armor power we write 0
    
sh_set_hero_hpap(gheroIDpcvarHealth0)

2. To create a hero with increased armor simply do the following:

PHP Code:
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 armor:
    
new pcvarArmor register_cvar("super_armor""150")
    
    
//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 armor accordingly to the cvar super_armor. The "0" before pcvarArmor is the health.
    //and since we did not add any health power we write 0
    
sh_set_hero_hpap(gheroID0pcvarArmor)    

3. To add gravity to your hero simply do this:

PHP Code:
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 gravity:
    
new pcvarGrav register_cvar("super_grav""0.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 gravity accordingly to the cvar super_grav.
    
sh_set_hero_grav(gHeroIDpcvarGrav)
    
//if you want to set the gravity accordingly to what weapon the client is using do it like this:
    //sh_set_hero_grav(gHeroID, pcvarGrav, {CSW_M4A1}, 1)
    //to explain it:
    //the gHeroID is pointing at the global variable gHeroID
    //the pcvarGrav is pointing at the cvar
    //the CSW_M4A1 is the weapon you can set more than one weapon to have this gravity with an array

4. To increase the speed simply do this:

PHP Code:
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 speed:
    
new pcvarSpeed register_cvar("super_speed""400")
    
    
//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 speed accordingly to the speed cvar
    
sh_set_hero_speed(gHeroIDpcvarSpeed)
    
//this works just like the gravity native so I wont explain this just write it
    //sh_set_hero_speed(gHeroID, pcvarSpeed, {CSW_M4A1}, 1)

5. To make a damage multiplier has gotten much easier!

PHP Code:
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(gHeroIDpcvarMultCSW_M4A1)

6. It is pretty simple to add a playermodel. You just precache the model and tells when it should be applied:

PHP Code:
//now we make a new global variable to hold the path of the playermodel
new const gSuperPlayer[] = "models/player/super/super.mdl"

public sh_hero_init(idheroIDmode)
{
    
//you should now know what should be going here
    
    //now we actually have to use the switch (mode) part in the init.
    
switch (mode)
    {
        
//remember what this does?
        
case SH_HERO_ADD:
        {
            
//Remember what this does?
            
gHasSuperPower[id] = true
            
//this is what you should add
            //this means that we are going to set the model in the super_morph and not here since that will create allot of confusion
            //remember this is only if the user picks the hero this runs
            
super_morph(id)
        }
        
//remember what this does?
        
case SH_HERO_DROP:
        {
            
//remember what this does?
            
gHasSuperPower[id] = false
            
//this is also new.
            //If the client has the hero and then drops it, we want to take his playermodel from him so we go to super_unmorph and do that there
            //same here this only runs when the user drops the hero
            
super_unmorph(id)
        }
    }
}

//we need to precache the playermodel before we can use it (this means the client has to download it or he will not be able to see it
public plugin_precache()
{
    
//remember to use the function precache_model for models
    
precache_model(gSuperPlayer//I already told where the playermodel is located, so all I have to do is just write the global variable
}

//this runs each time a player is spawning but you probably figured that one out by the name
public sh_client_spawn(id)
{
    
//first we check if the user has the hero or not
    
if (gHasSuperPower[id])
    {
        
//then we can go and set the playermodel
        
super_morph(id)
    }
}

//it is here where we set the playermodel for the player
super_morph(id)
{
    
//remember that after the id you have to write the filename witch has to be the model. In this case super.mdl is our model. Do not write .mdl after the filename
    
cs_set_user_model(id"super")
}

//it is here where we take off the playermodel if a user dropped the hero
super_unmorph(id)
{
    
//yeah, we just reset the playermodel to the original one
    
cs_reset_user_model(id)

7. This is what you have to do to add a weapon model

PHP Code:
//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(idheroIDmode)
{
    
//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(idCSW_M4A1true)
                
//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(idCSW_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(id1)
        
/*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(idpev_viewmodel2gSuperWeapon)
    }

8. By request I now add p model too. You need to look at the v (#7), and make that too. I did it that way since, well, lets face it, who sets a p model without a v model??

PHP Code:
//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(idpev_weaponmodel2gSuperWeapon2)
    }

__________________
No idea what to write here...

Last edited by Jelle; 02-24-2011 at 10:36.
Jelle is offline
Send a message via MSN to Jelle
Steak243
Senior Member
Join Date: May 2009
Old 02-28-2010 , 08:15   Re: [Tutorial] Learn the new ways
Reply With Quote #2

Big thumbs up man. Nice layout and nice explanation
Steak243 is offline
kanatzu
Veteran Member
Join Date: Oct 2007
Location: Sweden
Old 02-28-2010 , 09:54   Re: [Tutorial] Learn the new ways
Reply With Quote #3

Very nice Jelle.

Impressing how the newer style is ... alot, more easier!

Just woow, its like 100% shorter then the old one!


Thanks!
__________________




Quote:
Originally Posted by wrecked_ View Post
Stop saying words before I sodomize you with a cucumber.
kanatzu is offline
Send a message via MSN to kanatzu
The Art of War
Veteran Member
Join Date: Dec 2009
Location: Sweden Rock Festival
Old 02-28-2010 , 10:50   Re: [Tutorial] Learn the new ways
Reply With Quote #4

Yeah no shit! Good job!

Just one thing: Freeman always yells at me telling me that native_damage is much better then sh_mult
What is best?
__________________
The Art of War is offline
Fr33m@n
Veteran Member
Join Date: May 2008
Location: France Marne
Old 02-28-2010 , 12:09   Re: [Tutorial] Learn the new ways
Reply With Quote #5

The best is that you want.

In the first method we have an extra damage send into a client_damage.

In other method we have this new native sh_set_hero_dmgmult.

example is more clear :
in these two case we have 3 dmg mult heroes for the same weapon
we also have an user who have who have these 3 heroes
mult for them 1.2, 1.4, 1.6

first case :
damage = normaldamage * 1.2 * 1.4 * 1.6

second case (sh_set_hero_dmgmult):
mult are compared
damage = normaldamage * 1.6
You don't need to have 10000 heroes for one weapon's damage mult.
he can drop the 1.2 and 1.4 heroes and only keeep the 1.6

Last edited by Fr33m@n; 02-28-2010 at 12:12.
Fr33m@n is offline
The Art of War
Veteran Member
Join Date: Dec 2009
Location: Sweden Rock Festival
Old 02-28-2010 , 12:16   Re: [Tutorial] Learn the new ways
Reply With Quote #6

Yeah, thx! So if you use the first one, you can stack like 5 heroes to get 10.0 dmg mult with m4? xD
__________________
The Art of War is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 02-28-2010 , 16:16   Re: [Tutorial] Learn the new ways
Reply With Quote #7

Thank you for the appreciation of what I have done so far.

When I have time I will add playermodel and all basic hero stuff.
But I also need to work on the generator.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
The Art of War
Veteran Member
Join Date: Dec 2009
Location: Sweden Rock Festival
Old 03-03-2010 , 05:55   Re: [Tutorial] Learn the new ways
Reply With Quote #8

Well Jelle, you basically composed a tutorial thats a l0t easier then others! I know you are busy at the supermarket and working on JTP's Hero Generator to 1.2 ways, but could you or *someone* post some ham_natives? Like ham_block_damage etc?
Thx!

Hahaha yeah Viktor, I told you that the 1.2 ways are easier then the old ones! As an example, the .sma file is about half the size in kb's then stuff made in the old ways, and like half length of text as the old ones...

Again GJ Jelle gogo
__________________
The Art of War is offline
Fr33m@n
Veteran Member
Join Date: May 2008
Location: France Marne
Old 03-03-2010 , 06:42   Re: [Tutorial] Learn the new ways
Reply With Quote #9

Art of War look at ham includes for more explanation.
(hamsandwich.inc ham_const.inc)
Fr33m@n is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 03-03-2010 , 07:30   Re: [Tutorial] Learn the new ways
Reply With Quote #10

I have never used ham myself so to be honest I do not know anything about it. Checking the includes is probably the best way to go.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Reply


Thread Tools
Display Modes

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 14:34.


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