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 pCvarDmg, pCvarCool
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(gHeroName, pCvarLevel)
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(id, heroid, mode)
{
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:
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!
So, the entire forward should be like:
PHP Code:
public sh_hero_key(id, heroID, key)
{
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(id, aimvec, 3)
new origin[3]
get_user_origin(id, origin, 1)
// Beam effect between two points
message_begin(MSG_BROADCAST, SVC_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 tid, tbody, damage
damage = get_pcvar_num(pCvarDmg)
get_user_aiming(id, tid, tbody)
attack_effects(id)
if ( is_user_alive(tid) && (cs_get_user_team(id) != cs_get_user_team(tid) || sh_friendlyfire_on()) )
{
sh_extra_damage(tid, id, damage, "Keydown Power")
}
sh_set_cooldown(id, get_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 pCvarDmg, pCvarCool
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(gHeroName, pCvarLevel)
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(id, heroid, mode)
{
if ( heroid == gHeroID )
{
gHasHero[id] = mode ? true : false
}
if ( mode == SH_HERO_ADD ) {
gPlayerInCooldown[id] = false
}
}
public sh_hero_key(id, heroID, key)
{
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 tid, tbody, damage
damage = get_pcvar_num(pCvarDmg)
get_user_aiming(id, tid, tbody)
attack_effects(id)
if ( is_user_alive(tid) && (cs_get_user_team(id) != cs_get_user_team(tid) || sh_friendlyfire_on()) )
{
sh_extra_damage(tid, id, damage, "Keydown Power")
}
sh_set_cooldown(id, get_pcvar_float(pCvarCool))
}
public attack_effects(id)
{
new aimvec[3]
get_user_origin(id, aimvec, 3)
new origin[3]
get_user_origin(id, origin, 1)
// Beam effect between two points
message_begin(MSG_BROADCAST, SVC_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
__________________