• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Custom Weapon class help (typecasting)

Excalibolg

Grizzled Veteran
May 3, 2009
142
27
KF-BioticsLab
I added some new variables that should be used for all weapons. My custom weapons set these variables, but I need some place to store some defaults. For this purpose I though I could simply use a class that extends Weapon.

Code:
class CustomWeapon extends Weapon
    abstract;

var byte Foobar;

defaultproperties
{
}
Problem is: I can't typecast to this class.

Code:
if (Pawn.Weapon != None)
  if (CustomWeapon(Pawn.Weapon) != None)
     log("worked");
  else
     log("did not work");
else
  log("no pawn.weapon");
just fills my log with "did not work". I just can't put my finger on what I'm doing wrong :(
 
I see, how would I go about doing this then? My structure looks like this

Winchester -> CustomWinchester
Katana -> CustomKatana

and so on. Each of the custom classes has some variables and functions they share. Now when I need to access a Weapon at some point I obviously don't want to check "Is it a CustomWinchester? Access CustomWinchester(Weapon).Foobar. Is it a CustomKatana? Acess CustomKatana(Weapon).Foobar" etc. Is it possible to replace the underlying reference to Weapon with my CustomWeapon?

Any easy way out of this dilemma? :D


Edit: For now I just bit into the sour apple and copied all the weapon code over and changed the references (CustomWinchester -> CustomKFWeaponShotgun -> CustomKFWeapon etc)
 
Last edited:
Upvote 0