AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   make cvar wish changes something in your plugin (https://forums.alliedmods.net/showthread.php?t=24905)

wouter 03-04-2006 16:12

make cvar wish changes something in your plugin
 
Code:
/* Plugin generated by AMXX-Studio */         /*   Many help form Kraugh   Thx man   say \ammo                 // client cmd   say_team \ammo           // client cmd   amxx_ammoforhp  <1/0>   // enable / disable by admin   */       #include <amxmodx> #include <fun> #include <cstrike> #define PLUGIN "ammoforhp" #define VERSION "1.0" #define AUTHOR "wouter" public plugin_init()     {       register_plugin(PLUGIN, VERSION, AUTHOR)       register_clcmd("say /ammo", "cmd_ammo")       register_clcmd("say_team /ammo", "cmd_ammo")       register_cvar("amxx_ammoforhp", "1") }     public cmd_ammo(id) {           if ( ! get_cvar_num("amxx_ammoforhp") )           return PLUGIN_HANDLED         new AmmoCost = 10  // Change how much hp you loose for the ammo (hint: do not make it nagative - - becomes + :D)     new life = get_user_health(id)          if ( !is_user_alive(id) || life <= AmmoCost) {           client_print(id, print_chat, "[AmmoForHp] You are not alive or do not have enough HP!")           return PLUGIN_HANDLED       }         new clip, ammo, weapon = get_user_weapon(id,clip,ammo);               switch(weapon) {                 case CSW_P228: {             give_item(id,"ammo_357sig")         }         case CSW_SCOUT: {             give_item(id,"ammo_762nato")         }         case CSW_HEGRENADE: {             client_print(id, print_chat, "[AmmoForHp] There is no ammo for this item!")               return PLUGIN_HANDLED         }         case CSW_XM1014: {             give_item(id,"ammo_buckshot")                     }         case CSW_C4: {             client_print(id, print_chat, "[AmmoForHp] There is no ammo for this item!")               return PLUGIN_HANDLED         }         case CSW_MAC10: {             give_item(id,"ammo_45acp")         }         case CSW_AUG: {             give_item(id,"ammo_556nato")         }         case CSW_SMOKEGRENADE: {             client_print(id, print_chat, "[AmmoForHp] There is no ammo for this item!")               return PLUGIN_HANDLED         }         case CSW_ELITE: {             give_item(id,"ammo_9mm")         }         case CSW_FIVESEVEN: {             give_item(id,"ammo_57mm")         }         case CSW_UMP45: {             give_item(id,"ammo_45acp")         }         case CSW_SG550: {             give_item(id,"ammo_556nato")         }         case CSW_GALI: {             give_item(id,"ammo_308")   // do not give ammo => no errors         }         case CSW_FAMAS: {             give_item(id,"ammo_556nato")         }         case CSW_USP: {             give_item(id,"ammo_45acp")         }         case CSW_GLOCK18: {             give_item(id,"ammo_9mm")         }         case CSW_AWP: {             give_item(id,"ammo_338magnum")         }         case CSW_MP5NAVY: {             give_item(id,"ammo_9mm")         }         case CSW_M249: {             give_item(id,"ammo_556natobox")         }         case CSW_M3: {             give_item(id,"ammo_buckshot")                     }         case CSW_M4A1: {             give_item(id,"ammo_556nato")         }         case CSW_TMP: {             give_item(id,"ammo_9mm")         }         case CSW_G3SG1: {             give_item(id,"ammo_762nato")         }         case CSW_FLASHBANG: {             client_print(id, print_chat, "[AmmoForHp] There is no ammo for this item!")               return PLUGIN_HANDLED         }         case CSW_DEAGLE: {             give_item(id,"ammo_50ae")         }         case CSW_SG552: {             give_item(id,"ammo_556nato")         }         case CSW_AK47: {             give_item(id,"ammo_762nato")         }         case CSW_KNIFE: {             client_print(id, print_chat, "[AmmoForHp] There is no ammo for this item!")               return PLUGIN_HANDLED         }         case CSW_P90: {             give_item(id,"ammo_57mm")         }         default: return PLUGIN_CONTINUE     }         set_user_health(id, life - AmmoCost)     client_print(id, print_chat, "[AmmoForHp] You have exchanged health for ammo!")     return PLUGIN_HANDLED }
this is the plugin but i MUST ( :( ) make a cvar wish changes the
Code:
new AmmoCost = 10
but i dont know how to do that, i guess something with
Code:
register_cvar("amxx_ammoforhp_cost", "16000") read_argv(id, output[], len) get_cvar_num("amxx_ammoforhp_cost") set_cvar_num("amxx_ammoforhp_cost", value)
but put what were and how?
plz help me :up:

Jordan 03-04-2006 16:23

Code:
    register_cvar("mp_ammocost", "10") //(later on in the code)     new AmmoCost = get_cvar_num("mp_ammocost")

Should work.

wouter 03-04-2006 16:24

ok i'll try it right now :D

wouter 03-04-2006 16:35

uhu that works more then fine :D
no i only have one problem my ammo for the galil is wrong...
does someone know where i can get te right ammo name?

v3x 03-04-2006 16:48

Quote:

Originally Posted by wouter
uhu that works more then fine :D
no i only have one problem my ammo for the galil is wrong...
does someone know where i can get te right ammo name?

ammo_556nato

I believe.

Jordan 03-04-2006 16:49

It's the same as the m4 I think.

edit: freaking a v3x got it first.

wouter 03-04-2006 16:53

both right :D
thx guys :up:

Jordan 03-04-2006 16:54

No problem.

Jordan 03-04-2006 17:29

Edit: In 1.70, optimization would be like this:

Code:
#define PLUGIN "ammoforhp" #define VERSION "1.0" #define AUTHOR "wouter" //this is jsut to show where in the code you'd put this: new g_AmmoCost public plugin_init()     {       register_plugin(PLUGIN, VERSION, AUTHOR)       register_clcmd("say /ammo", "cmd_ammo")       register_clcmd("say_team /ammo", "cmd_ammo")       register_cvar("amxx_ammoforhp", "1")     g_AmmoCost = get_pcvar_num("mp_ammocost") }

wouter 03-04-2006 17:40

i'll do that in the morning :)


All times are GMT -4. The time now is 20:15.

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