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

Solved How to return multiple values and apply conditionals for all possible combinations?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
PatriotGames
AlliedModders Donor
Join Date: Feb 2012
Location: root@irs:/# rm -rf /
Old 02-12-2019 , 16:56   How to return multiple values and apply conditionals for all possible combinations?
Reply With Quote #1

My plugin needs to check a survivor's primary weapon, if they have one, for any upgrades (laser, incendiary ammo or explosive ammo) and then decide if an upgrade should be given or not.
Peace-Maker posted some code that I modified to find the current upgrades, if any, and return a value that corresponds to the appropriate cvar values for the same upgrades.

There are two challenges at this point:

1. The GetUpgradeType function successfully determines the client's primary weapon upgrades, but it needs to return multiple values and I'm not sure how best to handle it.
2. Because there are five unique non-repeating combinations of possible upgrades (incendiary and explosive ammo are mutually exclusive) the logic to check them for regular and vip players gets a little complicated.

The code below works for one upgrade, but not more. I understand why but am not sure where to go from here. Seems like an array is needed but my array experience is limited:

Note: Survivors are handled individually based on player_spawn event, so this codes runs for one client at a time.

PHP Code:
#define L4D2_WEPUPGFLAG_NONE            (0 << 0)
#define L4D2_WEPUPGFLAG_INCENDIARY      (1 << 0)
#define L4D2_WEPUPGFLAG_EXPLOSIVE       (1 << 1)
#define L4D2_WEPUPGFLAG_LASER           (1 << 2)

g_cvUpgradeChoice CreateConVar("l4d2_sis_upgrade_choice""0""Give an Upgrade to the survivors? 0=disable, 1=laser, 2=incendiary ammo, 3=explosive ammo"FCVAR_NOTIFY);
g_cvRandomUpgrade CreateConVar("l4d2_sis_random_upgrade""0""Give a random Upgrade item to the survivors? Overrides previous upgrade settings. 0=disable, 1=enable."FCVAR_NOTIFY);
g_cvVipUpgradeChoice CreateConVar("l4d2_sis_vip_upgrade_choice""0""Give an Upgrade to the VIPs? Overrides ALL other upgrade settings. 0=disable, 1=laser, 2=incendiary ammo, 3=explosive ammo"FCVAR_NOTIFY);


/* =============  Upgrade Item  ============= */
        
        
if (g_cvUpgradeChoice.IntValue || g_cvRandomUpgrade.BoolValue || g_cvVipUpgradeChoice.IntValue 0// check that at least one upgrade cvar is > 0
        
{
            
int iEntPrimaryWeapon GetPlayerWeaponSlot(clientview_as<int>(L4D2WeaponSlot_Primary)); // check for a primary weapon
            
if (iEntPrimaryWeapon == -&& !IsValidEntity(iEntPrimaryWeapon))
            {
                return; 
// client doesn't have a primary weapon, so no upgrade is given.
            
}
            else 
// client has a primary weapon.
            
{
                
int iExistingUpgrade GetUpgradeType(client); // what is the existing upgrade, if any?  Need to return and manage multiple values here!
                
if (iExistingUpgrade != 0//client has an upgrade. Should they receive another?
                
{
                    if (
bIsVip && g_cvVipUpgradeChoice.IntValue && g_cvVipUpgradeChoice.IntValue != iExistingUpgrade //check for vip/admin status and the vip upgrade cvar
                    
{
                        
SelectUpgrade(clientbIsVip);
                    }
                    else if (
g_cvUpgradeChoice.IntValue && g_cvUpgradeChoice.IntValue != iExistingUpgrade// client is not vip, check for base upgrade cvar.
                    
{
                        
SelectUpgrade(clientbIsVip);
                    }
                }
                else 
// client does not have an existing upgrade. Should they receive one?
                
{
                    if (
bIsVip && g_cvVipUpgradeChoice.IntValue 0// check vip/admin status and vip upgrade cvar.
                    
{
                        
SelectUpgrade(clientbIsVip);
                    }
                    else if (
g_cvUpgradeChoice.IntValue 0// client is not vip, check base upgrade cvar.
                    
{
                        
SelectUpgrade(clientbIsVip);
                    }
                }
            }
        }
        
        
stock int GetUpgradeType(int client)
{
    
int iEntPrimaryWeapon GetPlayerWeaponSlot(clientview_as<int>(L4D2WeaponSlot_Primary));
    if (
iEntPrimaryWeapon != -&& IsValidEdict(iEntPrimaryWeapon) && HasEntProp(iEntPrimaryWeaponProp_Send"m_upgradeBitVec")) // check if client has a valid primary weapon with an upgrade(s)
    
{
        
int iUpgradeType GetEntProp(iEntPrimaryWeaponProp_Send"m_upgradeBitVec"); // get the upgrade type
        
if (iUpgradeType L4D2_WEPUPGFLAG_LASER)
        {
            return 
1// laser upgrade cvar value
        
}
        else if (
iUpgradeType L4D2_WEPUPGFLAG_INCENDIARY)
        {
            return 
2// indendiary upgrade cvar value 
        
}
        else if (
iUpgradeType L4D2_WEPUPGFLAG_EXPLOSIVE)
        {
            return 
3// explosive upgrade cvar value 
        
}
    }
    return 
0// no upgrades

Appreciate any help,
PG

Last edited by PatriotGames; 02-15-2019 at 17:08. Reason: Update status to solved.
PatriotGames is offline
 



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 15:23.


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