AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with a Knife Shop. (Natives) (https://forums.alliedmods.net/showthread.php?t=233364)

Going Dutch 01-13-2014 15:37

Help with a Knife Shop. (Natives)
 
1 Attachment(s)
Hello,

PHP Code:

native hnsxp_get_user_xp(client);

native hnsxp_set_user_xp(clientxp);

stock hnsxp_add_user_xp(clientxp)
{
    return 
hnsxp_set_user_xp(clienthnsxp_get_user_xp(client) + xp);
}

stock hnsxp_sub_user_xp(clientxp)
{
    return 
hnsxp_set_user_xp(clienthnsxp_get_user_xp(client) - xp);
}


#include <amxmodx>
#include <cstrike>
#include <fakemeta>

#define SKINS 2

new g_knife[33];
new 
g_xp[33];

public 
plugin_natives()
{
    
register_library("hns_xp");
    
register_native("hnsxp_get_user_xp""_get_xp");
}

public 
_get_xp(pluginparams)
{
    return 
g_xp[get_param(1)];
}
    
new const 
g_knifemodels[SKINS][64] = {
    
"models/v_knife.mdl"// The default model, don't touch
    
"models/v_knife.mdl"
}

new const 
g_knifenames [SKINS][32] = {
    
"Default Knife",
    
"Custom Knife #1"
}

new 
g_knifecosts[SKINS][] = {
    
"0",
    
"500"
}

new 
g_knifeflag[SKINS][] = {
    
"0",
    
"0"
}  

static const DIE    [ ] = 
"You can not open a shop, you must be alive !"
static const MONEY    [ ] = "You dont have money for this knife skin !"
static const BUY    [ ] = "You bought ^3"

#define PLUGIN ""
#define VERSION ""
#define AUTHOR ""

#define VIP_FLAG ADMIN_LEVEL_G


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /knifeshop""cmd_knife")
    
register_clcmd("say /knife""cmd_knife")
    
    
register_event("CurWeapon","Event_CurWeapon","be","1=1");
}

public 
plugin_precache(){
    for (new 
i<= sizeof g_knifemodelsi++)
        
precache_model(g_knifemodels[i]);
}
    
public 
client_putinserver(client)
    
g_knife[client] = 0;

public 
Event_CurWeapon(client){
    
    if (
read_data(2) == CSW_KNIFE)
        
set_pev(client,pev_viewmodel2,g_knifemodels[g_knife[client]]);
    
}

public 
cmd_knife(id){
    new 
szSome[256];
    if(
is_user_alive(id))
    {
        new 
knife menu_create("Select your Knife""cmd_knife_h");
        new 
cb menu_makecallback("knife_callback");
        
        for (new 
i<= SKINS 1i++)
        {
                 
formatex(szSome,255,"%s \r[%sXP] \y%i",g_knifenames[i],str_to_num(g_knifecosts[i]),(str_to_num(g_knifeflag[i]) ? "[VIP]":""));  
            
menu_additem(knife,szSome,g_knifeflag[i],.callback=cb);
        }    
        
        
menu_display(id,knife);
    }
    
    else
        
ChatColor(id"%s %s", DIE);
}

public 
knife_callback(client,knife,item){
    new 
access,callback,szInfo[8],szName[32];
    
menu_item_getinfo(knife,item,access,szInfo,8,szName,32,callback);
    
    if (
str_to_num(szInfo) == && !(get_user_flags(client) & VIP_FLAG))
        return 
ITEM_DISABLED;
        
    return 
ITEM_ENABLED;
}
    
public 
cmd_knife_h(clientknifeitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(knife);
        return;
    }
    
    if (
g_xp(client) < str_to_num(g_knifecosts[item]))
    {
        
ChatColor(client,"%s %s",MONEY);
        return;
    }
    
    
_get_xp(client,(_get_xp(client) - str_to_num(g_knifecosts[item])),1);
    
g_knife[client] = item;
    
ChatColor(client,"%s %s%s",BUY,g_knifenames[g_knife[client]]);
}
    
stock ChatColor(const id, const input[], any:...) {
    new 
count 1players32 ]
    static 
msg191 ]
    
vformatmsg190input)
    
    
replace_allmsg190"!g""^4" )
    
replace_allmsg190"!y""^1" )
    
replace_allmsg190"!t""^3" )

    
    if(
idplayers] = id
    else 
