AlliedModders

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

tousif 05-03-2016 06:25

Dynamic items
 
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 .

addons_zz 07-24-2016 01:59

Re: Dynamic items
 
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:         {             ...         }     }

KiLLeR. 07-24-2016 05:48

Re: Dynamic items
 
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 


tousif 07-24-2016 06:06

Re: Dynamic items
 
Thanks :) for the help . Will try it .

KiLLeR. 07-24-2016 06:39

Re: Dynamic items
 
The above code is updated, because i forgot to add options for both teams.


All times are GMT -4. The time now is 18:33.

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