Raised This Month: $169 Target: $400
 42% 

how to change this (add item into a menu)


Post New Thread Reply   
 
Thread Tools Display Modes
gfxchris
Member
Join Date: Feb 2016
Old 12-08-2020 , 19:22   Re: how to change this (add item into a menu)
Reply With Quote #31

Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <cstrike>
#include <engine>
#include <cromchat>

#if defined client_disconnected
#define client_disconnect client_disconnected
#endif

native fcs_get_user_credits(index)
native fcs_set_user_credits(index, amount)

stock fcs_sub_user_credits(client, credits)
{
	return fcs_set_user_credits(client, fcs_get_user_credits(client) - credits);
}

new JETPACK_PMODEL[]     = "models/p_longjump.mdl"
new JETPACK_PMODEL_VIP[]     ="models/surfx_models/p_longjump_vip.mdl"
new JETPACK_GOTSOUND[]     = "items/ammopickup2.wav"

new cvar_cost
new cvar_thrust
new cvar_min_speed
new cvar_max_speed
new cvar_thrustvip
new cvar_minspeedvip
new cvar_maxspeedvip

new g_HasJetpack[33]
new g_JetpackEnt[33]

static const PLUGIN_NAME[]     = "SyN Surf Jetpack"
static const PLUGIN_AUTHOR[]     = "Cheap_Suit"
static const PLUGIN_VERSION[]    = "1.4"

public plugin_init()
{
    new mapName[33]
    get_mapname(mapName, 32)
    
    if(!equali(mapName, "surf_", 5))
    {
        new pluginName[33]
        format(pluginName, 32, "[Disabled] %s", PLUGIN_NAME)
        register_plugin(pluginName, PLUGIN_VERSION, PLUGIN_AUTHOR)
        pause("ade")
    }
    else
    {
        register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
        register_cvar(PLUGIN_NAME, PLUGIN_VERSION, FCVAR_SPONLY|FCVAR_SERVER)
        
        register_clcmd("sjp_givesj" ,         "cmd_GiveSJ",         ADMIN_IMMUNITY, "<userid> - Gives free surf jetpack")
        register_clcmd("sjp_stripsj" ,         "cmd_StripSJ",         ADMIN_IMMUNITY, "<userid> - Strips users surf jetpack")
        
        register_clcmd("say /buyjp",     "cmd_BuySurfJetpack", 0, "Buys surf jetpack")
        register_clcmd("say /jp",     "cmd_BuySurfJetpack", 0, "Buys surf jetpack")
        register_concmd("buy_jetpack",         "cmd_BuySurfJetpack", 0, "Buys surf jetpack")
        register_concmd("buyjetpack",         "cmd_BuySurfJetpack", 0, "Buys surf jetpack")
        
        cvar_cost    = get_cvar_num("fcsshop_jetpack_price")
        cvar_thrust     = register_cvar("sjp_thrust", "5")
        cvar_min_speed     = register_cvar("sjp_min_speed", "600")
        cvar_max_speed     = register_cvar("sjp_max_speed", "900")
        cvar_thrustvip     = register_cvar("vip_thrust", "8")
        cvar_minspeedvip     = register_cvar("vip_minspeed", "700")
        cvar_maxspeedvip     = register_cvar("vip_maxspeed", "1100")
        
        register_event("DeathMsg",         "Event_DeathMsg", "a")
    }
}

public plugin_precache()
{
    precache_sound(JETPACK_GOTSOUND)
    precache_model(JETPACK_PMODEL)
    precache_model(JETPACK_PMODEL_VIP)
}

public plugin_natives()
{
	register_native("give_jetpack", "native_give_jetpack")
        register_native("give_vip_jetpack", "native_give_vip_jetpack")
}


public client_connect(id)
{
    g_HasJetpack[id] = 0
    _removeJetpackEnt(id)
}
    
public client_disconnect(id)
{
    g_HasJetpack[id] = 0
    _removeJetpackEnt(id)
}

public Event_DeathMsg()
{
    new id = read_data(2)

    g_HasJetpack[id] = 0
    _removeJetpackEnt(id)

    return PLUGIN_CONTINUE
}