get_playersplayerscount"ch" )
    
    for(new 
0counti++)
    {
        if( 
is_user_connectedplayers] ) )
        {
            
message_beginMSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players] )  
            
write_byteplayers] )
            
write_stringmsg )
            
message_end( )
        }
    }


I am trying to implement the hidenseek xp mod by exolent into this shop, so you will pay with the XP earned from that xpmod.

But so far i am getting this error:
Quote:

Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team

Warning: Loose indentation on line 101
Error: Undefined symbol "xp" on line 129
Error: Number of arguments does not match definition on line 135

2 Errors.
I am really confused about all this.

YamiKaitou 01-13-2014 16:10

Re: Help with a Knife Shop. (Natives)
 
g_xp is an array, not a function.

You cannot call _get_xp directly, you have to call the native it is assigned to

Going Dutch 01-14-2014 07:06

Re: Help with a Knife Shop. (Natives)
 
Hello,

I have removed the g_xp array and replaced the _get_xp with hnsxp_sub_user_xp.

I am still getting some errors, i know i am probably doing something terribly stupid..
Could you please explain to me how i could do this right?

PHP Code:

native hnsxp_get_user_xp(client);

native hnsxp_set_user_xp(clientxp);

stock hnsxp_add_user_xp(clientxp)
{
    return 
hnsxp_set_user_xp(clienthnsxp_get_user_xp(client) + xp);
}

stock hnsxp_sub_user_xp(clientxp)
{
    return 
hnsxp_set_user_xp(clienthnsxp_get_user_xp(client) - xp);
}

#include <amxmodx>
#include <cstrike>
#include <fakemeta>

#define SKINS 11

new g_knife[33]; 

new const 
g_knifemodels[SKINS][64] = {
    
"models/v_knife.mdl"// The default model, don't touch
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl"
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl"
    
"models/v_knife.mdl",
    
"models/v_knife.mdl"
}

new const 
g_knifenames [SKINS][32] = {
    
"Default Knife",
    
"Dorex Knife",
    
"Lightning Knife",
    
"Master Knife",
    
"Traker Knife",
    
"Ultimate Knife",
    
"Ice Knife",
    
"Bloody Knife",
    
"Evolution Knife",
    
"Simple Knife",
    
"Crool Knife"
}

new 
g_knifecosts[SKINS][] = {
    
"0",
    
"5",
    
"5",
    
"5",
    
"5",
    
"5",
    
"10",
    
"10",
    
"15",
    
"15",
    
"15"
}

new 
g_knifeflag[SKINS][] = {
    
"0",
    
"0",
    
"0",
    
"0",
    
"0",
    
"0",
    
"1",
    
"1",
    
"1",
    
"1",
    
"1"
}  

static const 
PORTAL    [ ] = "^4[Website coming soon]^1"
static const DIE    [ ] = "You can not open this shop, you must be alive !"
static const MONEY    [ ] = "You dont have enough money for this knife skin !"
static const BUY    [ ] = "You have bought ^3"

#define PLUGIN ""
#define VERSION ""
#define AUTHOR ""

#define VIP_FLAG ADMIN_LEVEL_G


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /knifeshop""cmd_knife")
    
register_clcmd("say /knife""cmd_knife")
    
    
register_event("CurWeapon","Event_CurWeapon","be","1=1");
}

public 
plugin_precache(){
    for (new 
i<= sizeof g_knifemodelsi++)
        
precache_model(g_knifemodels[i]);
}

public 
client_putinserver(client)
    
g_knife[client] = 0;

public 
Event_CurWeapon(client){
    
    if (
read_data(2) == CSW_KNIFE)
        
set_pev(client,pev_viewmodel2,g_knifemodels[g_knife[client]]);
    
}

public 
cmd_knife(id){
    new 
szSome[256];
    if(
is_user_alive(id))
    {
        new 
knife menu_create("Select your Knife""cmd_knife_h");
        new 
cb menu_makecallback("knife_callback");
        
        for (new 
i<= SKINS 1i++)
        {
            
formatex(szSome,255,"%s \r[%i$] \y%s",g_knifenames[i],str_to_num(g_knifecosts[i]),(str_to_num(g_knifeflag[i]) ? "[VIP]":""));  
            
menu_additem(knife,szSome,g_knifeflag[i],.callback=cb);
        }    
        
        
menu_display(id,knife);
    }
    
    else
        
ChatColor(id"%s %s"PORTAL, DIE);
}

