Well, here's a supplement to this guide, an example:
Let's look at the hero, anubis:
plugin version, plugin_init:
Code:
#include <amxmod>
#include <Vexd_Utilities>
#include <superheromod>
// GLOBAL VARIABLES
new gHeroName[]="Anubis"
new bool:gHasAnubisPowers[SH_MAXSLOTS+1]
new gmsgSayText
public plugin_init()
{
// Plugin Info
register_plugin("SUPERHERO Anubis","1.18","AssKicR/JTP10181")
// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
register_cvar("anubis_level", "0" )
register_cvar("anibus_showdamage", "1")
register_cvar("anibus_showchat", "1")
// FIRE THE EVENT TO CREATE THIS SUPERHERO!
shCreateHero(gHeroName, "Dark Notices", "Nothing Is Secret From You. Hear Enemies - See Damage", false, "anubis_level" )
// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
register_event("ResetHUD","anubis_newround","b")
register_srvcmd("anubis_init", "anubis_init")
shRegHeroInit(gHeroName, "anubis_init")
// Damage Event
register_event("Damage", "damage_msg", "b", "2!0", "3=0", "4!0")
// Say
register_clcmd("say", "handle_say")
register_clcmd("say_team", "handle_say")
gmsgSayText = get_user_msgid("SayText")
}
And here's the module version of anubis, plugin_init:
Code:
#include <amxmodx>
#include <engine>
//#include <cstrike>
#include <shero>
// GLOBAL VARIABLES
new g_heroName[]="Anubis"
new g_heroID
new bool:g_hasAnubis[SH_MAXSLOTS+1]
new g_msgSayText
//----------------------------------------------------------------------------------------------
public plugin_init()
{
// Plugin Info
register_plugin("SUPERHERO Anubis", "1.18", "AssKicR/JTP10181")
// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
register_cvar("anubis_level", "0")
register_cvar("anibus_showdamage", "1")
register_cvar("anibus_showchat", "1")
// FIRE THE EVENT TO CREATE THIS SUPERHERO!
g_heroID = sh_create_hero(g_heroName)
sh_hero_info(g_heroID, "Dark Notices", "Nothing Is Secret From You. Hear Enemies - See Damage")
sh_hero_bind(g_heroID, false)
sh_hero_level(g_heroID, get_cvar_num("anubis_level"))
// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
// Damage Event
register_event("Damage", "damage_msg", "b", "2!0", "3=0", "4!0")
// Say
register_clcmd("say", "handle_say")
register_clcmd("say_team", "handle_say")
g_msgSayText = get_user_msgid("SayText")
}
Now, lets take a closer look:
When you want to create a hero:
In the plugin version, you would use:
Code:
shCreateHero(gHeroName, "Dark Notices", "Nothing Is Secret From You. Hear Enemies - See Damage", false, "anubis_level" )
In the module version you would replace that with:
Code:
g_heroID = sh_create_hero(g_heroName)
sh_hero_info(g_heroID, "Dark Notices", "Nothing Is Secret From You. Hear Enemies - See Damage")
sh_hero_bind(g_heroID, false)
sh_hero_level(g_heroID, get_cvar_num("anubis_level"))
Now for registering superhero server commands, you normally will have to do this, in the plugin:
Code:
register_srvcmd("anubis_init", "anubis_init")
shRegHeroInit(gHeroName, "anubis_init")
However in the module version, you no longer have to do that, as it is taken of, in a forward function called sh_hero_init(id, heroID, mode). Id is basically the player, heroID tells you what hero is being added or dropped, and mode tells you if you dropped the hero or added it.
There is also one more feature, at least with the hero anubis; you no longer have to register the respawn event, using(register_event("ResetHUD", "newSpawnFunction", "b")). This is because it is being taken care of in this function sh_new_spawn(id) (id is the player being respawned). The format of the respawn function is pretty much the same, only thing different is the name. Instead of anbus_respawn, it is now called sh_new_spawn.
Module's version of a respawn function: (sh_server_info(SH_MODACTIVE) is the same as shModActive())
Code:
public sh_new_spawn(id)
{
if ( sh_server_info(SH_MODACTIVE) && g_hasAnubis[id] ) anubis_speak_on(id)
}
Plugin's version of a respawn function:
Code:
public plugin_init(){
//Somewhere in plugin_init()
register_event("ResetHUD","anubis_newround","b")
}
public anubis_newround(id)
{
if (gHasAnubisPowers[id]) anubis_speak_on(id)
}
And of course, the rest of the plugin_init remains unchanged, for anubis at least.
Now lets take a look at the hero_init function for the plugin and module version.
Here's the plugin version:
Code:
public anubis_init()
{
new temp[6]
// 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 anubis
read_argv(2,temp,5)
new hasPowers=str_to_num(temp)
// Got to disable anubis that lost his powers...
gHasAnubisPowers[id] = (hasPowers!=0)
if (gHasAnubisPowers[id]) anubis_speak_on(id)
else anubis_speak_off(id)
}
Pretty messy isn't it? You had to write 5 lines to get the player id and information about whether the player is adding or dropping the hero (the lines dealing with read_argv and temp).
In the module version you need not to worry about that anymore; the information about the player and whether the hero is being dropped or added is all given in the function, as parameters (id is the player, heroID is the hero being dropped or added, and mode tells if that hero is being dropped or added (mode 0 means it's dropped and mode 1 means it's being added)).
Code:
public sh_hero_init(id, heroID, mode)
{
// See if this hero is the same that's being init
if ( g_heroID == heroID ) {
g_hasAnubis[id] = (mode != 0)
if ( mode == 1 ) {
anubis_speak_on(id)
}
else {
anubis_speak_off(id)
}
}
}
That's it for the example concerning anubis.
I'll post an example concerning a hero using a bind key later on, hope this supplement helps.
__________________