Raised This Month: $51 Target: $400
 12% 

[Tutorial] Learn how to change to the new ways


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 10-22-2023 , 01:19   [Tutorial] Learn how to change to the new ways
Reply With Quote #1

I decided to make this post so that you can finish understanding how to re-make the heroes or transfer them to new forms in case anyone wants to start and get started

Why change to the new ways?
Because the fact of being able to use the new forms simplifies being able to make better interactions between heroes, for example if we wanted a way to prevent Magneto from affecting a player who has the hero Noob, the new forms would be necessary.

If we wanted to make a cooldown visible to heroes who have cooldown we would also need these new forms

If we wanted to make a menu to be able to choose between all the knife skins that we have for the heroes depending on whether the hero has it or not, it is also necessary


I recommend that if you are new, you first start reading this tutorial on how to create a hero from scratch, it is quite simple to understand:

[Tutorial] Learn the new ways


Continuing with how to change, first we are going to see how to change the simplest heroes, that is, those that do not have keypowers.

In this case I am going to give an example with the hero "Noob" that we already know:


The first thing we have to generate is a global variables gHeroID that refers to the hero to be able to reuse it
PHP Code:
// GLOBAL VARIABLES
new gHeroName[]="Noob"
new gHasNoobPower[SH_MAXSLOTS+1

PHP Code:
// GLOBAL  VARIABLES
new gHeroID
new gHeroName[]="Noob"
new gHasNoobPower[SH_MAXSLOTS+1
The next change comes in the function public plugin_init() here we must make changes to how the hero starts
PHP Code:
public plugin_init()
{
    
// Plugin Info
    
register_plugin("SUPERHERO Noob","1.3","AssKicR")

    
register_cvar("noob_level""0")
    
register_cvar("noob_arrows""3")
    
register_cvar("noob_getdeagle""1")

    
// FIRE THE EVENT TO CREATE THIS SUPERHERO!
    
shCreateHero(gHeroName"exploding deagle shots""U WILL HAVE A DEAGE WITH 3 EXPLODING SHOTS!!"false"noob_level")

    
// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
    // INIT
    
register_srvcmd("noob_init""noob_init")
    
shRegHeroInit(gHeroName"noob_init"

PHP Code:
public plugin_init()
{
    
// Plugin Info
    
register_plugin("SUPERHERO Noob","1.3","AssKicR")

    new 
pcvarLevel    register_cvar("noob_level""0")
    
register_cvar("noob_arrows""3")
    
register_cvar("noob_getdeagle""1")

    
// FIRE THE EVENT TO CREATE THIS SUPERHERO!
    
gHeroID sh_create_hero(gHeroNamepcvarLevel)
    
sh_set_hero_info(gHeroID"exploding deagle shots""U WILL HAVE A DEAGE WITH 3 EXPLODING SHOTS!!"
As you could see we eliminated the function calls
// INIT
register_srvcmd("noob_init", "noob_init")
shRegHeroInit(gHeroName, "noob_init")

and we change how the hero is registered

What follows now is to eliminate the following function and replace it with this one, but before eliminating this function we must pay attention to some events that the hero has when we choose him, for example:
PHP Code:
public noob_init()
{
    new 
temp[128]
    
// First Argument is an id
    
read_argv(1,temp,5)
    new 
id=str_to_num(temp)

    
// 2nd Argument is 0 or 1 depending on whether the id has garrow
    
read_argv(2,temp,5)
    new 
hasPowers=str_to_num(temp)
    
gHasNoobPower[id]=(hasPowers!=0)
    
    if ( 
gHasNoobPower[id] ) {
        
shGiveWeapon(id,"weapon_deagle")
    }
    else {
        
sh_drop_weapon(idCSW_DEAGLEtrue)
    }

we have to pay attention to the part of
PHP Code:
if ( gHasNoobPower[id] ) {
        
shGiveWeapon(id,"weapon_deagle")
    }
    else {
        
sh_drop_weapon(idCSW_DEAGLEtrue)
    } 
What we have to understand from this fragment is what functions occur when it is added and when it is dropped


So to achieve a correct change with the events it shows us we have to do the following:
PHP Code:
public sh_hero_init(idheroIDmode)
{
    if ( 
gHeroID == heroID ) {
        switch(
mode) {
            case 
SH_HERO_ADD: {
                
gHasNoobPower[id] = true
                shGiveWeapon
(id,"weapon_deagle")
            }
            case 
SH_HERO_DROP: {
                
gHasNoobPower[id] = false
                sh_drop_weapon
(idCSW_DEAGLEtrue)
            }
        }
            
        
sh_debug_message(id1"%s %s"gHeroNamemode "ADDED" "DROPPED")
    }

Thus we conclude with how to write a hero without key powers, we can notice but a small difference in generic simplification in the code, but the most important thing is not that, but that it allows us to eventually be able to perform the actions that I mentioned at the beginning

In the end we should pass the code, it should look something like this, (although of course I am ignoring many more events that are called from the init plugin but that are not relevant to registering the hero)


PHP Code:
// VARIABLES
new gHeroName[]="Noob"
new gHasNoobPower[SH_MAXSLOTS+1]

//----------------------------------------------------------------------------------------------
public plugin_init()
{
    
// Plugin Info
    
register_plugin("SUPERHERO Noob","1.3","AssKicR")

    
register_cvar("noob_level""0")
    
register_cvar("noob_arrows""3")
    
register_cvar("noob_getdeagle""1")

    
// FIRE THE EVENT TO CREATE THIS SUPERHERO!
    
shCreateHero(gHeroName"exploding deagle shots""U WILL HAVE A DEAGE WITH 3 EXPLODING SHOTS!!"false"noob_level")

    
// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
    // INIT
    
register_srvcmd("noob_init""noob_init")
    
shRegHeroInit(gHeroName"noob_init")
}

public 
noob_init()
{
    new 
temp[128]
    
// First Argument is an id
    
read_argv(1,temp,5)
    new 
id=str_to_num(temp)

    
// 2nd Argument is 0 or 1 depending on whether the id has garrow
    
read_argv(2,temp,5)
    new 
hasPowers=str_to_num(temp)
    
gHasNoobPower[id]=(hasPowers!=0)
    
    if ( 
gHasNoobPower[id] ) {
        
shGiveWeapon(id,"weapon_deagle")
    }
    else {
        
sh_drop_weapon(idCSW_DEAGLEtrue)
    }


PHP Code:
// VARIABLES
new gHeroID
new gHeroName[]="Noob"
new gHasNoobPower[SH_MAXSLOTS+1]
//----------------------------------------------------------------------------------------------
public plugin_init()
{
    
// Plugin Info
    
register_plugin("SUPERHERO Noob","1.3","AssKicR")

    new 
pcvarLevel    register_cvar("noob_level""0")
    
register_cvar("noob_arrows""3")
    
register_cvar("noob_getdeagle""1")

    
// FIRE THE EVENT TO CREATE THIS SUPERHERO!
    
gHeroID sh_create_hero(gHeroNamepcvarLevel)
    
sh_set_hero_info(gHeroID"exploding deagle shots""U WILL HAVE A DEAGE WITH 3 EXPLODING SHOTS!!")
}

public 
sh_hero_init(idheroIDmode)
{
    if ( 
gHeroID == heroID ) {
        switch(
mode) {
            case 
SH_HERO_ADD: {
                
gHasNoobPower[id] = true
                shGiveWeapon
(id,"weapon_deagle")
            }
            case 
SH_HERO_DROP: {
                
gHasNoobPower[id] = false
                sh_drop_weapon
(idCSW_DEAGLEtrue)
            }
        }
            
        
sh_debug_message(id1"%s %s"gHeroNamemode "ADDED" "DROPPED")
    }

Arje is offline
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 13:16.


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