Raised This Month: $ Target: $400
 0% 

How to order items by price?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
colossus
Member
Join Date: Sep 2013
Old 09-14-2013 , 16:06   How to order items by price?
Reply With Quote #1

An example:


PHP Code:
show_menu_extras(id)
{
    if (!
is_user_alive(id))
        return;
    
    static 
menuidmenu[128], teambuffer[32]

    
formatex(menucharsmax(menu), "Items Menu")
    
menuid menu_create(menu"menu_extras")

    for (new 
0g_extraitem_ii++)
    {
        
formatex(menucharsmax(menu), "%s \r[Cost: %d]"bufferArrayGetCell(g_extraitem_costi))
        
buffer[0] = i
        buffer
[1] = 0
        menu_additem
(menuidmenubuffer)
    }

    if (
menu_items(menuid) <= 0)
    {
        
client_print(idprint_chat"No items in menu")
        
menu_destroy(menuid)
        return;
    }
    
    
// Back - Next - Exit
    
menu_setprop(menuidMPROP_BACKNAME"Back page")
    
menu_setprop(menuidMPROP_NEXTNAME"Next page")
    
menu_setprop(menuidMPROP_EXITNAME"Exit menu")
        
    
// If remembered page is greater than number of pages, clamp down the value
    
MENU_PAGE_EXTRAS min(MENU_PAGE_EXTRASmenu_pages(menuid)-1)
    
    
// Fix for AMXX custom menus
    
if (pev_valid(id) == PDATA_SAFE)
        
set_pdata_int(idOFFSET_CSMENUCODE0OFFSET_LINUX)
    
    
menu_display(idmenuidMENU_PAGE_EXTRAS)

This plugin what the zombie_plague40 kick and I need to know how to sort the items by price ...

PS: These items are added with a native ...

Example:

zp_register_extra_item ("Super Gun", 30, ZP_TEAM_HUMAN)
colossus is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-14-2013 , 16:54   Re: How to order items by price?
Reply With Quote #2

Since I'm guessing you have 2 dynamic arrays that stores name and cost ArraySort() is out of the question since it won't match the other array.

You could either make your own sorting function using ArraySwap on both arrays to keep them synced.
Another option is to create a new array that works like a key to both arrays and sort that using 1DCustom.

I can't write it for you since the function you supplied is missing the name array...

EDIT:
Here's the basics of the first method:
Code:
new size = ArraySize(hArray); for ( new i = 1 ; i < size ; i++ ) {     for ( new j = i ; j > 0 ; j-- ) {         if ( ArrayGetCell(hArray, j) < ArrayGetCell(hArray, j - 1) ) { // Use < for ascending and > for descending.             ArraySwap(hArray, j, j - 1);             ArraySwap(hStringArray, j, j - 1);         }         else             break;     } }
__________________

Last edited by Black Rose; 09-14-2013 at 18:11.
Black Rose 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 18:52.


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