AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Invalid CVAR pointer (https://forums.alliedmods.net/showthread.php?t=104818)

Alucard^ 09-27-2009 21:00

Invalid CVAR pointer
 
PHP Code:

////////////////////////////////
//  Credits...                //
//                            //
//  Arkshine, xPaw, joropito  //
//                            //
////////////////////////////////

#include <amxmodx>
#include <cstrike>
#include <geoip>

#define PLUGIN    "Country & City Menu"
#define AUTHOR    "Alucard"
#define VERSION    "1.1"

//--------------------START EDIT------------------------//

#define DURATION    8.0

#define RED        255
#define GREEN    255
#define BLUE    255

#define POS_X    0.02
#define POS_Y    0.23

#define is_user_admin2(%1)  (get_user_flags(%1) & ADMIN_KICK)

//--------------------END EDIT-------------------------//

new Ip1[48], Ip2[48]

new 
g_msgSayText

new p_ShowModep_OnlyAdminsp_ShowCode

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_cvar("cc_version"VERSION,FCVAR_SERVER|FCVAR_SPONLY)
    
register_cvar("cc_author"AUTHOR,FCVAR_SERVER|FCVAR_SPONLY)
    
    
register_clcmd("say /country""CountryMenu")
    
    
p_ShowMode register_cvar("cc_showmode""1")
    
p_ShowCode register_cvar("cc_showcode""1")
    
p_OnlyAdmins register_cvar("cc_onlyadmins""0")
    
    
g_msgSayText get_user_msgid("SayText")
}

public 
CountryMenu(id)
{
    if(!
get_pcvar_num(p_ShowMode) )
        return 
PLUGIN_HANDLED
    
    
if(get_pcvar_num(p_OnlyAdmins) && !is_user_admin2(id) )
        return 
PLUGIN_HANDLED
    
    
new Menu menu_create("\rCountry Menu:""CountryHandler")
    
    new 
szName[32], szTarget[10], players[32],
    
Code2[3], Code3[4], Item[64], pnumtarget
    
    get_players
(playerspnum)
    
    for(new 
ipnumi++)
    {
        
target players[i]
        
        
get_user_ip(targetIp1471)
        
get_user_name(targetszName31)
        
        
num_to_str(targetszTarget9)
        
        
geoip_code2_ex(Ip1Code2)
        
geoip_code3_ex(Ip1Code3)
        
        switch(
get_pcvar_num(p_ShowCode) )
        {
            case 
0:
            
formatex(Item63"%s"szName)
            case 
1:
            
formatex(Item63"%s \y[%s]"szNameCode2)
            case 
2:
            
formatex(Item63"%s \y[%s]"szNameCode3)
        }
        
        
menu_additem(MenuItemszTarget0)
    }
    
    if(
cs_get_user_buyzone(id) )
        
BuyIcon(id0)
    
    
menu_display(idMenu0)
    return 
PLUGIN_HANDLED
}

