Raised This Month: $ Target: $400
 0% 

get_cvar_num problems


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shino
Senior Member
Join Date: May 2006
Old 06-07-2006 , 15:36   get_cvar_num problems
Reply With Quote #1

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.
shino is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 06-07-2006 , 16:12  
Reply With Quote #2

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; }
;)
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
shino
Senior Member
Join Date: May 2006
Old 06-07-2006 , 16:14  
Reply With Quote #3

this was just a part of the plugin...

still, god bless you!
+karma 4 u
shino is offline
shino
Senior Member
Join Date: May 2006
Old 06-07-2006 , 16:34  
Reply With Quote #4

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!
shino is offline
JohnJ3
Member
Join Date: May 2006
Location: Tomsk
Old 06-08-2006 , 00:46  
Reply With Quote #5

for what this part of code
Code:
    if( get_cvar_num( "amx_instagib" ) != 1 ) {         return PLUGIN_HANDLED     }
if you not register amx_instagib even?!
JohnJ3 is offline
shino
Senior Member
Join Date: May 2006
Old 06-08-2006 , 03:28  
Reply With Quote #6

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?
shino is offline
JohnJ3
Member
Join Date: May 2006
Location: Tomsk
Old 06-08-2006 , 03:50  
Reply With Quote #7

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 }
JohnJ3 is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 06-08-2006 , 04:39  
Reply With Quote #8

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 }
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
JohnJ3
Member
Join Date: May 2006
Location: Tomsk
Old 06-08-2006 , 05:16  
Reply With Quote #9

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?
JohnJ3 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 16:30.


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