public 
knife_callback(client,knife,item){
    new 
access,callback,szInfo[8],szName[32];
    
menu_item_getinfo(knife,item,access,szInfo,8,szName,32,callback);
    
    if (
str_to_num(szInfo) == && !(get_user_flags(client) & VIP_FLAG))
        return 
ITEM_DISABLED;
    
    return 
ITEM_ENABLED;
}

public 
cmd_knife_h(clientknifeitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(knife);
        return;
    }
    
    if (
hnsxp_sub_user_xp(client) < str_to_num(g_knifecosts[item]))
    {
        
ChatColor(client,"%s %s",PORTAL,MONEY);
        return;
    }
    
    
hnsxp_sub_user_xp(client,(hnsxp_sub_user_xp(client) - str_to_num(g_knifecosts[item])),1);
    
g_knife[client] = item;
    
ChatColor(client,"%s %s%s",PORTAL,BUY,g_knifenames[g_knife[client]]);
}

stock ChatColor(const id, const input[], any:...) {
    new 
count 1players32 ]
    static 
msg191 ]
    
vformatmsg190input)
    
    
replace_allmsg190"!g""^4" )
    
replace_allmsg190"!y""^1" )
    
replace_allmsg190"!t""^3" )
    
    
    if(
idplayers] = id
    else 
get_playersplayerscount"ch" )
    
    for(new 
0counti++)
    {
        if( 
is_user_connectedplayers] ) )
        {
            
message_beginMSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players] )  
            
write_byteplayers] )
            
write_stringmsg )
            
message_end( )
        }
    }


Quote:

Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team

Error: Number of arguments does not match definition on line 154
Error: Number of arguments does not match definition on line 160

2 Errors.
Thank you

YamiKaitou 01-14-2014 07:19

Re: Help with a Knife Shop. (Natives)
 
Stock hnsxp_sub_user_xp has 2 parameters, not 1

Going Dutch 01-14-2014 08:04

Re: Help with a Knife Shop. (Natives)
 
Hi,

I almost got it, only getting one error now.

Quote:

Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team

Error: Number of arguments does not match definition on line 169

1 Error.
This line is wrong:

PHP Code:

hnsxp_set_user_xp(client, (hnsxp_get_user_xp(client) - str_to_num(g_knifecosts[item])),1); 



PHP Code:

native hnsxp_get_user_xp(client);

native hnsxp_set_user_xp(clientxp);

stock hnsxp_add_user_xp(clientxp)
{
    return 
hnsxp_set_user_xp(clienthnsxp_get_user_xp(client) + xp);
}

stock hnsxp_sub_user_xp(clientxp)
{
    return 
hnsxp_set_user_xp(clienthnsxp_get_user_xp(client) - xp);
}

#include <amxmodx>
#include <cstrike>
#include <fakemeta>

#define SKINS 11

new g_knife[33]; 
new 
g_xp[33];
new const 
g_knifemodels[SKINS][64] = {
    
"models/v_knife.mdl"// The default model, don't touch
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl"
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl"
    
"models/v_knife.mdl",
    
"models/v_knife.mdl"
}

new const 
g_knifenames [SKINS][32] = {
    
"Default Knife",
    
"Dorex Knife",
    
"Lightning Knife",
    
"Master Knife",
    
"Traker Knife",
    
"Ultimate Knife",
    
"Ice Knife",
    
"Bloody Knife",
    
"Evolution Knife",
    
"Simple Knife",
    
"Crool Knife"
}

new 
g_knifecosts[SKINS][] = {
    
"0",
    
"5",
    
"5",
    
"5",
    
"5",
    
"5",
    
"10",
    
"10",
    
"15",
    
"15",
    
"15"
}

new 
g_knifeflag[SKINS][] = {
    
"0",
    
"0",
    
"0",
    
"0",
    
"0",
    
"0",
    
"1",
    
"1",
    
"1",
    
"1",
    
"1"
}  

static const 
PORTAL    [ ] = "^4[Website coming soon]^1"
static const DIE    [ ] = "You can not open this shop, you must be alive !"
static const MONEY    [ ] = "You dont have enough XP for this knife skin !"
static const BUY    [ ] = "You have bought ^3"

#define PLUGIN ""
#define VERSION ""
#define AUTHOR ""

#define VIP_FLAG ADMIN_LEVEL_G

