Raised This Month: $51 Target: $400
 12% 

what did i do wrong?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alahmoh
Member
Join Date: Jun 2018
Old 08-24-2022 , 12:25   what did i do wrong?
Reply With Quote #1

PHP Code:
/*================================================================================
    
    --------------------------
    -*- [ZP] Items Manager -*-
    --------------------------
    
    This plugin is part of Zombie Plague Mod and is distributed under the
    terms of the GNU General Public License. Check ZP_ReadMe.txt for details.
    
================================================================================*/

#include <amxmodx>
#include <fakemeta>
#include <amx_settings_api>
#include <zp50_colorchat>
#include <zp50_core_const>
#include <zp50_items_const>

// Extra Items file
new const ZP_EXTRAITEMS_FILE[] = "zp_extraitems.ini"

// CS Player PData Offsets (win32)
const OFFSET_CSMENUCODE 205

#define MAXPLAYERS 32

// For item list menu handlers
#define MENU_PAGE_ITEMS g_menu_data[id]
new g_menu_data[MAXPLAYERS+1]

enum _:TOTAL_FORWARDS
{
    
FW_ITEM_SELECT_PRE 0,
    
FW_ITEM_SELECT_POST
}
new 
g_Forwards[TOTAL_FORWARDS]
new 
g_ForwardResult

// Items data
new Array:g_ItemRealName
new Array:g_ItemName
new Array:g_ItemCost
new Array:g_ItemDescription
new g_ItemCount
new g_AdditionalMenuText[32]

public 
plugin_init()
{
    
register_plugin("[ZP] Items Manager"ZP_VERSION_STRING"ZP Dev Team")
    
    
register_clcmd("say /items""clcmd_items")
    
register_clcmd("say items""clcmd_items")
    
    
g_Forwards[FW_ITEM_SELECT_PRE] = CreateMultiForward("zp_fw_items_select_pre"ET_CONTINUEFP_CELLFP_CELLFP_CELL)
    
g_Forwards[FW_ITEM_SELECT_POST] = CreateMultiForward("zp_fw_items_select_post"ET_IGNOREFP_CELLFP_CELLFP_CELL)
}

public 
plugin_natives()
{
    
register_library("zp50_items")
    
register_native("zp_items_register""native_items_register")
    
register_native("zp_items_get_id""native_items_get_id")
    
register_native("zp_items_get_name""native_items_get_name")
    
register_native("zp_items_get_real_name""native_items_get_real_name")
    
register_native("zp_items_get_cost""native_items_get_cost")
    
register_native("zp_items_get_description""native_items_get_description")
    
register_native("zp_items_show_menu""native_items_show_menu")
    
register_native("zp_items_force_buy""native_items_force_buy")
    
register_native("zp_items_menu_text_add""native_items_menu_text_add")
    
    
// Initialize dynamic arrays
    
g_ItemRealName ArrayCreate(321)
    
g_ItemName ArrayCreate(321)
    
g_ItemCost ArrayCreate(11)
    
g_ItemDescription ArrayCreate(321)
}

public 
native_items_register(plugin_idnum_params)
{
    new 
name[32],description[32], cost get_param(2)
    
get_string(1namecharsmax(name))
    
get_string(2descriptioncharsmax(description))
    
    if (
strlen(name) < 1)
    {
        
log_error(AMX_ERR_NATIVE"[ZP] Can't register item with an empty name")
        return 
ZP_INVALID_ITEM;
    }
    
    new 
indexitem_name[32]
    for (
index 0index g_ItemCountindex++)
    {
        
ArrayGetString(g_ItemRealNameindexitem_namecharsmax(item_name))
        if (
equali(nameitem_name))
        {
            
log_error(AMX_ERR_NATIVE"[ZP] Item already registered (%s)"name)
            return 
ZP_INVALID_ITEM;
        }
    }
    
    
// Load settings from extra items file
    
new real_name[32]
    
copy(real_namecharsmax(real_name), name)
    
copy(real_name,charsmax(real_name),description)
    
ArrayPushString(g_ItemRealNamereal_name)
    
    
// Name
    
if (!amx_load_setting_string(ZP_EXTRAITEMS_FILEreal_name"NAME"namecharsmax(name)))
        
amx_save_setting_string(ZP_EXTRAITEMS_FILEreal_name"NAME"name)
    
ArrayPushString(g_ItemNamename)
    
    if (!
amx_load_setting_string(ZP_EXTRAITEMS_FILEreal_name"DESCRIPTION"descriptioncharsmax(description)))
        
amx_save_setting_string(ZP_EXTRAITEMS_FILEreal_name"DESCRIPTION"description)
    
ArrayPushString(g_ItemDescriptiondescription)
    
    
// Cost
    
if (!amx_load_setting_int(ZP_EXTRAITEMS_FILEreal_name"COST"cost))
        
amx_save_setting_int(ZP_EXTRAITEMS_FILEreal_name"COST"cost)
    
ArrayPushCell(g_ItemCostcost)
    
    
g_ItemCount++
    return 
g_ItemCount 1;
}

