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

Creating a hero like Goten/Vegeta.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
X-Shadow
Member
Join Date: Nov 2009
Old 02-24-2011 , 14:00   Creating a hero like Goten/Vegeta.
Reply With Quote #1

Hey can someone help me creating a keydown hero like Goten/Vegeta? Example: If you press on F it shots a blue beam, I just can't seem to find any tutorials on this, any help is appreciated.
X-Shadow is offline
The Art of War
Veteran Member
Join Date: Dec 2009
Location: Sweden Rock Festival
Old 02-24-2011 , 14:13   Re: Creating a hero like Goten/Vegeta.
Reply With Quote #2

I were thinking of making a tutorial about this. Im not exactly the most qualified but Im sure I can cover the basics pretty well as its very easy to make such a hero.
__________________
The Art of War is offline
Exploited
Veteran Member
Join Date: Jul 2010
Location: Sweden
Old 02-24-2011 , 14:25   Re: Creating a hero like Goten/Vegeta.
Reply With Quote #3

A fair warning, asking Art for help and not understanding the first time he explains something may result in serious injury or death.
__________________
Jelle (1): I LOVE YOU
Jelle (1): Yeah. omg you are so awesome!
--------------
Jelle (1): You know when a poo is about to exit but it is too big?
Jelle (1): God my ass still hurts
Exploited is offline
Exploited
Veteran Member
Join Date: Jul 2010
Location: Sweden
Old 02-24-2011 , 17:13   Re: Creating a hero like Goten/Vegeta.
Reply With Quote #4

I understood the difference between else if and else; the first time you explained it to me, and I realised that just after I asked, thank you.
__________________
Jelle (1): I LOVE YOU
Jelle (1): Yeah. omg you are so awesome!
--------------
Jelle (1): You know when a poo is about to exit but it is too big?
Jelle (1): God my ass still hurts
Exploited is offline
The Art of War
Veteran Member
Join Date: Dec 2009
Location: Sweden Rock Festival
Old 02-24-2011 , 18:49   Re: Creating a hero like Goten/Vegeta.
Reply With Quote #5

So, before I get my ass into something big, I can just try this, but you need some basic knowledge of superheromod (how to register your hero etc).


To create a hero, we need a lot of things, please go check Jelle's tutorial on how to create a simple hero that does nothing before you do this.

The global things we need to register are the following:

PHP Code:
//First we must of course include the superheromod
#include <superheromod>

//Then comes the gHeroID, the gHeroName and the gHasHero bool
new gHeroID
new gHeroName[] = "Keydown Power Test"
new bool:gHasHero[SH_MAXSLOTS+1]

//The sprite 
new Beam

