AlliedModders

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

AnimalMonster 10-20-2020 06:43

Help Scripting
 
https://forums.alliedmods.net/showthread.php?t=243419
Or never mind, i came to get some help in editing this plugin. I wanted ti make a new native that gets the extra item id like zombie plague does since i met zp_get_extra_item_id in a buymenu plugin i wanna use, i wanted you to help me script this thing out in this shop menu for ze, please help me:))

AnimalMonster 10-21-2020 05:01

Re: Help Scripting
 
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <zev2_core>

#define PLUGIN "Zombie Escape V2: Shop"
#define VERSION "1.0.0"
#define AUTHOR "Kia"

// ===============================================================================
//     Variables
// ===============================================================================

/* Enums */

enum _:ItemData
{
    
ItemName[32],
    
ItemTeam,
    
ItemCost,
    
ItemPlugin,
    
ItemFuncID
}

/* Arrays */

new Array:g_aItems

/* Integer */

new g_iTotalItems
new g_iCredits[33]

// ===============================================================================
//     plugin_natives
// ===============================================================================

public plugin_natives()
{
    
register_library("zev2_shop")
    
    
register_native("ZEV2_AddItem""Native_ZEV2_AddItem")
    
register_native("ZEV2_GetUserCredits""Native_ZEV2_GetUserCreidts")
    
register_native("ZEV2_SetUserCredits""Native_ZEV2_SetUserCreidts")
}

// ===============================================================================
//     Native_ZEV2_AddItem
// ===============================================================================

public Native_ZEV2_AddItem(iPluginiParams)
{
    new 
eItemData[ItemData]
    
    
get_string(1eItemData[ItemName], charsmax(eItemData[ItemName]))
    
eItemData[ItemTeam] = get_param(2)
    
eItemData[ItemCost] = get_param(3)
    
eItemData[ItemPlugin] = iPlugin
    
    
new szHandler32 ];
    
get_string(4szHandlercharsmaxszHandler ) );
    
eItemDataItemFuncID ] = get_func_idszHandleriPlugin );
    
    
ArrayPushArray(g_aItemseItemData)
    
g_iTotalItems++
    
    return (
g_iTotalItems 1)
}

// ===============================================================================
//     Native_ZEV2_GetUserCreidts
// ===============================================================================

public Native_ZEV2_GetUserCreidts(iPlayer)
    return 
g_iCredits[get_param(1)]

// ===============================================================================
//     Native_ZEV2_SetUserCreidts
// ===============================================================================

public Native_ZEV2_SetUserCreidts(iPlayeriAmount)
{
    new 
iPlayer get_param(1);
    
g_iCredits[iPlayer] = max(0get_param(2));
    
    return 
g_iCredits[iPlayer];
}


// ===============================================================================
//     plugin_init
// ===============================================================================

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
/* Arrays */
    
    
g_aItems ArrayCreate(ItemData)
    
    
/* ClCMDs */
    
    
register_clcmd("say /shop""CreditShop")
}

// ===============================================================================
//     WeaponShop
// ===============================================================================

public CreditShop(idiPage)
{
    if(!
g_iTotalItems || !is_user_alive(id)) 
        return;
    
    
iPage clamp(iPage0, (g_iTotalItems 1) / )
    
    new 
szMenuString[64]
    
formatex(szMenuStringcharsmax(szMenuString), "Zombie Escape V2 - Item Shop^nYour Credits : \y%i"g_iCredits[id])
    
    new 
menu menu_create(szMenuString"CreditShop_handler")
    
    new 
eItemData[ItemData]
    new 
szItem[64]
    new 
szNum[3]
    new 
bool:bZombieReq
    
    
for(new 0g_iTotalItemsi++)
    {
        
ArrayGetArray(g_aItemsieItemData)
        
        
formatex(szItemcharsmax(szItem), "%s - \y%i Credits"eItemData[ItemName], eItemData[ItemCost])
        
        
num_to_str(iszNumcharsmax(szNum))
        
        
bZombieReq eItemData[ItemTeam] == true false
            
        
if(bZombieReq && ZEV2_IsUserZombie(id))
            if(
g_iCredits[id] >= eItemData[ItemCost])
                
menu_additem(menuszItemszNum0)
            else
                
menu_additem(menuszItemszNum1<<31)
        else if(!
bZombieReq && !ZEV2_IsUserZombie(id))
            if(
g_iCredits[id] >= eItemData[ItemCost])
                
menu_additem(menuszItemszNum0)
            else
                
menu_additem(menuszItemszNum1<<31)
    }    
    
    
menu_display(idmenuiPage)
}

public 
CreditShop_handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
iAccessszNum[3], hCallback;
    
menu_item_getinfo(menuitemiAccessszNumcharsmax(szNum), __hCallback)
    
menu_destroy(menu)
    
    
// get item index from menu
    
new iItemIndex str_to_num(szNum)
    
    new 
eItemData[ItemData]
    
ArrayGetArray(g_aItemsiItemIndexeItemData)
    
    
g_iCredits[id] -= eItemData[ItemCost]
    
    
callfunc_begin_i(eItemData[ItemFuncID], eItemData[ItemPlugin])
    
callfunc_push_int(id)
    
callfunc_end()
    
    return 
PLUGIN_HANDLED
}

public 
Native_GetItemId(const text[])
{
    new 
eItemData[ItemData]
    
    for(new 
0g_iTotalItemsi++)
    {
        if(
equali(texteItemData[ItemName[i]])
        return -
1
    
}


Would this do??

PHP Code:

public Native_GetItemId(const text[])
{
    new 
eItemData[ItemData]
    
    for(new 
0g_iTotalItemsi++)
    {
        if(
equali(texteItemData[ItemName[i]])
        return -
1
    
}


I will register native after i know that the function should work good.

Celena Luna 10-22-2020 02:52

Re: Help Scripting
 
wait, why return -1?
you want to return the ID, not say "it is invalid"

Also eItemData[ItemData] is empty, you won't find anything from it

AnimalMonster 10-23-2020 13:39

Re: Help Scripting
 
Quote:

Originally Posted by Celena Luna (Post 2722149)
wait, why return -1?
you want to return the ID, not say "it is invalid"

Also eItemData[ItemData] is empty, you won't find anything from it

thx for telling but i moved on from trying because it s hard since i never tried before and my logic is null in this and all i did there i tried to copy from zombie plague that had arrays, also new in arrays.
not to say that this plugin doesn t use arrays that are saved into a ini file.

Anyways, i moved on zombie plague since i found out how to do what wanted there.

AnimalMonster 10-23-2020 13:42

Re: Help Scripting
 
Quote:

Originally Posted by Celena Luna (Post 2722149)
wait, why return -1?
you want to return the ID, not say "it is invalid"

Also eItemData[ItemData] is empty, you won't find anything from it

Also if you can show me how you would have done this in my place.


All times are GMT -4. The time now is 13:44.

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