public 
native_items_get_id(plugin_idnum_params)
{
    new 
real_name[32]
    
get_string(1real_namecharsmax(real_name))
    
    
// Loop through every item
    
new indexitem_name[32]
    for (
index 0index g_ItemCountindex++)
    {
        
ArrayGetString(g_ItemRealNameindexitem_namecharsmax(item_name))
        if (
equali(real_nameitem_name))
            return 
index;
    }
    
    return 
ZP_INVALID_ITEM;
}

public 
native_items_get_name(plugin_idnum_params)
{
    new 
item_id get_param(1)
    
    if (
item_id || item_id >= g_ItemCount)
    {
        
log_error(AMX_ERR_NATIVE"[ZP] Invalid item id (%d)"item_id)
        return 
false;
    }
    
    new 
name[32]
    
ArrayGetString(g_ItemNameitem_idnamecharsmax(name))
    
    new 
len get_param(3)
    
set_string(2namelen)
    return 
true;
}

public 
native_items_get_description(plugin_idnum_params)
{
    new 
item_id get_param(1)
    
    if (
item_id || item_id >= g_ItemCount)
    {
        
log_error(AMX_ERR_NATIVE"[ZP] Invalid item id (%d)"item_id)
        return 
false;
    }
    
    new 
description[32]
    
ArrayGetString(g_ItemDescriptionitem_iddescriptioncharsmax(description))
    
    new 
len get_param(3)
    
set_string(2descriptionlen)
    return 
true;
}

public 
native_items_get_real_name(plugin_idnum_params)
{
    new 
item_id get_param(1)
    
    if (
item_id || item_id >= g_ItemCount)
    {
        
log_error(AMX_ERR_NATIVE"[ZP] Invalid item id (%d)"item_id)
        return 
false;
    }
    
    new 
real_name[32]
    
ArrayGetString(g_ItemRealNameitem_idreal_namecharsmax(real_name))
    
    new 
len get_param(3)
    
set_string(2real_namelen)
    return 
true;
}

public 
native_items_get_cost(plugin_idnum_params)
{
    new 
item_id get_param(1)
    
    if (
item_id || item_id >= g_ItemCount)
    {
        
log_error(AMX_ERR_NATIVE"[ZP] Invalid item id (%d)"item_id)
        return -
1;
    }
    
    return 
ArrayGetCell(g_ItemCostitem_id);
}

public 
native_items_show_menu(plugin_idnum_params)
{
    new 
id get_param(1)
    
    if (!
is_user_connected(id))
    {
        
log_error(AMX_ERR_NATIVE"[ZP] Invalid Player (%d)"id)
        return 
false;
    }
    
    
clcmd_items(id)
    return 
true;
}

public 
native_items_force_buy(plugin_idnum_params)
{
    new 
id get_param(1)
    
    if (!
is_user_connected(id))
    {
        
log_error(AMX_ERR_NATIVE"[ZP] Invalid Player (%d)"id)
        return 
false;
    }
    
    new 
item_id get_param(2)
    
    if (
item_id || item_id >= g_ItemCount)
    {
        
log_error(AMX_ERR_NATIVE"[ZP] Invalid item id (%d)"item_id)
        return 
false;
    }
    
    new 
ignorecost get_param(3)
    
    
buy_item(iditem_idignorecost)
    return 
true;
}

public 
native_items_menu_text_add(plugin_idnum_params)
{
    static 
text[32]
    
get_string(1textcharsmax(text))
    
format(g_AdditionalMenuTextcharsmax(g_AdditionalMenuText), "%s%s"g_AdditionalMenuTexttext)
}

public 
client_disconnected(id)
{
    
// Reset remembered menu pages
    
MENU_PAGE_ITEMS 0
}

public 
clcmd_items(id)
{
    
// Player dead
    
if (!is_user_alive(id))
        return;
    
    
show_items_menu(id)
}

