AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_cvar_num problems (https://forums.alliedmods.net/showthread.php?t=29545)

shino 06-07-2006 15:36

get_cvar_num problems
 
Code:
public plugin_init() {     register_cvar( "amx_instagibweapon", "xm1014" )     register_logevent("round_start",2,"0=World triggered","1=Round_Start") } public round_start(id) {     set_task(0.1,"GiveWeapon") } public GiveWeapon(id) {     if( get_cvar_num( "amx_instagib" ) != 1 ) {         return PLUGIN_HANDLED     }     new players[32],num,i,id,cvar,ak47,xm1014     get_players(players,num)     for(i = 0; i <= num; i++) {         id = players[i]         if(is_user_connected(id) && is_user_alive(id)) {             cvar = get_cvar_string("amx_instagibweapon",players,31)             cs_set_user_money(id,1)             strip_user_weapons(id)             give_item(id,"weapon_knife")             if(cvar == ak47) {                 give_item(id,"weapon_ak47")                 give_item(id,"weapon_ak47")                 give_item(id,"weapon_ak47")                 give_item(id,"weapon_ak47")             }             if(cvar == xm1014) {                 give_item(id,"weapon_xm1014")                 give_item(id,"weapon_xm1014")                 give_item(id,"weapon_xm1014")                 give_item(id,"weapon_xm1014")             }         }     }     return PLUGIN_CONTINUE }
so, i would like the plugin to give me only xm1014, but i get ak47 also. even more, if i type amx_instagibweapon into console, it returns me that amx_instagibweapon is ak47, not xm1014.

i think the problem is in the cvar, so i would be very happy, if someone could help me on this one. :)

v3x 06-07-2006 16:12

Don't use a logevent. Use a regular event like so:
Code:
register_event("ResetHUD" , "new_round" , "b");
You got the delay part correct.

The cvar "amx_instagib" doesn't exist in this plugin so you must register it.

This would be how you would compare the cvar's value:
Code:
new weap[21]; get_cvar_string("amx_instagibweapon" , weap , 20); if(equali(weap , "ak47")) {   give_item(id , "weapon_ak47");   cs_set_user_bpammo(id , CSW_AK47 , 90);   return PLUGIN_HANDLED; }
;)

shino 06-07-2006 16:14

this was just a part of the plugin...

still, god bless you!
+karma 4 u

shino 06-07-2006 16:34

still, if i type amx_instagibweapon, i get ak47. it depends on the first weapon i would like to give: if it is
Code:
if(equali(weap , "ak47")) {   give_item(id , "weapon_ak47");   cs_set_user_bpammo(id , CSW_AK47 , 90);   return PLUGIN_HANDLED; }
, amx_instagibweapon is ak47, if it is:
Code:
if(equali(weap , "usp")) {   give_item(id , "weapon_usp");   cs_set_user_bpammo(id , CSW_USP , 90);   return PLUGIN_HANDLED; }
, amx_instagibweapon is usp.

also, i made the code look like this now:
Code:
public GiveWeapon(id) {     if( get_cvar_num( "amx_instagib" ) != 1 ) {         return PLUGIN_HANDLED     }     new players[32],num,i,id,cvar,ak47,usp     get_players(players,num)     for(i = 0; i <= num; i++) {         id = players[i]         if(is_user_alive(id)) {             new weap[21]             get_cvar_string("amx_instagibweapon" , weap , 20)             if(equali(weap , "usp"))                 {                 give_item(id , "weapon_usp")                 cs_set_user_bpammo(id , CSW_USP, 90)                 return PLUGIN_HANDLED             }                       if(equali(weap , "ak47"))                 {                 give_item(id , "weapon_ak47")                 cs_set_user_bpammo(id , CSW_AK47 , 90)                 return PLUGIN_HANDLED             }                   }     }     return PLUGIN_CONTINUE }
server crashes.
EDIT: there's no problem, my mistake!

JohnJ3 06-08-2006 00:46

for what this part of code
Code:
    if( get_cvar_num( "amx_instagib" ) != 1 ) {         return PLUGIN_HANDLED     }
if you not register amx_instagib even?!

shino 06-08-2006 03:28

Quote:

Originally Posted by JohnJ3
for what this part of code
Code:
    if( get_cvar_num( "amx_instagib" ) != 1 ) {         return PLUGIN_HANDLED     }
if you not register amx_instagib even?!

it is just a part of the code. so, can this mistake be forgiven to me? :twisted:

JohnJ3 06-08-2006 03:50

so, i try use this script in my lan-server. When you play - no errors and script is work. But if you use amx_instagibweapon usp and when you type "quit" in console, windows show error near "cannot read a memory".
Code:
#include <amxmodx> #include <cstrike> #include <fun> public plugin_init() {     register_cvar( "amx_instagibweapon", "xm1014" )     register_logevent("round_start",2,"0=World triggered","1=Round_Start") } public round_start(id) {     set_task(0.1,"GiveWeapon",id) } public GiveWeapon(tid) {     new players[32],num,i,id     get_players(players,num)     for(i = 0; i < num; i++)     {      id = players[i]      if(is_user_connected(id) && is_user_alive(id))      {     new weap[21]       get_cvar_string("amx_instagibweapon",weap,20)     console_print(id,"weap=%s",weap)       if(equali(weap , "usp"))       {        give_item(id , "weapon_usp")        cs_set_user_bpammo(id , CSW_USP, 90)        return PLUGIN_HANDLED       }       if(equali(weap , "ak47"))       {        give_item(id , "weapon_ak47")        cs_set_user_bpammo(id , CSW_AK47 , 90)        return PLUGIN_HANDLED       }      }     }     return PLUGIN_CONTINUE }

v3x 06-08-2006 04:39

Code:
#include <amxmodx> #include <cstrike> #include <fun> public plugin_init() {     register_cvar( "amx_instagibweapon", "xm1014" )     register_event("ResetHUD" , "new_round" , "b"); } public new_round(id) {     set_task(0.1,"GiveWeapon",id) } public GiveWeapon(id) {   if(!is_user_alive(id))     return PLUGIN_HANDLED   new weap[21]   get_cvar_string("amx_instagibweapon",weap,20)   console_print(id,"weap=%s",weap)   if(equali(weap , "usp")) {     give_item(id , "weapon_usp")     cs_set_user_bpammo(id , CSW_USP, 90)     return PLUGIN_HANDLED   }   if(equali(weap , "ak47")) {     give_item(id , "weapon_ak47")     cs_set_user_bpammo(id , CSW_AK47 , 90)     return PLUGIN_HANDLED   }   return PLUGIN_CONTINUE }

JohnJ3 06-08-2006 05:16

You want to say that error returned becouse we used a register_logevent function. Right? I have read a documentation "Scripting Tutorial -> Advanced Topics -> Catching Log Messages" and see the example of use register_event.
I'm understand that you help for me, but my question: why I see error?


All times are GMT -4. The time now is 16:31.

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