public cmd_BuySurfJetpack(id)
{
    new iMoney = fcs_get_user_credits(id)
    new iCost = get_pcvar_num(cvar_cost) 
    
    if(!is_user_alive(id)) 
        client_print(id, print_center, "You cant buy when your dead!")
    else if(g_HasJetpack[id])
        client_print(id, print_center, "You already own a surf jetpack.")
    else if(iMoney < iCost)
        client_print(id, print_center, "Insufficient funds! (%d Credits)", iCost)
    else
    {
        _give_Jetpack(id)
        fcs_sub_user_credits(id, iCost)
      }
    return PLUGIN_HANDLED
}

public cmd_GiveSJ(id , level , cid) 
{
    if(!cmd_access(id , level , cid , 2))
        return PLUGIN_HANDLED
        
    new arg1[33]
    read_argv(1 , arg1 , 32)

    new target = cmd_target(id , arg1 , 0)
    if(!is_user_connected(target))
    {
        console_print(id, "Player does not exist")
        return PLUGIN_HANDLED
    }

    if(g_HasJetpack[target])
    {
        console_print(id, "Player already has a surf jetpack")
        return PLUGIN_HANDLED
    }
    
    _vip_Jetpack(target)

    new Name[33], Name2[33]
    get_user_name(id, Name, 32)
    get_user_name(target, Name2, 32)
    
    console_print(id, "You gave %s a surf jetpack", Name2)
    CromChat(target,"^4[ADMIN]: ^3%s ^1gave you a surf ^4vip ^1jetpack,test it out!", Name)
    
    return PLUGIN_HANDLED
}

public cmd_StripSJ(id , level , cid) 
{
    if(!cmd_access(id , level , cid , 2))
        return PLUGIN_HANDLED
        
    new arg1[33]
    read_argv(1 , arg1 , 32)

    new target = cmd_target(id , arg1 , 0)
    if(!is_user_connected(target))
    {
        console_print(id, "Player does not exist")
        return PLUGIN_HANDLED
    }

    if(!g_HasJetpack[target])
    {
        console_print(id, "Player does not have a surf jetpack")
        return PLUGIN_HANDLED
    }
    
    g_HasJetpack[id] = 0
    _removeJetpackEnt(id)

    new Name[33], Name2[33]
    get_user_name(id, Name, 32)
    get_user_name(target, Name2, 32)
    
    console_print(id, "You stripped %s of his surf jetpack", Name2)
    CromChat(target,"^4[ADMIN]: ^3%s ^1stripped your surf jetpack.", Name)
    
    return PLUGIN_HANDLED
}

public _give_Jetpack(id)
{
    g_HasJetpack[id] = 1
    CromChat(id,"^4****^3YOU HAVE BOUGHT A ^1JETPACK,^3JUST SURF! ITS AUTOMATIC^4~~~")
    _set_jetpack_model(id)
}

public _vip_Jetpack(id)
{
    g_HasJetpack[id] = 2
    CromChat(id,"^4****^1to use the ^4VIP ^1jetpack just ^3surf ^1it will activate automatically.")
    _set_jetpack_model(id)
}

public _set_jetpack_model(id)
{
    client_cmd(id, "spk %s", JETPACK_GOTSOUND)

    if(g_JetpackEnt[id] < 1)
    {
        g_JetpackEnt[id] = create_entity("info_target")
        if(is_valid_ent(g_JetpackEnt[id]))
        {
            entity_set_model(g_JetpackEnt[id], g_HasJetpack[id] == 2 ? JETPACK_PMODEL_VIP : JETPACK_PMODEL)
            entity_set_int(g_JetpackEnt[id], EV_INT_movetype, MOVETYPE_FOLLOW)
            entity_set_edict(g_JetpackEnt[id], EV_ENT_aiment, id)
        }
    }
} 

public _removeJetpackEnt(id)
{
    if(g_JetpackEnt[id] > 0)
        remove_entity(g_JetpackEnt[id])
    g_JetpackEnt[id] = 0
}

public client_PreThink(id)
{
    if(!is_user_alive(id) || !g_HasJetpack[id])
        return PLUGIN_CONTINUE
        
    if(get_user_speed(id) < get_pcvar_num(g_HasJetpack[id] == 2 ? cvar_minspeedvip : cvar_min_speed)) 
        return PLUGIN_CONTINUE    
        
    new Button = get_user_button(id)
    if(Button & IN_MOVELEFT || Button & IN_MOVERIGHT)
    {           
        _jetThrust(id)
    }
    return PLUGIN_CONTINUE
}