// Items Menu
show_items_menu(id)
{
    static 
menu[128], name[32],description[32], costtranskey[64]
    new 
menuidindexitemdata[2]
    
    
// Title
    
formatex(menucharsmax(menu), "%L:\r"id"MENU_EXTRABUY")
    
menuid menu_create(menu"menu_extraitems")
    
    
// Item List
    
for (index 0index g_ItemCountindex++)
    {
        
// Additional text to display
        
g_AdditionalMenuText[0] = 0
        
        
// Execute item select attempt forward
        
ExecuteForward(g_Forwards[FW_ITEM_SELECT_PRE], g_ForwardResultidindex0)
        
        
// Show item to player?
        
if (g_ForwardResult >= ZP_ITEM_DONT_SHOW)
            continue;
        
        
// Add Item Name and Cost
        
ArrayGetString(g_ItemNameindexnamecharsmax(name))
        
ArrayGetString(g_ItemDescriptionindexdescription,charsmax(description))
        
cost ArrayGetCell(g_ItemCostindex)
        
        
// ML support for item name
        
formatex(transkeycharsmax(transkey), "ITEMNAME %s"name)
        if (
GetLangTransKey(transkey) != TransKey_Badformatex(namecharsmax(name), "%L"idtranskey)
        
        
// Item available to player?
        
if (g_ForwardResult >= ZP_ITEM_NOT_AVAILABLE)
            
formatex(menucharsmax(menu), "\d%s \r(%s) %d %s"name,descriptioncostg_AdditionalMenuText)
        else
            
formatex(menucharsmax(menu), "%s \r(%s) \y%d \w%s"name,descriptioncostg_AdditionalMenuText)
        
        
itemdata[0] = index
        itemdata
[1] = 0
        menu_additem
(menuidmenuitemdata)
    }
    
    
// No items to display?
    
if (menu_items(menuid) <= 0)
    {
        
zp_colored_print(id"%L"id"NO_EXTRA_ITEMS")
        
menu_destroy(menuid)
        return;
    }
    
    
// Back - Next - Exit
    
formatex(menucharsmax(menu), "%L"id"MENU_BACK")
    
menu_setprop(menuidMPROP_BACKNAMEmenu)
    
formatex(menucharsmax(menu), "%L"id"MENU_NEXT")
    
menu_setprop(menuidMPROP_NEXTNAMEmenu)
    
formatex(menucharsmax(menu), "%L"id"MENU_EXIT")
    
menu_setprop(menuidMPROP_EXITNAMEmenu)
    
    
// If remembered page is greater than number of pages, clamp down the value
    
MENU_PAGE_ITEMS min(MENU_PAGE_ITEMSmenu_pages(menuid)-1)
    
    
// Fix for AMXX custom menus
    
set_pdata_int(idOFFSET_CSMENUCODE0)
    
menu_display(idmenuidMENU_PAGE_ITEMS)
}

// Items Menu
public menu_extraitems(idmenuiditem)
{
    
// Menu was closed
    
if (item == MENU_EXIT)
    {
        
MENU_PAGE_ITEMS 0
        menu_destroy
(menuid)
        return 
PLUGIN_HANDLED;
    }
    
    
// Remember items menu page
    
MENU_PAGE_ITEMS item 7
    
    
// Dead players are not allowed to buy items
    
if (!is_user_alive(id))
    {
        
menu_destroy(menuid)
        return 
PLUGIN_HANDLED;
    }
    
    
// Retrieve item id
    
new itemdata[2], dummyitemid
    menu_item_getinfo
(menuiditemdummyitemdatacharsmax(itemdata), __dummy)
    
itemid itemdata[0]
    
    
// Attempt to buy the item
    
buy_item(iditemid)
    
menu_destroy(menuid)
    return 
PLUGIN_HANDLED;
}

// Buy Item
buy_item(iditemidignorecost 0)
{
    
// Execute item select attempt forward
    
ExecuteForward(g_Forwards[FW_ITEM_SELECT_PRE], g_ForwardResultiditemidignorecost)
    
    
// Item available to player?
    
if (g_ForwardResult >= ZP_ITEM_NOT_AVAILABLE)
        return;
    
    
// Execute item selected forward
    
ExecuteForward(g_Forwards[FW_ITEM_SELECT_POST], g_ForwardResultiditemidignorecost)

so i wanted to creat items opis for zp server but it doesnt work at all.
please tell me what did i do wrong, not proffisenal in arrays.
Alahmoh 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 01:33.


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