//And finally the pCvars
new pCvarDmgpCvarCool 
Now, to register a keydown we have to use this:
Code:
sh_set_hero_bind(gHeroID)
in the forward called
Code:
public plugin_init()
As you see it uses gHeroID which is created as globally (in the start of the plugin, under the files you want to include, in this case #include <superheromod>, but before any forwards are called) and is defined as
Code:
gHeroID = sh_create_hero(gHeroName, pCvarLevel)
--> This is what we usually use to create the hero itself, comes with setting info for example like
Code:
sh_set_hero_info(gHeroID, "Keydown Power", "Press the +power key to fire a keydown power!")
Note that the forward
Code:
public plugin_init()
has no set parameters inside the paranthesis', hence why we define gHeroID inside it.

So, all this will be:

PHP Code:
public plugin_init()
{
    
//First we want to register the plugin itself, later create the hero(again, check Jelle's tutorial)
    
register_plugin("SUPERHERO Keydown Power""0.1""Test")


    
//Then its always good to set a level required to have the hero...
    
new pCvarLevel register_cvar("keydown_power_level""1")

    
//Then we probably want a cooldown aswell
    
pCvarCool register_cvar("keydown_power_cooldown""20.0")

    
//And of course some damage
    
pCvarDmg register_cvar("keydown_power_dmg""100")

    
gHeroID sh_create_hero(gHeroNamepCvarLevel
    
sh_set_hero_info(gHeroID"Keydown Power""Press the +power key to fire a keydown power!")
    
sh_set_hero_bind(gHeroID)

As we are using a sprite for the effects, we have to precache it:

PHP Code:
public plugin_precache()
{
         
Beam precache_model("sprites/shmod/beam.spr")


Now, the next forward we need for every hero aswell is
Code:
public sh_hero_init(id, heroID, mode)
so it will be like
PHP Code:
public sh_hero_init(idheroidmode

    if ( 
heroid == gHeroID )  
    { 
        
gHasHero[id] = mode true false 
    

    if ( 
mode == SH_HERO_ADD ) { 
        
gPlayerInCooldown[id] = false 
    




Then on to the keydown forward itself:
Code:
public sh_hero_key(id, heroID, key)
In here we want to have a variety of things, and there are many ways of registering a keydown or a keyup. For example we have the generical one that is called on both up and down:
Code:
if (key)
We also have only keydown:
Code:
if (key == SH_KEYDOWN)
or
Code:
switch(key){
case SH_KEYDOWN: {
bla(id)
}
}
etc, etc, etc and etc. There are so many ways, but lets use if (key == SH_KEYDOWN) for this purpose.

So, what we shall do now is to check if the user has the hero etc:

Code:
 if (gHeroID != heroID || !gHasHero[id] || gPlayerInCooldown[id] || !is_user_alive(id)) return
and then the keydown check:
Code:
if (key == SH_KEYDOWN)
Now, we can call the attack forward, lets call it fire_attack!

Code:
fire_attack(id)
So, the entire forward should be like:

PHP Code:
public sh_hero_key(idheroIDkey)
{

if (
gHeroID != heroID || !gHasHero[id] || gPlayerInCooldown[id] || !is_user_alive(id)) return

        if (
key == SH_KEYDOWN)
        {
                 
fire_attack(id)
        }

The next thing we need is to reset the cooldown on spawn:

PHP Code:
public sh_client_spawn(id

        if (
gHasHero[id])
    {    
        
gPlayerInCooldown[id] = false 
        
}

After that comes the attack forward itself!

Code:
public fire_wave(id)
Here we will want to make some effects (?)

Lets make an easy, small beam:

PHP Code:
public attack_effects(id)
{
    new 
aimvec[3]  
    
get_user_origin(idaimvec3
    
    
    new 
origin[3]
    
get_user_origin(idorigin1)
    
    
// Beam effect between two points
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
    
write_byte(TE_BEAMPOINTS)    // 0
    
write_coord(origin[0])
    
write_coord(origin[1])
    
write_coord(origin[2])
    
write_coord(aimvec[0])
    
write_coord(aimvec[1])
    
write_coord(aimvec[2])
    
write_short(Beam)
    
write_byte(1)        // framestart
    
write_byte(5)        // framerate
    
write_byte(2)        // life
    
write_byte(40)        // width
    
write_byte(0)        // noise
    
write_byte(255)        // r, g, b
    
write_byte(255)        // r, g, b
    
write_byte(0)        // r, g, b
    
write_byte(200)        // brightness
    
write_byte(200)        // speed
    
message_end()

Now we want to inflict some damage on the user in the crosshair:

Code:
new tid, tbody, damage

damage = get_pcvar_num(pCvarDmg)

//Get the aiming of the crosshair
get_user_aiming(id, tid, tbody)


//The necessary checks
if ( is_user_alive(tid) && (cs_get_user_team(id) != cs_get_user_team(tid) || sh_friendlyfire_on()) )

//And then the damage
sh_extra_damage(tid, id, damage, "Keydown Power")
Now we set the cooldown:

Code:
sh_set_cooldown(id, get_pcvar_float(pCvarCool))
Soo, the result would be:

PHP Code:
public fire_attack(id)  
{   
    new 
tidtbodydamage  
    
    damage 
get_pcvar_num(pCvarDmg)   
    
    
get_user_aiming(idtidtbody)  
    
    
    
attack_effects(id)
    
    
    if ( 
is_user_alive(tid) && (cs_get_user_team(id) != cs_get_user_team(tid) || sh_friendlyfire_on()) )  
    {  
        
sh_extra_damage(tididdamage"Keydown Power")  
    }  
    
sh_set_cooldown(idget_pcvar_float(pCvarCool))  

If Ive done this correctly, it will create a power that on keydown, shoot a beam in the middle of your crosshair and damage any enemy that is in it. Only a simple beam effect, no area damage or explosion sprite. Im too tired for that right now lol.

So, the entire shit should be:

PHP Code:
//First we must of course include the superheromod 
#include <superheromod> 

//Then comes the gHeroID, the gHeroName and the gHasHero bool 
new gHeroID 
new gHeroName[] = "Keydown Power Test" 
new bool:gHasHero[SH_MAXSLOTS+1

//The sprite  
new Beam 

//And finally the pCvars 
new pCvarDmgpCvarCool 


public plugin_init() 

    
//First we want to register the plugin itself, later create the hero(again, check Jelle's tutorial) 
    
register_plugin("SUPERHERO Keydown Power""0.1""Test"
    
    
    
//Then its always good to set a level required to have the hero... 
    
new pCvarLevel register_cvar("keydown_power_level""1"
    
    
//Then we probably want a cooldown aswell 
    
pCvarCool register_cvar("keydown_power_cooldown""20.0"
    
    
//And of course some damage 
    
pCvarDmg register_cvar("keydown_power_dmg""100"
    
    
gHeroID sh_create_hero(gHeroNamepCvarLevel)  
    
sh_set_hero_info(gHeroID"Keydown Power""Press the +power key to fire a keydown power!"
    
sh_set_hero_bind(gHeroID)  


public 
plugin_precache()  
{  
    
Beam precache_model("sprites/shmod/beam.spr")  
}   

public 
sh_hero_init(idheroidmode)
{
    if ( 
heroid == gHeroID 
    {
        
gHasHero[id] = mode true false
    
}
    if ( 
mode == SH_HERO_ADD ) {
        
gPlayerInCooldown[id] = false
    
}
}
    
public 
sh_hero_key(idheroIDkey)  
{  
    
    if (
gHeroID != heroID || !gHasHero[id] || gPlayerInCooldown[id] || !is_user_alive(id)) return  
    
    if (
key == SH_KEYDOWN)
    {
            
        if ( 
gPlayerInCooldown[id] )
        {
            
sh_sound_deny(id)
            return
        }
        
fire_attack(id)  
    }  
}   

public 
sh_client_spawn(id)   
{   
    if (
gHasHero[id])  
    {      
        
gPlayerInCooldown[id] = false   
    
}  
}   

public 
fire_attack(id)  
{   
    new 
tidtbodydamage  
    
    damage 
get_pcvar_num(pCvarDmg)   
    
    
get_user_aiming(idtidtbody)  
    
    
    
attack_effects(id)
    
    
    if ( 
is_user_alive(tid) && (cs_get_user_team(id) != cs_get_user_team(tid) || sh_friendlyfire_on()) )  
    {  
        
sh_extra_damage(tididdamage"Keydown Power")  
    }  
    
sh_set_cooldown(idget_pcvar_float(pCvarCool))  
}  

public 
attack_effects(id)
{
    new 
aimvec[3]  
    
get_user_origin(idaimvec3
    
    
    new 
origin[3]
    
get_user_origin(idorigin1)
    
    
// Beam effect between two points
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
    
write_byte(TE_BEAMPOINTS)    // 0
    
write_coord(origin[0])
    
write_coord(origin[1])
    
write_coord(origin[2])
    
write_coord(aimvec[0])
    
write_coord(aimvec[1])
    
write_coord(aimvec[2])
    
write_short(Beam)
    
write_byte(1)        // framestart
    
write_byte(5)        // framerate
    
write_byte(2)        // life
    
write_byte(40)        // width
    
write_byte(0)        // noise
    
write_byte(255)        // r, g, b
    
write_byte(255)        // r, g, b
    
write_byte(0)        // r, g, b
    
write_byte(200)        // brightness
    
write_byte(200)        // speed
    
message_end()


Well, now Im really tired! Im sure Ive done some mistakes, please correct me! Ive tested it though, works like a charm for me.

Hope someone finds this intriguing and that someone learn something out of it. It kind of became a mess, I guess I can clean it up a bit tomorrow :p
__________________

Last edited by The Art of War; 02-24-2011 at 19:10.
The Art of War is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 02-24-2011 , 20:27   Re: Creating a hero like Goten/Vegeta.
Reply With Quote #6

Is your edit button broken, Exploited?
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
X-Shadow
Member
Join Date: Nov 2009
Old 02-25-2011 , 02:07   Re: Creating a hero like Goten/Vegeta.
Reply With Quote #7

Omg Art I love you so much! Works so freaking great, why didn't you create tutorial about this?
10+ For Art's help
X-Shadow is offline
Exploited
Veteran Member
Join Date: Jul 2010
Location: Sweden
Old 02-25-2011 , 03:09   Re: Creating a hero like Goten/Vegeta.
Reply With Quote #8

Quote:
Originally Posted by Jelle View Post
Is your edit button broken, Exploited?
My edit button works perfectly fine. Art deleted his post.

Also, thanks for this Fluffy
__________________
Jelle (1): I LOVE YOU
Jelle (1): Yeah. omg you are so awesome!
--------------
Jelle (1): You know when a poo is about to exit but it is too big?
Jelle (1): God my ass still hurts
Exploited is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 02-25-2011 , 07:31   Re: Creating a hero like Goten/Vegeta.
Reply With Quote #9

Quote:
Originally Posted by Exploited View Post
My edit button works perfectly fine. Art deleted his post.

Also, thanks for this Fluffy
Ahh, I believe your edit button is broken but you just wont admit it.
__________________
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 02-25-2011 , 12:02   Re: Creating a hero like Goten/Vegeta.
Reply With Quote #10

So, I were about to write an answer to this but when I posted AM didnt like me and gave me a 500 internal... So here we go again.


Ill add more stuff to it, like range checking, damage over time perhaps, more effects etc, before Ill make a separate thread. Whats best vittu, Off-Topic or Scripting Help?

Any input from more experienced coders? ;)
__________________
The Art of War 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 05:13.


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