public _jetThrust(id)
{    
    new Float:fVelocity[3]
    entity_get_vector(id, EV_VEC_velocity, fVelocity)

    new Float:fAngle[3]
    entity_get_vector(id, EV_VEC_angles, fAngle)
    engfunc(EngFunc_MakeVectors, fAngle)
                
    new Float:fForward[3]
    get_global_vector(GL_v_forward, fForward)
                
    fVelocity[0] += fForward[0] * get_pcvar_num( g_HasJetpack[id] == 2 ? cvar_thrustvip : cvar_thrust ) 
    fVelocity[1] += fForward[1] * get_pcvar_num( g_HasJetpack[id] == 2 ? cvar_thrustvip : cvar_thrust ) 
            
    if(get_user_speed(id) < get_pcvar_num(g_HasJetpack[id] == 2 ? cvar_maxspeedvip : cvar_max_speed)) 
        entity_set_vector(id, EV_VEC_velocity, fVelocity)
        
    return PLUGIN_CONTINUE
}

stock get_user_speed(id)
{
    new Float:fVelocity[3]
    entity_get_vector(id, EV_VEC_velocity, fVelocity)
    
    new iVelocity[3]
    FVecIVec(fVelocity, iVelocity)
    
    new iVelocity0 = iVelocity[0] * iVelocity[0]
    new iVelocity1 = iVelocity[1] * iVelocity[1]
    
    return sqroot(iVelocity0 + iVelocity1)
}

public native_give_jetpack(iPluginID, iPluginParams, id)
{
_give_Jetpack(get_param(1))
{
    if(!is_user_alive(id)) 
        client_print(id, print_center, "You cant buy when your dead!")
    else if(g_HasJetpack[id])
        client_print(id, print_center, "You already own a surf jetpack.")
    else
    {
        _give_Jetpack(id)
    }
    return PLUGIN_HANDLED
    }
}

public native_give_vip_jetpack(iPluginID, iPluginParams, id)
{
_vip_Jetpack(get_param(1))
{
    if(!is_user_alive(id)) 
        client_print(id, print_center, "You cant buy when your dead!")
    else if(g_HasJetpack[id])
        client_print(id, print_center, "You already own a surf jetpack.")
    else
    {
        _vip_Jetpack(id)
    }
    return PLUGIN_HANDLED
    }
}
this is the code i've been working on,i got it somehow to compile,and tested it but it doesen't work as intended,first of all if i use /buyjp the server crashes (gives me segmentation fault)
second of all,if i use the shop or the vmenu it gives me the print_chat twice (so i think it gives me two same jetpacks) and if i try to buy or select them again it gives me the message (you already own a surf jetpack) but it still gives me the jetpack

any help here?
gfxchris is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-08-2020 , 22:58   Re: how to change this (add item into a menu)
Reply With Quote #32

Technically, you are calling the 'give jetpack' functions once if the checks fail and twice if the checks are successful. See the highlighted lines here:

Code:
public native_give_jetpack(iPluginID, iPluginParams, id) {
_give_Jetpack(get_param(1))
{     if(!is_user_alive(id))         client_print(id, print_center, "You cant buy when your dead!")     else if(g_HasJetpack[id])         client_print(id, print_center, "You already own a surf jetpack.")     else     {
        _give_Jetpack(id)
    }     return PLUGIN_HANDLED     } } public native_give_vip_jetpack(iPluginID, iPluginParams, id) {
_vip_Jetpack(get_param(1))
{     if(!is_user_alive(id))         client_print(id, print_center, "You cant buy when your dead!")     else if(g_HasJetpack[id])         client_print(id, print_center, "You already own a surf jetpack.")     else     {
        _vip_Jetpack(id)
    }     return PLUGIN_HANDLED     } }

You also have a extra unnecessary pair of braces in each of your functions above. I always recommend that you indent your code once for every opening brace and unindent when you place the closing brace (the opening and closing brace should be lined up vertically). Doing this can make errors more obvious.

The other major issue with your code is I'm not sure what value is actually getting assigned to the "id" variable because there is not a third parameter for this type of native. You should define "id" like it's done in the dynamic native example code. It's possible that it might be getting defined with the first parameter but you should never rely on that.
__________________
fysiks is offline
gfxchris
Member
Join Date: Feb 2016
Old 12-09-2020 , 13:28   Re: how to change this (add item into a menu)
Reply With Quote #33

Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <cstrike>
#include <engine>
#include <cromchat>

