Raised This Month: $ Target: $400
 0% 

Optimize/fix my code


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
[X]-RayCat
Senior Member
Join Date: Sep 2006
Old 08-14-2008 , 18:36   Optimize/fix my code
Reply With Quote #1

Code:
#include <amxmodx> #include <fakemeta>   #define PLUGIN "HNS Buymenu" #define AUTHOR "X-RayCat" #define VERSION "1.0"   #define OFFSET_MONEY 115 #define cs_get_user_money(%1) get_pdata_int(%1, OFFSET_MONEY)   new pcvars[5]; new Messages[5][] ={      "You bought silent footsteps! (Noone can hear your footsteps)",      "You bought health! (150 health)",      "You bought sunglasses (No flash blinding)!",      "You bought steahlt! (50% invisible)",      "You bought armor (150 armor)!" }   new Names[6][] ={      "",      "Silent Footsteps",      "150 health",      "Sunglasses (No flash)",      "Steahlt-Suit",      "150 Armor" }   new bool:has_noflash[33], has_health[33], has_footsteps[33], has_steahlt[33], has_armor[33]; new g_nMsgScreenFade;   public plugin_init() {      register_plugin(PLUGIN, VERSION, AUTHOR)        pcvars[0] = register_cvar("hns_footsteps_price", "2000");      pcvars[1] = register_cvar("hns_health_price", "12000");      pcvars[2] = register_cvar("hns_noflash_price", "8000");      pcvars[3] = register_cvar("hns_stealth_price", "4000");      pcvars[4] = register_cvar("hns_armor_price", "6000");        register_clcmd("say /hnsshop","HnsBuyMenu");      register_clcmd("say_team /hnsshop","HnsBuyMenu");        register_event ("ScreenFade","FlashedEvent","be","4=255","5=255","6=255","7>199");      register_event("ResetHUD", "Event_ResetHud", "be");      register_event("DeathMsg", "hook_death", "a", "1>0");      g_nMsgScreenFade = get_user_msgid("ScreenFade"); }   public hook_death(id) {      new victim = read_data(2);        has_armor[victim] = false;      has_footsteps[victim] = false;      has_health[victim] = false;      has_noflash[victim] = false;      has_steahlt[victim] = false;        set_pev(id, pev_flTimeStepSound, 400); } public client_disconnect(id) {      has_armor[id] = false;      has_footsteps[id] = false;      has_health[id] = false;      has_noflash[id] = false;      has_steahlt[id] = false; }   public ResetHUD(id) {      set_task(0.1, "give_ability", id); }   public HnsBuyMenu(id) {      new menu = menu_create("\rHide 'N Seek Shop:", "menu_handler");        new i = 1, nr[3]      new Form[50]      for ( i = 1; i < 9; i++)      {          format(nr, 2,"%i", i)          format(Form, 49, "%s: ($%i)", Names[i], get_pcvar_num(pcvars[i]))          menu_additem(menu, Form, nr, 0);      }        menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);      menu_display(id, menu, 0);      return 0; }   public menu_handler(id, menu, item) {      if (item == MENU_EXIT)      {           client_print(id, print_chat, "[HNS-Shop] You have exited from the shopmenu!")           menu_destroy(menu);           return 1;      }        new szCommand[6] , szName[64];      new access , callback;        menu_item_getinfo(menu, item, access, szCommand, 5, szName, 63, callback);        new i = str_to_num(szCommand);      new money = cs_get_user_money(id);      new cost = get_pcvar_num(pcvars[i]);        if(money < cost)      {          client_print(id, print_chat, "[HNS-Shop] You don't have enough money ($%i Needed).", cost);          return 1;      }        cs_set_user_money(id, money-cost, 1);      client_print(id, print_chat, "[HNS-Shop] %s", Messages[i]);        switch(i)      {          case 1:{               //Default: 400 / Silent: 999               set_pev(id, pev_flTimeStepSound, 999);               has_footsteps[id] = true;                   menu_display(id, menu, 0);               return 1;          }            case 2:{              set_pev(id, pev_health, 150.0);              has_health[id] = true;                  menu_display(id, menu, 0);          }          case 3:{             has_noflash[id] = true;             menu_display(id, menu, 0);                 return 1;          }          case 4:{            fm_set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, floatround(255.0 * 0.50)); //50%            has_steahlt[id] = true;                menu_display(id, menu, 0);            return 1;         }         case 5:{           set_pev(id, pev_armorvalue, 150.0);           menu_display(id, menu, 0);           return 1;         }      }      menu_destroy(menu)      return 1; }   public give_ability(id) {      if(has_armor[id]) {        set_pev(id, pev_armorvalue, 150.0);      } else if(has_footsteps[id]) {        set_pev(id, pev_flTimeStepSound, 999);      }  else if(has_health[id]) {       set_pev(id, pev_health, 150.0)      } else if(has_steahlt[id]) {          fm_set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0,   kRenderTransAlpha, floatround(255.0 * 0.50));      } }   public FlashedEvent( id ) {      if(!has_noflash[id])          return 0;        message_begin( MSG_ONE, g_nMsgScreenFade, {0,0,0}, id );      write_short( read_data( 1 ) ); // Duration      write_short( read_data( 2 ) ); // Hold time      write_short( read_data( 3 ) );      write_byte ( 0 );   //Red      write_byte ( 0 );   // Green      write_byte ( 0 ); // Blue      write_byte ( 0 ); // Alpha      message_end();        return 1; }   stock cs_set_user_money(index, money, flash = 1)   {      set_pdata_int(index, OFFSET_MONEY, money);        message_begin(MSG_ONE, get_user_msgid("Money"), _, index);      write_long(money);      write_byte(flash ? 1 : 0);      message_end(); } stock fm_set_user_rendering(entity, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16) {      new Float:RenderColor[3];      RenderColor[0] = float(r);      RenderColor[1] = float(g);      RenderColor[2] = float(b);        set_pev(entity, pev_renderfx, fx);      set_pev(entity, pev_rendercolor, RenderColor);      set_pev(entity, pev_rendermode, render);      set_pev(entity, pev_renderamt, float(amount));        return 1; }

The menu doesnt open it say something like "Index out of bounds".
[X]-RayCat is offline
 



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:11.


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