public plugin_natives()
{
    
register_library("hns_xp");
    
register_native("hnsxp_get_user_xp""_get_xp");
    
register_native("hnsxp_set_user_xp""_set_xp");
}

public 
_get_xp(pluginparams)
{
    return 
g_xp[get_param(1)];
}
public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /knifeshop""cmd_knife")
    
register_clcmd("say /knife""cmd_knife")
    
    
register_event("CurWeapon","Event_CurWeapon","be","1=1");
}

public 
plugin_precache(){
    for (new 
i<= sizeof g_knifemodelsi++)
        
precache_model(g_knifemodels[i]);
}

public 
client_putinserver(client)
    
g_knife[client] = 0;

public 
Event_CurWeapon(client){
    
    if (
read_data(2) == CSW_KNIFE)
        
set_pev(client,pev_viewmodel2,g_knifemodels[g_knife[client]]);
    
}

public 
cmd_knife(id){
    new 
szSome[256];
    if(
is_user_alive(id))
    {
        new 
knife menu_create("Select your Knife""cmd_knife_h");
        new 
cb menu_makecallback("knife_callback");
        
        for (new 
i<= SKINS 1i++)
        {
            
formatex(szSome,255,"%s \r[%i$] \y%s",g_knifenames[i],str_to_num(g_knifecosts[i]),(str_to_num(g_knifeflag[i]) ? "[VIP]":""));  
            
menu_additem(knife,szSome,g_knifeflag[i],.callback=cb);
        }    
        
        
menu_display(id,knife);
    }
    
    else
        
ChatColor(id"%s %s"PORTAL, DIE);
}

public 
knife_callback(client,knife,item){
    new 
access,callback,szInfo[8],szName[32];
    
menu_item_getinfo(knife,item,access,szInfo,8,szName,32,callback);
    
    if (
str_to_num(szInfo) == && !(get_user_flags(client) & VIP_FLAG))
        return 
ITEM_DISABLED;
    
    return 
ITEM_ENABLED;
}

public 
cmd_knife_h(clientknifeitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(knife);
        return;
    }
    
    if (
hnsxp_get_user_xp(client) < str_to_num(g_knifecosts[item]))
    {
        
ChatColor(client,"%s %s",PORTAL,MONEY);
        return;
    }
    
    
hnsxp_set_user_xp(client, (hnsxp_get_user_xp(client) - str_to_num(g_knifecosts[item])),1);
    
g_knife[client] = item;
    
ChatColor(client,"%s %s%s",PORTAL,BUY,g_knifenames[g_knife[client]]);
}

stock ChatColor(const id, const input[], any:...) {
    new 
count 1players32 ]
    static 
msg191 ]
    
vformatmsg190input)
    
    
replace_allmsg190"!g""^4" )
    
replace_allmsg190"!y""^1" )
    
replace_allmsg190"!t""^3" )
    
    
    if(
idplayers] = id
    else 
get_playersplayerscount"ch" )
    
    for(new 
0counti++)
    {
        if( 
is_user_connectedplayers] ) )
        {
            
message_beginMSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players] )  
            
write_byteplayers] )
            
write_stringmsg )
            
message_end( )
        }
    }


Sorry if i am asking too much, but i really want to get this right.

Thank you

YamiKaitou 01-14-2014 08:07

Re: Help with a Knife Shop. (Natives)
 
Native hnsxp_set_user_xp requires 2 parameters, not 3.

If you just read the code, you will find these solutions yourself

Going Dutch 01-14-2014 09:08

Re: Help with a Knife Shop. (Natives)
 
It finally compiles, but the problem is i cant buy anything.
It doesn't remove any XP nor money.

PHP Code:

native hnsxp_get_user_xp(client);

native hnsxp_set_user_xp(clientxp);

stock hnsxp_add_user_xp(clientxp)
{
    return 
hnsxp_set_user_xp(clienthnsxp_get_user_xp(client) + xp);
}

stock hnsxp_sub_user_xp(clientxp)
{
    return 
hnsxp_set_user_xp(clienthnsxp_get_user_xp(client) - xp);
}

#include <amxmodx>
#include <cstrike>
#include <fakemeta>

#define SKINS 11

new g_knife[33]; 
new 
g_xp[33];
new const 
g_knifemodels[SKINS][64] = {
    
"models/v_knife.mdl"// The default model, don't touch
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl"
    
"models/v_knife.mdl",
    
"models/v_knife.mdl",
    
"models/v_knife.mdl"
    
"models/v_knife.mdl",
    
"models/v_knife.mdl"
}

