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

Converting heroes to new Module API


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 09-18-2005 , 14:36   Converting heroes to new Module API
Reply With Quote #1

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
    Code:
    ex: new bool: g_HasPower[SH_MAXSLOTS+1];
  • You need a variable to store current hero id #
    Code:
    ex: new g_heroID;

Converting plugin_init() to the new API:
  • You register plugin just as usualy
    Code:
    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:
      Code:
      sh_create_hero(g_heroName); ex: g_heroID = sh_create_hero(g_heroName);
    • Set heroes Power and Help info.
      Code:
      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.
      Code:
      sh_hero_bind(g_heroID, bool:button = false); ex: sh_hero_bind(g_heroID, false);
    • Set what level the hero is available at.
      Code:
      sh_hero_level(g_heroID, level); ex: sh_hero_level(g_heroID, get_cvar_num("superman_level"));

  • Other syntax:
    • Setting heroes Max AP/HP
      Code:
      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.

      Code:
      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.
      Code:
      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
    Code:
    sh_hero_init(id, heroID, mode)
    Code:
    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
    Code:
    sh_hero_key(id, heroID, key)
    Code:
    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.
Freecode is offline
kanu | DarkPredator
Senior Member
Join Date: Apr 2005
Old 09-18-2005 , 16:20  
Reply With Quote #2

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?
__________________
Dark | Predator
kanu | DarkPredator is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 09-18-2005 , 16:25  
Reply With Quote #3

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
Freecode is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 11-07-2005 , 17:32   Re: Converting heroes to new Module API
Reply With Quote #4

Quote:
Originally Posted by Freecode
I will post the rest later on today.
still waiting

or is that all of it?
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 11-07-2005 , 19:51  
Reply With Quote #5

i think thats it
Freecode is offline
[DoD]GoldenEagle
Member
Join Date: Nov 2005
Location: In Front Of Computer Sys
Old 11-24-2005 , 17:12   WHAt
Reply With Quote #6

but you said you were gonna post the rest
[DoD]GoldenEagle is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 11-24-2005 , 18:00  
Reply With Quote #7

OMG
GET OUT
Freecode is offline
[DoD]GoldenEagle
Member
Join Date: Nov 2005
Location: In Front Of Computer Sys
Old 12-04-2005 , 02:19   ?what?
Reply With Quote #8

What do you mean get out lol? and ok dont get pissed like every other time you have replied to me!
[DoD]GoldenEagle is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 12-04-2005 , 03:12  
Reply With Quote #9

if i said that thats it then thats what it means. dont ask stupid questions 2 1/2 weeks later after my reply.
Freecode is offline
Batman/Gorlag
Senior Member
Join Date: Aug 2005
Old 02-07-2006 , 05:22  
Reply With Quote #10

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.
__________________
GRR If only the amxmod programming were in Java.....
Java and C used to be two different languages, now Java is turning into another C. My logevent plugin
Batman/Gorlag 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 03:36.


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