#if defined client_disconnected
#define client_disconnect client_disconnected
#endif

native fcs_get_user_credits(index)
native fcs_set_user_credits(index, amount)

stock fcs_sub_user_credits(client, credits)
{
	return fcs_set_user_credits(client, fcs_get_user_credits(client) - credits);
}

new JETPACK_PMODEL[]     = "models/p_longjump.mdl"
new JETPACK_PMODEL_VIP[]     ="models/surfx_models/p_longjump_vip.mdl"
new JETPACK_GOTSOUND[]     = "items/ammopickup2.wav"

new cvar_cost
new cvar_thrust
new cvar_min_speed
new cvar_max_speed
new cvar_thrustvip
new cvar_minspeedvip
new cvar_maxspeedvip

new g_HasJetpack[33]
new g_JetpackEnt[33]

static const PLUGIN_NAME[]     = "SyN Surf Jetpack"
static const PLUGIN_AUTHOR[]     = "Cheap_Suit"
static const PLUGIN_VERSION[]    = "1.4"

public plugin_init()
{
    new mapName[33]
    get_mapname(mapName, 32)
    
    if(!equali(mapName, "surf_", 5))
    {
        new pluginName[33]
        format(pluginName, 32, "[Disabled] %s", PLUGIN_NAME)
        register_plugin(pluginName, PLUGIN_VERSION, PLUGIN_AUTHOR)
        pause("ade")
    }
    else
    {
        register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
        register_cvar(PLUGIN_NAME, PLUGIN_VERSION, FCVAR_SPONLY|FCVAR_SERVER)
        
        register_clcmd("sjp_givesj" ,         "cmd_GiveSJ",         ADMIN_IMMUNITY, "<userid> - Gives free surf jetpack")
        register_clcmd("sjp_stripsj" ,         "cmd_StripSJ",         ADMIN_IMMUNITY, "<userid> - Strips users surf jetpack")
        
        register_clcmd("say /buyjp",     "cmd_BuySurfJetpack", 0, "Buys surf jetpack")
        register_clcmd("say /jp",     "cmd_BuySurfJetpack", 0, "Buys surf jetpack")
        register_concmd("buy_jetpack",         "cmd_BuySurfJetpack", 0, "Buys surf jetpack")
        register_concmd("buyjetpack",         "cmd_BuySurfJetpack", 0, "Buys surf jetpack")
        
        cvar_cost    = get_cvar_num("fcsshop_jetpack_price")
        cvar_thrust     = register_cvar("sjp_thrust", "5")
        cvar_min_speed     = register_cvar("sjp_min_speed", "600")
        cvar_max_speed     = register_cvar("sjp_max_speed", "900")
        cvar_thrustvip     = register_cvar("vip_thrust", "8")
        cvar_minspeedvip     = register_cvar("vip_minspeed", "700")
        cvar_maxspeedvip     = register_cvar("vip_maxspeed", "1100")
        
        register_event("DeathMsg",         "Event_DeathMsg", "a")
    }
}

public plugin_precache()
{
    precache_sound(JETPACK_GOTSOUND)
    precache_model(JETPACK_PMODEL)
    precache_model(JETPACK_PMODEL_VIP)
}

public plugin_natives()
{
	register_native("give_jetpack", "native_give_jetpack")
        register_native("give_vip_jetpack", "native_give_vip_jetpack")
}


public client_connect(id)
{
    g_HasJetpack[id] = 0
    _removeJetpackEnt(id)
}
    
public client_disconnect(id)
{
    g_HasJetpack[id] = 0
    _removeJetpackEnt(id)
}

public Event_DeathMsg()
{
    new id = read_data(2)

    g_HasJetpack[id] = 0
    _removeJetpackEnt(id)

    return PLUGIN_CONTINUE
}

public cmd_BuySurfJetpack(id)
{
    new iMoney = fcs_get_user_credits(id)
    new iCost = get_pcvar_num(cvar_cost) 
    
    if(!is_user_alive(id)) 
        client_print(id, print_center, "You cant buy when your dead!")
    else if(g_HasJetpack[id])
        client_print(id, print_center, "You already own a surf jetpack.")
    else if(iMoney < iCost)
        client_print(id, print_center, "Insufficient funds! (%d Credits)", iCost)
    else
    {
        _give_Jetpack(id)
        fcs_sub_user_credits(id, iCost)
      }
    return PLUGIN_HANDLED
}