new const 
g_knifenames [SKINS][32] = {
    
"Default Knife",
    
"Dorex Knife",
    
"Lightning Knife",
    
"Master Knife",
    
"Traker Knife",
    
"Ultimate Knife",
    
"Ice Knife",
    
"Bloody Knife",
    
"Evolution Knife",
    
"Simple Knife",
    
"Crool Knife"
}

new 
g_knifecosts[SKINS][] = {
    
"0",
    
"5",
    
"5",
    
"5",
    
"5",
    
"5",
    
"10",
    
"10",
    
"15",
    
"15",
    
"15"
}

new 
g_knifeflag[SKINS][] = {
    
"0",
    
"0",
    
"0",
    
"0",
    
"0",
    
"0",
    
"1",
    
"1",
    
"1",
    
"1",
    
"1"
}  

static const 
PORTAL    [ ] = "^4[Website coming soon]^1"
static const DIE    [ ] = "You can not open this shop, you must be alive !"
static const MONEY    [ ] = "You dont have enough XP for this knife skin !"
static const BUY    [ ] = "You have bought ^3"

#define PLUGIN ""
#define VERSION ""
#define AUTHOR ""

#define VIP_FLAG ADMIN_LEVEL_G

public plugin_natives()
{
    
register_library("hns_xp");
    
register_native("hnsxp_get_user_xp""_get_xp");
}

public 
_get_xp(pluginparams)
{
    return 
g_xp[get_param(1)];
}
public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /knifeshop""cmd_knife")
    
register_clcmd("say /knife""cmd_knife")
    
    
register_event("CurWeapon","Event_CurWeapon","be","1=1");
}

public 
plugin_precache(){
    for (new 
i<= sizeof g_knifemodelsi++)
        
precache_model(g_knifemodels[i]);
}

public 
client_putinserver(client)
    
g_knife[client] = 0;

public 
Event_CurWeapon(client){
    
    if (
read_data(2) == CSW_KNIFE)
        
set_pev(client,pev_viewmodel2,g_knifemodels[g_knife[client]]);
    
}

public 
cmd_knife(id){
    new 
szSome[256];
    if(
is_user_alive(id))
    {
        new 
knife menu_create("Select your Knife""cmd_knife_h");
        new 
cb menu_makecallback("knife_callback");
        
        for (new 
i<= SKINS 1i++)
        {
            
formatex(szSome,255,"%s \r[%i$] \y%s",g_knifenames[i],str_to_num(g_knifecosts[i]),(str_to_num(g_knifeflag[i]) ? "[VIP]":""));  
            
menu_additem(knife,szSome,g_knifeflag[i],.callback=cb);
        }    
        
        
menu_display(id,knife);
    }
    
    else
        
ChatColor(id"%s %s"PORTAL, DIE);
}

public 
knife_callback(client,knife,item){
    new 
access,callback,szInfo[8],szName[32];
    
menu_item_getinfo(knife,item,access,szInfo,8,szName,32,callback);
    
    if (
str_to_num(szInfo) == && !(get_user_flags(client) & VIP_FLAG))
        return 
ITEM_DISABLED;
    
    return 
ITEM_ENABLED;
}

public 
cmd_knife_h(clientknifeitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(knife);
        return;
    }
    
    if (
hnsxp_get_user_xp(client) < str_to_num(g_knifecosts[item]))
    {
        
ChatColor(client,"%s %s",PORTAL,MONEY);
        return;
    }
    
    
_get_xp(client, - str_to_num(g_knifecosts[item]))
    
g_knife[client] = item;
    
ChatColor(client,"%s %s%s",PORTAL,BUY,g_knifenames[g_knife[client]]);
}

stock ChatColor(const id, const input[], any:...) {
    new 
count 1players32 ]
    static 
msg191 ]
    
vformatmsg190input)
    
    
replace_allmsg190"!g""^4" )
    
replace_allmsg190"!y""^1" )
    
replace_allmsg190"!t""^3" )
    
    
    if(
idplayers] = id
    else 
get_playersplayerscount"ch" )
    
    for(new 
0counti++)
    {
        if( 
is_user_connectedplayers] ) )
        {
            
message_beginMSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players] )  
            
write_byteplayers] )
            
write_stringmsg )
            
message_end( )
        }
    }




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

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