SH Tutorial 1.2

From AlliedModders Wiki
Revision as of 21:13, 13 October 2009 by Jtpizzalover (talk | contribs) (Superhero Mod tutuorial for the code changes under shmod1.2)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



#include <superheromod> //Must be included in the creating of a superhero

// VARIABLES
new const gHeroName[]="Tutorial" //Name Of The Hero
new bool:gHasTutorialPower[SH_MAXSLOTS+1] //A Variable telling us if player has this hero
//----------------------------------------------------------------------------------------------
public plugin_init()
{
  // Plugin Info
  register_plugin("SUPERHERO Tutorial","1.0","AssKicR") //Register The Plugin (name,version,creator)

  // DEFAULT THE CVARS
  new pcvarGravity = register_cvar("tutorial_gravity", "0.35" ) //Cvar holding the heros Gravity
  new pcvarArmor = register_cvar("tutorial_armor", "150") //Cvar holding the heros AP
  new pcvarHealth = register_cvar("tutorial_health", "150") //Cvar holding the heros HP
  new pcvarSpeed = register_cvar("tutorial_speed", "300") //Cvar holding the heros Speed
  new pcvarCooldown = register_cvar("tutorial_cooldown", "0" ) //Cvar holding the heros Gravity 
  new pcvarMultiplier = register_cvar("tutorial_multiplier", "10" ) //Cvar holding a number that we are gonna use as a multiplier later 
  new pcvarHealpoints = register_cvar("tutorial_healpoints", "1" ) //Cvar we are using to see how much he heals
  new pcvarLevel = register_cvar("tutorial_level", "0" ) ///Resister the cvar that tells us what level he is available
  

  sh_set_hero_info(gHeroID, "Short Desc", "Longer Desc") // This is the command that registers the hero with the mod. In The "Short Desc" You write a short Description.. And a longer one in "Longer Desc"

  // Binds
  sh_set_hero_bind(gHeroID) //This command is added for bind-able heros.


  // DEATH EVENT
  register_event("DeathMsg", "tutorial_death", "a") //When someone is killed this event is called
  // NEW ROUND
  register_event("ResetHUD","newRound","b") //Called on a New Round
  // DAMAGE EVENT
  register_event("Damage", "tutorial_damage", "b", "2!0") //Called When a Player Gets Damaged by another player
  // WEAPON EVENT (called on CHANGING of weapon... ZOOMING of weapon... and when you RUN OUT OF AMMO on a weapon)
  register_event("CurWeapon","changeWeapon","be","1=1")  
  // LOOP
  register_srvcmd("tutorial_loop", "tutorial_loop")
  //shRegLoop1P0(gHeroName, "tutorial_loop", "ac") // Alive tutorialerineHeros="ac"
  set_task(1.0,"tutorial_loop",0,"",0,"b" )


  // Let Server know about Tutorials Variable
  // It is possible that another hero has more hps, less gravity, or more armor
  // so rather than just setting these - let the superhero module decide each round
  sh_set_hero_hpap(heroID, pcvarHealth, pcvarArmor)
  sh_set_hero_grav(heroID, pcvarGravity)
  sh_set_hero_speed(heroID, pcvarSpeed)

//----------------------------------------------------------------------------------------------
public tutorial_init()
{
  new temp[6] //Variable to store temp info in
  // First Argument is an id
  read_argv(1,temp,5) //This Checks for the ID of the person selecting/dropping this hero and saves as string
  new id=str_to_num(temp) //This makes the string Into a num
  
  // 2nd Argument is 0 or 1 depending on whether the id has flash
  read_argv(2,temp,5) //This Checks if ID has this hero
  new hasPowers=str_to_num(temp) //This makes the string into a num
  gHasTutorialPower[id]=(hasPowers!=0) //Store if this person has the hero
  
  if ( hasPowers ) //Check if person selected this hero
  {
    //Do stuff to him if he just seleced it
  }
  // Got to slow down a Flash that lost his powers...
  if ( !hasPowers  && is_user_connected(id) ) //Check if person dropped this hero
  {
    //Do stuff to him if he just droppped it
    shRemHealthPower(id) //Loose the HP power of this hero
    shRemGravityPower(id) //Loose the Gravity power of this hero
    shRemArmorPower(id) //Loose the AP power of this hero
    shRemSpeedPower(id) //Loose the Speed power of this hero
  }
}
//----------------------------------------------------------------------------------------------
public plugin_precache()
{
  // precache_sound("misc/name.wav") // Sounds Must be precached before they can be used
  // precache_sound("models/name.mdl") // Models Must be precached before they can be used
}
//----------------------------------------------------------------------------------------------
public client_connect(id)
{
  // This event is called every time someone connects to server
}
//----------------------------------------------------------------------------------------------
public client_putinserver(id)
{
  // This event is called every time someone gets into to server
}
//----------------------------------------------------------------------------------------------
public client_disconnect(id)
{
  // This event is called every time someone disconnects from server
}
//----------------------------------------------------------------------------------------------
// RESPOND TO KEYDOWN
public tutorial_kd() { 
  new temp[6] //Variable to store temp info in
  // First Argument is an id with Tutorial Powers!
  read_argv(1,temp,5) //This Checks for the ID of the person pressing the button
  new id=str_to_num(temp) //This makes the string Into a num
  
  // Let them know they already used their ultimate if they have
  if ( gPlayerUltimateUsed[id] ) //If the player already have used this and try using again while avtive/ in cooldown...
  {
    playSoundDenySelect(id) //...It plays the deny sound...
    return PLUGIN_HANDLED //...And cancels the users action
  } 
  
  new TutorialCooldown=get_cvar_num("tutorial_cooldown") //How long the cooldown is (cvar controlled)
  if ( TutorialCooldown>0 ) //Check if it is higher than 0 (0=disabled)
	ultimateTimer(id, TutorialCooldown * 1.0 ) //Fire the Ultimatetimer
  
  //Fire an action on this button press here

  return PLUGIN_HANDLED 
} 
//----------------------------------------------------------------------------------------------
// RESPOND TO KEYUP
public tutorial_ku() 
{ 
  new temp[6] //Variable to store temp info in
  // First Argument is an id with tutorial Powers!
  read_argv(1,temp,5) //This Checks for the ID of the person pressing the button
  new id=str_to_num(temp) //This makes the string Into a num

  //Fire an action on this button release here

  return PLUGIN_HANDLED 
} 
//----------------------------------------------------------------------------------------------
public tutorial_death()
{
  //The Deathmessage is "Killer Weapon Victim" Killer=data1 Victim=data2 Weapon=data3
  new id=read_data(2) //Get the ID of the person who died
  
  if (gHasTutorialPower[id]) { //Checks if the person killed has the powers of this hero
	//Do something to him when he dies
  }
  if (!gHasTutorialPower[id]) { //Checks if the person killed doesn't have the powers of this hero
	//Do something to him when he dies
  }
  return PLUGIN_HANDLED 
}
//----------------------------------------------------------------------------------------------
public newRound(id)
{
  gPlayerUltimateUsed[id]=false // It is a new round so nevermind the cooldown on the skill and let him use it again
  return PLUGIN_HANDLED
}
//----------------------------------------------------------------------------------------------
public tutorial_damage(id)
{
  //!shModActive() tells us that that shMod Must be active
  //!gHasTutorialPower[id] tells us that the person being attacked must have Tutorial Hero
  if (!shModActive() || !gHasTutorialPower[id] ) return PLUGIN_CONTINUE

  new damage = read_data(2) //This reads the damage done to ID 
  new weapon, bodypart, attacker = get_user_attacker(id,weapon,bodypart)
    
  //is_user_alive(id) checks if the one attacked is still alive
  //id != attacker States that the Person giving damage can't be the same as the one getting it
  //weapon=CSW_KNIFE tell us that only the weapon knife will make this happen (Changeable.. Look in amxconst.inc for other )
  if ( is_user_alive(id) && id != attacker && weapon==CSW_KNIFE) {
    // DO EXTRA DAMAGE (Can be replaced by something else)
    new extraDamage = floatround(damage * get_cvar_float("tutorial_multiplier") - damage) //Find out how much extradamage there is
    if (extraDamage>0) //Check if extradamage is higher that 0
	new defence=random_num(0,5) //This will assign a random number between 0 and 5 to the variable defence
    switch (defence) { //Choose one of these defences depending on what the number is
		case 0:shExtraDamage( id, attacker, extraDamage, "Right Hook" ) //Do extraDamage to ID from ATTACKER with weapon Right Hook
		case 1:shExtraDamage( id, attacker, extraDamage, "Left Hook" ) //Do extraDamage to ID from ATTACKER with weapon Left Hook
		case 2:shExtraDamage( id, attacker, extraDamage, "Right Jab" ) //Do extraDamage to ID from ATTACKER with weapon Right Jab
		case 3:shExtraDamage( id, attacker, extraDamage, "Left Jab" ) //Do extraDamage to ID from ATTACKER with weapon left Jab
		case 4:shExtraDamage( id, attacker, extraDamage, "Uppercut" ) //Do extraDamage to ID from ATTACKER with weapon Uppercut
		case 5:shExtraDamage( id, attacker, 0, "Miss" ) //Do 0 damage to ID from ATTACKER
	}
  }
  setScreenFlash(attacker, 230, 10, 10, 10, damage )  //This makes the screen of the attacker flash
  sh_screenShake(attacker, 14, 14, 14 ) //Make his Screen Shake a little
  shStun(attacker, 1) //Stun Him in 1 second

  return PLUGIN_CONTINUE
}
//----------------------------------------------------------------------------------------------
public tutorial_loop()
{
  for ( new id=1; id<=SH_MAXSLOTS; id++ ) //Check Everyone on Server
  {
    if (  gHasTutorialPower[id] && is_user_alive(id)  ) //Check if this person is alive and has the powers of the Tutorial hero
    {
      shAddHPs(id, get_cvar_num("tutorial_healpoints"), 50 ) //This Command gives the hero back HP to max 50 in this case
    }
  }
}
//----------------------------------------------------------------------------------------------
public changeWeapon(id)
{
    if ( !gHasTutorialPower[id] || !shModActive() ) return PLUGIN_CONTINUE
    new  clip, ammo
    new wpn_id=get_user_weapon(id, clip, ammo) //Get some info on current weapon
    new wpn[32]
	//JUST MAKING SURE IT'S NOT GRENADES,KNIFE or C4
    if ( wpn_id==CSW_C4 || wpn_id==CSW_HEGRENADE || wpn_id == CSW_SMOKEGRENADE || wpn_id == CSW_FLASHBANG || wpn_id == CSW_KNIFE ) return PLUGIN_CONTINUE
    
    // Never Run Out of Ammo!
    //server_print("STATUS ID=%d CLIP=%d, AMMO=%d WPN=%d", id, clip, ammo, wpn_id)
    if ( clip == 0 )
    {
      //server_print("INVOKING PUNISHER MODE! ID=%d CLIP=%d, AMMO=%d WPN=%d", id, clip, ammo, wpn_id)
      get_weaponname(wpn_id,wpn,31) //Get name of the weapon
      give_item(id,wpn) //Give him that weapon
      engclient_cmd(id, wpn ) //Switch to that weapon
      shResetSpeed(id) //Set heros speed to normal hero again
    }
    return PLUGIN_CONTINUE
}
//----------------------------------------------------------------------------------------------