public cmd_GiveSJ(id , level , cid) 
{
    if(!cmd_access(id , level , cid , 2))
        return PLUGIN_HANDLED
        
    new arg1[33]
    read_argv(1 , arg1 , 32)

    new target = cmd_target(id , arg1 , 0)
    if(!is_user_connected(target))
    {
        console_print(id, "Player does not exist")
        return PLUGIN_HANDLED
    }

    if(g_HasJetpack[target])
    {
        console_print(id, "Player already has a surf jetpack")
        return PLUGIN_HANDLED
    }
    
    _vip_Jetpack(target)

    new Name[33], Name2[33]
    get_user_name(id, Name, 32)
    get_user_name(target, Name2, 32)
    
    console_print(id, "You gave %s a surf jetpack", Name2)
    CromChat(target,"^4[ADMIN]: ^3%s ^1gave you a surf ^4vip ^1jetpack,test it out!", Name)
    
    return PLUGIN_HANDLED
}

public cmd_StripSJ(id , level , cid) 
{
    if(!cmd_access(id , level , cid , 2))
        return PLUGIN_HANDLED
        
    new arg1[33]
    read_argv(1 , arg1 , 32)

    new target = cmd_target(id , arg1 , 0)
    if(!is_user_connected(target))
    {
        console_print(id, "Player does not exist")
        return PLUGIN_HANDLED
    }

    if(!g_HasJetpack[target])
    {
        console_print(id, "Player does not have a surf jetpack")
        return PLUGIN_HANDLED
    }
    
    g_HasJetpack[id] = 0
    _removeJetpackEnt(id)

    new Name[33], Name2[33]
    get_user_name(id, Name, 32)
    get_user_name(target, Name2, 32)
    
    console_print(id, "You stripped %s of his surf jetpack", Name2)
    CromChat(target,"^4[ADMIN]: ^3%s ^1stripped your surf jetpack.", Name)
    
    return PLUGIN_HANDLED
}

public _give_Jetpack(id)
{
    g_HasJetpack[id] = 1
    CromChat(id,"^4****^3YOU HAVE BOUGHT A ^1JETPACK,^3JUST SURF! ITS AUTOMATIC^4~~~")
    _set_jetpack_model(id)
}

public _vip_Jetpack(id)
{
    g_HasJetpack[id] = 2
    CromChat(id,"^4****^1to use the ^4VIP ^1jetpack just ^3surf ^1it will activate automatically.")
    _set_jetpack_model(id)
}

public _set_jetpack_model(id)
{
    client_cmd(id, "spk %s", JETPACK_GOTSOUND)

    if(g_JetpackEnt[id] < 1)
    {
        g_JetpackEnt[id] = create_entity("info_target")
        if(is_valid_ent(g_JetpackEnt[id]))
        {
            entity_set_model(g_JetpackEnt[id], g_HasJetpack[id] == 2 ? JETPACK_PMODEL_VIP : JETPACK_PMODEL)
            entity_set_int(g_JetpackEnt[id], EV_INT_movetype, MOVETYPE_FOLLOW)
            entity_set_edict(g_JetpackEnt[id], EV_ENT_aiment, id)
        }
    }
} 

public _removeJetpackEnt(id)
{
    if(g_JetpackEnt[id] > 0)
        remove_entity(g_JetpackEnt[id])
    g_JetpackEnt[id] = 0
}

public client_PreThink(id)
{
    if(!is_user_alive(id) || !g_HasJetpack[id])
        return PLUGIN_CONTINUE
        
    if(get_user_speed(id) < get_pcvar_num(g_HasJetpack[id] == 2 ? cvar_minspeedvip : cvar_min_speed)) 
        return PLUGIN_CONTINUE    
        
    new Button = get_user_button(id)
    if(Button & IN_MOVELEFT || Button & IN_MOVERIGHT)
    {           
        _jetThrust(id)
    }
    return PLUGIN_CONTINUE
}

