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

Dynamic items


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tousif
AlliedModders Donor
Join Date: Nov 2014
Location: India
Old 05-03-2016 , 06:25   Dynamic items
Reply With Quote #1

I've read this https://forums.alliedmods.net/showthread.php?t=123445 tutorial regarding dynamic items . How can we show shop for different team ? T and CT ? .
Any help didnt find anything like that in that tutorial .

Last edited by tousif; 08-20-2016 at 00:25.
tousif is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 07-24-2016 , 01:59   Re: Dynamic items
Reply With Quote #2

On the 'public _item_add( iPlugin, iParams )' function declaration, you need to receive 4 paramenters instead of 3. Note, '( iPlugin, iParams )' are not the parameters. The parameters I am talking about are those you get with 'get_param(1)'.

The new parameter will the the CS_TEAM's constants on which you are adding the item. Them you can add different itens for CT and T, handling on the this function to which team you are adding items.
On that function, when you add a item, it goes to the global Array 'g_aItems'. Now you will have to create more 1 global Array, for the other team items, and add the items for that team to it.

Next step is to change the function 'ShowShopMenu( iPlayer, iPage )'. On it, you will the get user team by their id using 'cs_get_user_team(1)' function. And create the menu with the CT items, or with the TR items. Remember, the items are on the arrays you created on the last step.

Cs team use example:
Code:
    new CsTeams:currentTeam = cs_get_user_team( playerId );         if( currentTeam == CS_TEAM_CT )     {         ...     }     else if( currentTeam == CS_TEAM_T )     {         ...     }


Update:

Using a switch for the team selection seens to be more appropriate.
Code:
    switch( cs_get_user_team( playerId ) )     {         case CS_TEAM_CT:         {             ...         }         case CS_TEAM_T:         {             ...         }     }
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 07-24-2016 at 14:54. Reason: example
addons_zz is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 07-24-2016 , 05:48   Re: Dynamic items
Reply With Quote #3

Try this:
PHP Code:
enum _:ItemData
{
    
ItemName32 ],
    
ItemCost
}; 
>
PHP Code:
enum _:ItemData
{
    
ItemName32 ],
    
ItemCost,
    
ItemTeam
}; 
------------------------------
PHP Code:
public _item_addiPluginiParams )
{
    
// create an array to hold our item data
    
new eItemDataItemData ];
    
    
// get item name from function
    
get_string1eItemDataItemName ], charsmaxeItemDataItemName ] ) );
    
    
// get item cost from function
    
eItemDataItemCost ] = get_param);
    
    
// add item to array and increase size
    
ArrayPushArrayg_aItemseItemData );
    
g_iTotalItems++;
    
    
// return the index of this item in the array
    // this creates the unique item index
    
return ( g_iTotalItems );

>
PHP Code:
public _item_addiPluginiParams )
{
    
// create an array to hold our item data
    
new eItemDataItemData ];
    
    
// get item name from function
    
get_string1eItemDataItemName ], charsmaxeItemDataItemName ] ) );
    
    
// get item cost from function
    
eItemDataItemCost ] = get_param);

    
// get item team from function
    
eItemDataItemTeam ] = clampget_param), 0);
    
    
// add item to array and increase size
    
ArrayPushArrayg_aItemseItemData );
    
g_iTotalItems++;
    
    
// return the index of this item in the array
    // this creates the unique item index
    
return ( g_iTotalItems );

------------------------------
PHP Code:
  for( new 0g_iTotalItemsi++ )
    {
        
// get item data from array
        
ArrayGetArrayg_aItemsieItemData );
        
        
// format item for menu
        
formatexszItemcharsmaxszItem ), "%s\R\y%i"eItemDataItemName ], eItemDataItemCost ] );
        
        
// pass array index to menu to find information about it later
        
num_to_striszNumcharsmaxszNum ) );
        
        
// add item to menu
        
menu_additemhMenuszItemszNum );
    } 
>
PHP Code:
  for( new 0g_iTotalItemsi++ )
    {
        
// get item data from array
        
ArrayGetArrayg_aItemsieItemData );
       
        if(
eItemDataItemTeam ] && (eItemDataItemTeam ] != cs_get_user_team(iPlayer)))
            continue;

        
// format item for menu
        
formatexszItemcharsmaxszItem ), "%s\R\y%i"eItemDataItemName ], eItemDataItemCost ] );
        
        
// pass array index to menu to find information about it later
        
num_to_striszNumcharsmaxszNum ) );
        
        
// add item to menu
        
menu_additemhMenuszItemszNum );
    } 
In .inc file:
PHP Code:
shop_item_add( const szName[ ], const iCost ); 
>
PHP Code:
shop_item_add( const szName[ ], const iCost, const iTeam ); // 0 = Both teams, 1 = Terrorist, 2 = Counter-Terrorist 

Last edited by KiLLeR.; 07-24-2016 at 06:38.
KiLLeR. is offline
tousif
AlliedModders Donor
Join Date: Nov 2014
Location: India
Old 07-24-2016 , 06:06   Re: Dynamic items
Reply With Quote #4

Thanks for the help . Will try it .
tousif is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 07-24-2016 , 06:39   Re: Dynamic items
Reply With Quote #5

The above code is updated, because i forgot to add options for both teams.
KiLLeR. 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 08:49.


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