Page 1 of 1

Custom Weapon Pickup Sounds

PostPosted: Wed Apr 18, 12 6:32 am
by SimonDenton
Hey fellow coders,

I am simply overriding the DeusExPlayer function HandleItemPickup so that whenever we pick up an inventory item under SummerInventory master class, one of three set sounds will be played. In SummerInventory is simply the variables for the three pickup sounds. It seems this function cannot access the variables of whatever item under this inventory master class that is picked up in order to play the right sound.

Code: Select all
// ----------------------------------------------------------------------
// HandleItemPickup()
// ----------------------------------------------------------------------

function bool HandleItemPickup(Actor FrobTarget, optional bool bSearchOnly)
{

local float rand;

rand = FRand();


   if   (FrobTarget.IsA('SummerInventory'))
   {
   if(rand < 0.33)
   {
         PlaySound(FrobTarget.Inventory.SummerInventory.pickupSound1, SLOT_Interact, 0.5+FRand()*0.25, , 256, 0.95+FRand()*0.1);
     }   
   
    if(rand < 0.66)
   {
         PlaySound(FrobTarget.Inventory.SummerInventory.pickupSound2, SLOT_Interact, 0.5+FRand()*0.25, , 256, 0.95+FRand()*0.1);
     }   
   
    else
         PlaySound(FrobTarget.Inventory.SummerInventory.pickupSound3, SLOT_Interact, 0.5+FRand()*0.25, , 256, 0.95+FRand()*0.1);
   
   DoFrob(Self, inHand);
}
}


The error I have the moment is: Unrecognized member 'SummerInventory' in class 'Inventory' despite SummerInventory expanding Inventory.

Thanks for the helpout :D

PostPosted: Wed Apr 18, 12 7:38 am
by Alex
Try this
Code: Select all
// ----------------------------------------------------------------------
// HandleItemPickup()
// ----------------------------------------------------------------------

function bool HandleItemPickup(Actor FrobTarget, optional bool bSearchOnly)
{
  local float rand;
  local SummerInventory frobInventory;

  rand = FRand();
  frobInventory = SummerInventory(FrobTarget);

  if(frobInventory != None)
  {
    if(rand < 0.33)
      PlaySound(frobInventory.pickupSound1, SLOT_Interact, 0.5+FRand()*0.25, , 256, 0.95+FRand()*0.1);
    else if(rand < 0.66)
      PlaySound(frobInventory.pickupSound2, SLOT_Interact, 0.5+FRand()*0.25, , 256, 0.95+FRand()*0.1);
    else
      PlaySound(frobInventory.pickupSound3, SLOT_Interact, 0.5+FRand()*0.25, , 256, 0.95+FRand()*0.1);

    DoFrob(Self, inHand);
  }
}

PostPosted: Thu Apr 19, 12 6:58 am
by SimonDenton
Thanks Alex! Works like a charm :D Lesson to learn is when customising a function to override we should introduce variables and call them during functions.