public _jetThrust(id)
{    
    new Float:fVelocity[3]
    entity_get_vector(id, EV_VEC_velocity, fVelocity)

    new Float:fAngle[3]
    entity_get_vector(id, EV_VEC_angles, fAngle)
    engfunc(EngFunc_MakeVectors, fAngle)
                
    new Float:fForward[3]
    get_global_vector(GL_v_forward, fForward)
                
    fVelocity[0] += fForward[0] * get_pcvar_num( g_HasJetpack[id] == 2 ? cvar_thrustvip : cvar_thrust ) 
    fVelocity[1] += fForward[1] * get_pcvar_num( g_HasJetpack[id] == 2 ? cvar_thrustvip : cvar_thrust ) 
            
    if(get_user_speed(id) < get_pcvar_num(g_HasJetpack[id] == 2 ? cvar_maxspeedvip : cvar_max_speed)) 
        entity_set_vector(id, EV_VEC_velocity, fVelocity)
        
    return PLUGIN_CONTINUE
}

stock get_user_speed(id)
{
    new Float:fVelocity[3]
    entity_get_vector(id, EV_VEC_velocity, fVelocity)
    
    new iVelocity[3]
    FVecIVec(fVelocity, iVelocity)
    
    new iVelocity0 = iVelocity[0] * iVelocity[0]
    new iVelocity1 = iVelocity[1] * iVelocity[1]
    
    return sqroot(iVelocity0 + iVelocity1)
}

public native_give_jetpack(iPlugin, iParams)
{
    if(iParams != 1)
        return PLUGIN_CONTINUE
        
    new id = get_param(1)
    if(!id)
        return PLUGIN_CONTINUE

    if(g_HasJetpack[id])
    client_print(id, print_center, "You already own a surf jetpack.")
    else
    {
        _give_Jetpack(id)
    }
    return PLUGIN_HANDLED
}

public native_give_vip_jetpack(iPlugin, iParams)
{
    if(iParams != 1)
        return PLUGIN_CONTINUE
        
    new id = get_param(1)
    if(!id)
        return PLUGIN_CONTINUE

    if(g_HasJetpack[id])
    client_print(id, print_center, "You already own a surf jetpack.")
    else
    {
        _vip_Jetpack(id)
    }
    return PLUGIN_HANDLED
}
alright,this is the code
seems to work as intended,only one big problem remains,when i write /buyjp or /jp to get the original jetpack the server crashes.
Code:
Segmentation fault (core dumped)
email debug.log to [email protected]
Wed Dec 9 19:23:41 UTC 2020: Server restart in 10 seconds
this is the error im receiveing from the console
not a single error in the logs..
any idea causing this ?
gfxchris is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-09-2020 , 23:00   Re: how to change this (add item into a menu)
Reply With Quote #34

Well, I can't see what would be causing that. Maybe try disabling all plugins that are not required for this plugin to run and see what happens. If it still happens, you'll need to add debugging code to the plugin to find out what code is being executed when the crash occurs. I use server_print() when I have direct access to the console so that I can see the output even after it crashes. You should be able to find out how far you get into the code before a crash so that you can rule out any code that was successful. It is also very helpful to include the values of various variables in the print message to understand what values are actually being used.

You can also comment out function calls as a way to locate the failure. For example, you can comment out _give_Jetpack(id) in cmd_BuySurfJetpack() and then buy a jetpack and see if it still happens.