public 
CountryHandler(idMenuitem)
{
    if( 
item == MENU_EXIT )
    {
        if(
cs_get_user_buyzone(id) )
            
BuyIcon(id1)    
        
        
menu_destroy(Menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], iName[64]
    new 
accesscallback
    menu_item_getinfo
(Menuitemaccessdata,5iName63callback)
    
    new 
target str_to_num(data)
    
    static 
szCountry[48], szCity[48], szName[32], szTimeZone[48]
    
    
get_user_name(targetszName31)
    
    
get_user_ip(targetIp1471)
    
get_user_ip(idIp2471)
    
    
geoip_timezone(Ip1szTimeZone47)
    
geoip_country(Ip1szCountry47)
    
geoip_city(Ip1szCity47)
    
    if(
equal(szCountry"error") )
    {
        if(!
contain(Ip1"192.168.") || !contain(Ip1"10.") || !contain(Ip1"172.") || equal(Ip1"127.0.0.1") )
        {
            
szCountry "LAN"
            
szCity "LAN"
            
szTimeZone "LAN"
        
}
        else if(
equal(Ip1"loopback") )
        {
            
szCountry "LAN Owner"
            
szCity "LAN Owner"
            
szTimeZone "LAN Owner"
        
}
        else
        {
            
szCountry "Unknown Country"
            
szCity "Unknown City"
            
szTimeZone "Unknown TimeZone"
        
}    
    }
    
    switch(
get_pcvar_num(p_ShowMode) )
    {
        case 
1:
        {
            
chat_color(id"!gName: !y%s !t| !gCountry: !y%s !t| !gCity: !y%s !t| !gTime: !y%s"szNameszCountryszCityszTimeZone)
            
chat_color(id"!gDistance with you: !y%f"geoip_distance(geoip_latitude(Ip1), geoip_longitude(Ip1), geoip_latitude(Ip2), geoip_longitude(Ip2) ) )
        }
        case 
2:
        {
            
set_hudmessage(REDGREENBLUEPOS_XPOS_Y06.0DURATION0.10.2, -1)
            
show_hudmessage(id"Name: %s^nCountry: %s^nCity: %s^nTime: %s"szNameszCountryszCityszTimeZone)
        }
        case 
3:
        {
            static 
MotdChars[1536], iLen
            
            iLen 
formatex(MotdChars[iLen], (charsmax(MotdChars) ) - iLen"<html>" 
            
iLen += formatex(MotdChars[iLen], (charsmax(MotdChars) ) - iLen"<body bgcolor=#000000><font color=#FFFFFF face=Verdana size=4>")
            
iLen += formatex(MotdChars[iLen], (charsmax(MotdChars) ) - iLen"<center><font size=8 color=#3399FF><b><u>Country & City Info</u></b></font></center>")
            
iLen += formatex(MotdChars[iLen], (charsmax(MotdChars) ) - iLen"<br><br><br><center><font color=#CCCC00>Name:</font> %s</center>"szName)
            
iLen += formatex(MotdChars[iLen], (charsmax(MotdChars) ) - iLen"<center><font color=#CCCC00>Country:</font> %s</center>"szCountry)
            
iLen += formatex(MotdChars[iLen], (charsmax(MotdChars) ) - iLen"<center><font color=#CCCC00>City:</font> %s</center>"szCity)
            
iLen += formatex(MotdChars[iLen], (charsmax(MotdChars) ) - iLen"<center><font color=#CCCC00>Time:</font> %s</center>"szTimeZone)
            
            
iLen += formatex(MotdChars[iLen], (charsmax(MotdChars) ) - iLen"</font></body></html>" )
            
            
show_motd(idMotdChars"Country & City Info"
        }
    }
    
    if(
cs_get_user_buyzone(id) )
        
BuyIcon(id1)
    
    
menu_destroy(Menu)
    return 
PLUGIN_HANDLED    
}


stock chat_color(const id, const input[], any:...)
{
    static 
msg[191]
    
vformat(msg190input3)
    
    
replace_all(msg190"!g""^4")
    
replace_all(msg190"!y""^1")
    
replace_all(msg190"!t""^3")
    
    
message_begin(MSG_ONE_UNRELIABLEg_msgSayText_id)
    
write_byte(id)
    
write_string(msg)
    
message_end()
}

BuyIcon(idiNum)
{
    
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("StatusIcon"), _id)
    
write_byte(iNum)
    
write_string("buyzone")
    
write_byte(0)
    
write_byte(160)
    
write_byte(0)
    
message_end()


This is very annoying :/

I edited some things and now the menu don't work... when i type /country... i get this error, with debug.

Quote:

L 09/28/2009 - 02:53:37: Invalid CVAR pointer
L 09/28/2009 - 02:53:37: [AMXX] Displaying debug trace (plugin "country_new.amxx")
L 09/28/2009 - 02:53:37: [AMXX] Run time error 10: native error (native "get_pcvar_num")
L 09/28/2009 - 02:53:37: [AMXX] [0] country_new.sma::CountryMenu (line 55)
The line is this:

PHP Code:

if(!get_pcvar_num(p_ShowMode) ) 

o.o

Also, if i comment that part... i get the same error with other get_pcvar_num native...

What is the problem? i can't find what is wrong in this code.

Bugsy 09-27-2009 21:20

Re: Invalid CVAR pointer
 
Do you remember what you changed?

I remember vaguely getting the same error for something totally unrelated to the cvar.

Alucard^ 09-27-2009 21:37

Re: Invalid CVAR pointer
 
Well, this is the first:

http://forums.alliedmods.net/showthread.php?t=104719

First:

http://alucard.pastebin.com/d3ad8b478

Second:

http://alucard.pastebin.com/d1163ba3d

And Difference betwen first and second:

http://alucard.pastebin.com/pastebin.php?diff=d3ad8b478

Emm, added p_ShowCode cvar... (used a switch with this cvar).

Changed Ip and IpID to Ip1 and Ip2 (also Ip2 now is global variable).

Added distance with geoip_distance...

ot_207 09-28-2009 07:42

Re: Invalid CVAR pointer
 
It seems to be a compiler/module error.
Here is what I advise you to do.

1. Check if plugin_init() causes any problems before you register the cvars (log_amx after each register) if so there is where you need to look.
2. Print to server or log_amx the values of the pointers. If one is 0 then that is the problem.
3. Try get_cvar_num if the pointers are 0. That will point out if the cvar has even been registered.
4. What other plugins does the server where you have tested this plugin?

Arkshine 09-28-2009 11:52

Re: Invalid CVAR pointer
 
I've tried on my test server, I don't have this error.

Alucard^ 09-29-2009 00:00

Re: Invalid CVAR pointer
 
Sry, my error. Had a register_concmd when i tested (wich i never used)...

Sry and Thx.


All times are GMT -4. The time now is 22:38.

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