PDA

View Full Version : Converting heroes to new Module API


Freecode
09-18-2005, 14:36
Converting Heroes to the new Module API.

Notes: This convert guide is only for AMXX heroes.


Required Global Variables:

You need a bool to store whether or not user has this hero
ex: new bool: g_HasPower[SH_MAXSLOTS+1];

You need a variable to store current hero id #
ex: new g_heroID;


Converting plugin_init() to the new API:

You register plugin just as usualy
ex: register_plugin("SUPERHERO Superman","1.18","{HOJ} Batman");

New syntax for registering a hero:

Register hero in the module. Will return hero ID number:
sh_create_hero(g_heroName);
ex: g_heroID = sh_create_hero(g_heroName);

Set heroes Power and Help info.
sh_hero_info(g_heroID, power[], help[]);
ex: sh_hero_info(g_heroID, "Health/Armor/Gravity", "More Health/Free Armor/Reduced Gravity");

Set whether hero will use a bind.
sh_hero_bind(g_heroID, bool:button = false);
ex: sh_hero_bind(g_heroID, false);

Set what level the hero is available at.
sh_hero_level(g_heroID, level);
ex: sh_hero_level(g_heroID, get_cvar_num("superman_level"));



Other syntax:

Setting heroes Max AP/HP
sh_set_hero_vars(g_heroID, maxHP, maxAP);
ex: sh_set_hero_vars(g_heroID, get_cvar_num("superman_health"), get_cvar_num("superman_armor"))

Now i introduced a new gravity feature which resembles old speed feature where you can set certain speed for certain weapons.
So to set a certain gravity for certain gun you need this :)
So let me break this down so you understand:

Float:gravity = 1.0 - Just a float specifying the gravity obviously
weaponsNum - a number specifying how many weapons gravity you will be changing. (min - 1)
weapons[] - an array which stores the weapon numbers. Use 0 for all weapons.

sh_set_hero_grav(g_heroID, Float:gravity = 1.0, weaponsNum, weapons[]);
ex: sh_set_hero_grav(g_heroID, get_cvar_float("superman_gravity"), 1, {0}); // Will set gravity for all weapons

Setting speed for certain weapons.
sh_set_hero_speed(g_heroID, Float:speed = -1.0, numWeapons, weapons[]);
ex: set_hero_speed(g_heroID, 500.0, 3, {6,26,29}); // Will set 500.0 speed for weapons 6, 26, 29



Converting hero_init() to the new API:

The new API got rid of old hero_init() and now uses sh_hero_init forward which gets called everytime a hero is added or dropped.
Mode:
HERO_ADD
HERO_DROP
sh_hero_init(id, heroID, mode)

public sh_hero_init(id, heroID, mode)
{
if ( g_heroID == heroID )
{
switch(mode)
{
case HERO_ADD:
g_HasPower[id] = true;
case HERO_DROP:
g_HasPower[id] = false;
}
}
}


Converting bound key heroes to the new API:

The new API got rid of registering functions for keyUP/keyDOWN heroes and now uses a forward: sh_hero_key that gets called everytime a key is pressed.
Key:
SH_KEYDOWN
SH_KEYUP
sh_hero_key(id, heroID, key)

public sh_hero_key(id, heroID, key)
{
if ( g_heroID != heroID ) return PLUGIN_CONTINUE

switch(key)
{
case SH_KEYDOWN:
// Call your keydown function from here
case SH_KEYUP:
// Call your keyup function from here
}

return PLUGIN_HANDLED
}

I will post the rest later on today. :D

kanu | DarkPredator
09-18-2005, 16:20
With this guide I'm sure there will be many heroes made for the module, will there be a separate forum for these types of heroes or will it simply specify in the topic which type of hero it is?

Freecode
09-18-2005, 16:25
well old AMX/AMXX heroes will eventualy end up in another forum like "Old Heroes" or something like that. All the approved heroes will "eventualy" be converted to the module API. New Submissions forum will be cleared out for module API heroe's

Emp`
11-07-2005, 17:32
I will post the rest later on today. :D

still waiting :roll:

or is that all of it? :oops:

Freecode
11-07-2005, 19:51
i think thats it

[DoD]GoldenEagle
11-24-2005, 17:12
but you said you were gonna post the rest

Freecode
11-24-2005, 18:00
OMG :evil:
GET OUT

[DoD]GoldenEagle
12-04-2005, 02:19
What do you mean get out lol? and ok dont get pissed like every other time you have replied to me!

Freecode
12-04-2005, 03:12
if i said that thats it then thats what it means. dont ask stupid questions 2 1/2 weeks later after my reply.

Batman/Gorlag
02-07-2006, 05:22
Well, here's a supplement to this guide, an example:

Let's look at the hero, anubis:

plugin version, plugin_init:


#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:

#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:

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:

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:
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())
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:
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:
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)).
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.