P.S. the PLUGIN_* constants are specifically for functions registered with a register_* function (if there are other proper use cases, I can't remember them off the top of my head). So, you shouldn't use these in your native functions. If you are not intending to use the value being returned by the native, then you should return with no value specified. If you want to return a specific value for plugins to use, you can do that too but it shouldn't be the PLUGIN_* constants.
__________________

Last edited by fysiks; 12-09-2020 at 23:08.
fysiks is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 12-09-2020 , 23:10   Re: how to change this (add item into a menu)
Reply With Quote #35

Quote:
Originally Posted by fysiks View Post
Well, I can't see what would be causing that. Maybe try disabling all plugins that are not required for this plugin to run and see what happens. If it still happens, you'll need to add debugging code to the plugin to find out what code is being executed when the crash occurs. I use server_print() when I have direct access to the console so that I can see the output even after it crashes. You should be able to find out how far you get into the code before a crash so that you can rule out any code that was successful. It is also very helpful to include the values of various variables in the print message to understand what values are actually being used.

You can also comment out function calls as a way to locate the failure. For example, you can comment out _give_Jetpack(id) in cmd_BuySurfJetpack() and then buy a jetpack and see if it still happens.

P.S. the PLUGIN_* constants are specifically for functions registered with a register_* function (if there are other proper use cases, I can't remember them off the top of my head). So, you shouldn't use these in your native functions. If you are not intending to use the value being returned by the native, then you should return with no value specified. If you want to return a specific value for plugins to use, you can do that too but it shouldn't be the PLUGIN_* constants.
Maybe #pragma dynamic?
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
iceeedr is online now
Send a message via Skype™ to iceeedr
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-10-2020 , 01:23   Re: how to change this (add item into a menu)
Reply With Quote #36

Quote:
Originally Posted by iceeedr View Post
Maybe #pragma dynamic?
Why would that be necessary? The original plugin worked just fine and we barely changed anything regarding how it actually functions. The only major difference is that we allow it to choose between two different models and cvar-based settings.
__________________
fysiks is offline
gfxchris
Member
Join Date: Feb 2016
Old 12-10-2020 , 07:42   Re: how to change this (add item into a menu)
Reply With Quote #37

alright so i tested it on a new game server,this is what i get whenever im writing /buyjp

Code:
[AMXX]
L 12/10/2020 - 13:46:20: Invalid CVAR pointer
L 12/10/2020 - 13:46:20: [AMXX] Displaying debug trace (plugin "ajet.amxx")
L 12/10/2020 - 13:46:20: [AMXX] Run time error 10: native error (native "get_pcvar_num")
L 12/10/2020 - 13:46:20: [AMXX]    [0] ajet.sma::cmd_BuySurfJetpack (line 115)
    new iCost = get_pcvar_num(cvar_cost)

edit v2.0: @fysiks you said you noticed this mistake : "new iCost = cvar_cost " -> "new iCost = get_pcvar_num(cvar_cost)"
this is the reason why it crashes when im writing /buyjp,what's the mistake here and how do i fix it properly to stop crashing my server?

(changing the new iCost = get_pcvar_num(cvar_cost) to new iCost = cvar_cost fixed the problem,but im waiting for fysiks to tell me why it's a mistake

Last edited by gfxchris; 12-10-2020 at 07:53. Reason: when enabling debug,it gives me error on line 115 (the icost one)
gfxchris is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-11-2020 , 00:05   Re: how to change this (add item into a menu)
Reply With Quote #38

Quote:
Originally Posted by gfxchris View Post
alright so i tested it on a new game server,this is what i get whenever im writing /buyjp

Code:
[AMXX]
L 12/10/2020 - 13:46:20: Invalid CVAR pointer
L 12/10/2020 - 13:46:20: [AMXX] Displaying debug trace (plugin "ajet.amxx")
L 12/10/2020 - 13:46:20: [AMXX] Run time error 10: native error (native "get_pcvar_num")
L 12/10/2020 - 13:46:20: [AMXX]    [0] ajet.sma::cmd_BuySurfJetpack (line 115)
    new iCost = get_pcvar_num(cvar_cost)

edit v2.0: @fysiks you said you noticed this mistake : "new iCost = cvar_cost " -> "new iCost = get_pcvar_num(cvar_cost)"
this is the reason why it crashes when im writing /buyjp,what's the mistake here and how do i fix it properly to stop crashing my server?

(changing the new iCost = get_pcvar_num(cvar_cost) to new iCost = cvar_cost fixed the problem,but im waiting for fysiks to tell me why it's a mistake
Sorry, looks like I was wrong on that one. Because you named the variable "cvar_cost" I thought it was a cvar pointer (because all the cvar pointers are named with the "cvar_" prefix).

So, to address this, change:

Code:
cvar_cost    = get_cvar_num("fcsshop_jetpack_price")
to this:
Code:
cvar_cost = get_cvar_pointer("fcsshop_jetpack_price")
Then, you need to move this line to a new forward called plugin_cfg():

Code:
public plugin_cfg()
{
    cvar_cost = get_cvar_pointer("fcsshop_jetpack_price")
}
And you would keep the previous suggestion with the get_pcvar_num().
__________________
fysiks is offline
gfxchris
Member
Join Date: Feb 2016
Old 12-12-2020 , 12:20   Re: how to change this (add item into a menu)
Reply With Quote #39

alright,now it works flawlessly,fysiks honestly thanks for all your help !
love you
gfxchris is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-12-2020 , 19:07   Re: how to change this (add item into a menu)
Reply With Quote #40

I'm glad you got it all working. I appreciate that you took the time and effort to write the code yourself. A lot of people wouldn't have done as much work as you did so it's nice to see.
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

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 09:53.


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