Raised This Month: $ Target: $400
 0% 

Need help with scripting my hero


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
martop5hng
Junior Member
Join Date: Mar 2014
Old 03-08-2014 , 10:14   Need help with scripting my hero
Reply With Quote #1

Ok so im newbie here and i would be happy if someone help.
so first i read this tut - > https://forums.alliedmods.net/showthread.php?t=120051
i just want to make new hero but im sure where i did wrong (i can't compile it too)..this is my broken code:
Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include<superheromod>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"


public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Add your code here...
}
#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", "Strygwyr")
    
    //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", "34") //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, "V", "V For Vendetta")
    
    //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 armor:
    new pcvarArmor = register_cvar("super_armor", "4500")
    
    //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(gheroID, 0, pcvarArmor)    
}  
{
    //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", "4500")
    
    //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(gHeroID, pcvarSpeed)
    //this works just like the gravity native so I wont explain this just write it
    //sh_set_hero_speed(gHeroID, pcvarSpeed, {CSW_M4A1}, 1)
}  
{
    //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)
}  
new const gSuperPlayer[] = "models/player/super/super.mdl"

public sh_hero_init(id, heroID, mode)
{
    //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)
}  
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1251\\ deff0\\ deflang1026{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/
martop5hng is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 03-08-2014 , 16:56   Re: Need help with scripting my hero
Reply With Quote #2

Read the whole thing. At the very top I write it as clear as humanly possible: "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."
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
martop5hng
Junior Member
Join Date: Mar 2014
Old 03-11-2014 , 15:13   Re: Need help with scripting my hero
Reply With Quote #3

Quote:
Originally Posted by Jelle View Post
Read the whole thing. At the very top I write it as clear as humanly possible: "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."
oh yeah that's one of my mistake. Ok so i fix it (kinda) but when i try to compile : http://prikachi.com/images/334/7150334f.png
here's my new code if you help again i will love you man
Code:
#include <superheromod>

new gHeroID
new gHeroName[] = "test"  
new bool:gHasSuperPower[SH_MAXSLOTS+1] 
public plugin_init()
{
    
    register_plugin("SUPERHERO test", "1.0", "Jelle")
    
    
    new pcvarLevel = register_cvar("test_level", "25") //this is what level the hero should be avalible at
    
    
    gHeroID = sh_create_hero(gHeroName, pcvarLevel)
    
    sh_set_hero_info(gHeroID, "test123", "test321")
    {
    
    
    new pcvarHealth = register_cvar("test_health", "150")
    new pcvarArmor = register_cvar("test_armor", "4500")
    new pcvarSpeed = register_cvar("test_speed", "1750")
    
    
    sh_set_hero_hpap(gheroID, pcvarHealth, 0)
    sh_set_hero_speed(gHeroID, pcvarSpeed)
}
    
}

public sh_test_init(id, heroID, mode)
{
       
    if (gHeroID != HeroID) return
    
    
    switch(mode)
    {
        
        case SH_HERO_ADD:
        {
            
            gHasSuperPower[id] = true
        }
      
        case SH_HERO_DROP:
        {
           
            gHasSuperPower[id] = false
        }
    }
}  
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1251\\ deff0\\ deflang1026{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1251\\ deff0\\ deflang1026{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/
martop5hng is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 03-12-2014 , 08:50   Re: Need help with scripting my hero
Reply With Quote #4

PHP Code:
public plugin_init()
{
    
    
register_plugin("SUPERHERO test""1.0""Jelle")
    
    
    new 
pcvarLevel register_cvar("test_level""25"//this is what level the hero should be avalible at
    
    
    
gHeroID sh_create_hero(gHeroNamepcvarLevel)
    
    
sh_set_hero_info(gHeroID"test123""test321")
{
    
    
    new 
pcvarHealth register_cvar("test_health""150")
    new 
pcvarArmor register_cvar("test_armor""4500")
    new 
pcvarSpeed register_cvar("test_speed""1750")
    
    
    
sh_set_hero_hpap(gheroIDpcvarHealth0)
    
sh_set_hero_speed(gHeroIDpcvarSpeed)
}


You have an opening and a closing bracket which has no use and get's the compiler confused. And you forgot to set the armor:

PHP Code:
public plugin_init()
{
    
register_plugin("SUPERHERO test""1.0""Jelle")
    
    new 
pcvarLevel register_cvar("test_level""25"//this is what level the hero should be avalible at
    
    
gHeroID sh_create_hero(gHeroNamepcvarLevel)
    
    
sh_set_hero_info(gHeroID"test123""test321")
    
    new 
pcvarHealth register_cvar("test_health""150")
    new 
pcvarArmor register_cvar("test_armor""4500")
    new 
pcvarSpeed register_cvar("test_speed""1750")
    
    
sh_set_hero_hpap(gheroIDpcvarHealthpcvarArmor)
    
sh_set_hero_speed(gHeroIDpcvarSpeed)

You only had indentation problems in the init:

PHP Code:
public sh_test_init(idheroIDmode)
{
    if (
gHeroID != HeroID) return
    
    switch(
mode)
    {
        
        case 
SH_HERO_ADD:
        {
            
gHasSuperPower[id] = true
        
}
        
        case 
SH_HERO_DROP:
        {
            
gHasSuperPower[id] = false
        
}
    }

But since you are not really using your init, you can actually delete it. You hero could look like this:

PHP Code:
#include <superheromod>

new gHeroID
new gHeroName[] = "test"  

public plugin_init()
{
    
register_plugin("SUPERHERO test""1.0""Jelle")
    
    new 
pcvarLevel register_cvar("test_level""25"//this is what level the hero should be avalible at
    
    
gHeroID sh_create_hero(gHeroNamepcvarLevel)
    
    
sh_set_hero_info(gHeroID"test123""test321")
    
    new 
pcvarHealth register_cvar("test_health""150")
    new 
pcvarArmor register_cvar("test_armor""4500")
    new 
pcvarSpeed register_cvar("test_speed""1750")
    
    
sh_set_hero_hpap(gheroIDpcvarHealthpcvarArmor)
    
sh_set_hero_speed(gHeroIDpcvarSpeed)

Then since you only have one forward, you do not need the global variables, so you can move them inside plugin_init, and you can delete the variable to hold the name, as you only use it once:

PHP Code:
#include <superheromod> 

public plugin_init()
{
    new 
HeroID
    
    register_plugin
("SUPERHERO test""1.0""Jelle")
    
    new 
pcvarLevel register_cvar("test_level""25"//this is what level the hero should be avalible at
    
    
HeroID sh_create_hero("Test"pcvarLevel)
    
    
sh_set_hero_info(HeroID"test123""test321")
    
    new 
pcvarHealth register_cvar("test_health""150")
    new 
pcvarArmor register_cvar("test_armor""4500")
    new 
pcvarSpeed register_cvar("test_speed""1750")
    
    
sh_set_hero_hpap(heroIDpcvarHealthpcvarArmor)
    
sh_set_hero_speed(HeroIDpcvarSpeed)

__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
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 12:23.


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