Neo-Kamek

AssetReplacer sample

May 22nd, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Asset Replacer
  3. //
  4. // This is a sample Workshop mod based off of P2GameMod.
  5. // Feel free to copy this code and use it as a basis for your own game mods.
  6. //
  7. // This is a mod that reads in a list of textures and sounds in the default
  8. // properties, and attempts to replace them in-game wherever possible.
  9. //
  10. // Limitations:
  11. // * BSP surfaces can't be messed with. If you want to change the texture on
  12. //   a wall, rebuild the map and include it with your mod.
  13. // * Dialog won't be replaced. Script a new dialog class and assign it to
  14. //   the desired pawns.
  15. // * Some classes change materials or sounds on the fly; this mod won't change
  16. //   those.
  17. // * Certain specific sounds or skins won't be replaced, you'll have to change
  18. //   them manually.
  19. ///////////////////////////////////////////////////////////////////////////////
  20. class AssetReplacer extends P2GameMod;
  21.  
  22. struct MaterialReplaceStruct {
  23.     var() Material OldMaterial, NewMaterial;
  24. };
  25.  
  26. struct SoundReplaceStruct {
  27.     var() Sound OldSound, NewSound;
  28. };
  29.  
  30. var() array<MaterialReplaceStruct> MaterialReplace;
  31. var() array<SoundReplaceStruct> SoundReplace;
  32.  
  33. ///////////////////////////////////////////////////////////////////////////////
  34. // ReplaceMaterial
  35. // Attempts to replace passed-in material
  36. ///////////////////////////////////////////////////////////////////////////////
  37. function Material ReplaceMaterial(Material ReplaceMe)
  38. {
  39.     local int i;
  40.    
  41.     for (i = 0; i < MaterialReplace.Length; i++)
  42.     {
  43.         if (ReplaceMe == MaterialReplace[i].OldMaterial)
  44.             return MaterialReplace[i].NewMaterial;
  45.     }
  46.    
  47.     return None;
  48. }
  49.  
  50. ///////////////////////////////////////////////////////////////////////////////
  51. // ReplaceSound
  52. // Attempts to replace passed-in sound
  53. ///////////////////////////////////////////////////////////////////////////////
  54. function Sound ReplaceSound(Sound ReplaceMe)
  55. {
  56.     local int i;
  57.    
  58.     for (i = 0; i < SoundReplace.Length; i++)
  59.     {
  60.         if (ReplaceMe == SoundReplace[i].OldSound)
  61.             return SoundReplace[i].NewSound;
  62.     }
  63.    
  64.     return None;
  65. }
  66.  
  67. ///////////////////////////////////////////////////////////////////////////////
  68. // ParseActor
  69. // Looks to replace any textures, sounds on new actor
  70. ///////////////////////////////////////////////////////////////////////////////
  71. function ParseActor(Actor Other)
  72. {
  73.     local int i, j;
  74.     local Material NewMaterial;
  75.     local Sound NewSound;
  76.     local Name NewName;
  77.    
  78.     if (Other == None)
  79.         return;
  80.    
  81.     // Try Actor skins and sounds
  82.     for (i = 0; i < Other.Skins.Length; i++)
  83.     {
  84.         NewMaterial = ReplaceMaterial(Other.Skins[i]);
  85.         if (NewMaterial != None)
  86.             Other.Skins[i] = NewMaterial;
  87.     }
  88.     NewMaterial = ReplaceMaterial(Other.Texture);
  89.     if (NewMaterial != None)
  90.         Other.Texture = NewMaterial;
  91.     NewSound = ReplaceSound(Other.AmbientSound);
  92.     if (NewSound != None)
  93.         Other.AmbientSound = NewSound;
  94.        
  95.     // Emitters.
  96.     if (Emitter(Other) != None)
  97.     {
  98.         for (i = 0; i < Emitter(Other).Emitters.Length; i++)
  99.         {
  100.             NewMaterial = ReplaceMaterial(Emitter(Other).Emitters[i].Texture);
  101.             if (Texture(NewMaterial) != None)
  102.                 Emitter(Other).Emitters[i].Texture = Texture(NewMaterial);
  103.         }
  104.     }
  105.    
  106.     // Sound Things
  107.     if (SoundThing(Other) != None)
  108.     {
  109.         for (i = 0; i < SoundThing(Other).Settings.Sounds.Length; i++)
  110.         {
  111.             NewSound = ReplaceSound(SoundThing(Other).Settings.Sounds[i]);
  112.             if (NewSound != None)
  113.                 SoundThing(Other).Settings.Sounds[i] = NewSound;
  114.         }
  115.     }
  116.    
  117.     // Pistol.
  118.     if (PistolWeapon(Other) != None)
  119.     {
  120.         NewSound = ReplaceSound(PistolWeapon(Other).FireSound);
  121.         if (NewSound != None)
  122.             PistolWeapon(Other).FireSound = NewSound;
  123.     }
  124. }
  125.  
  126. ///////////////////////////////////////////////////////////////////////////////
  127. // CheckReplacement
  128. // This function is called for any actor spawned into the world.
  129. // You can use this function to change any default properties of that actor,
  130. // or replace it entirely with something else using ReplaceWith.
  131. // Return FALSE if you replace the actor or just want it to be destroyed.
  132. // Return TRUE if you want to keep the actor and don't want to replace it.
  133. // Unlike other functions you do NOT need to call Super here.
  134. ///////////////////////////////////////////////////////////////////////////////
  135. function bool CheckReplacement(Actor Other, out byte bSuperRelevant)
  136. {
  137.     ParseActor(Other);
  138.     return true;
  139. }
  140.  
  141. ///////////////////////////////////////////////////////////////////////////////
  142. // ModifyNPC
  143. // Called by PersonController/AnimalController after adding default inventory.
  144. // Use this function to alter any aspect of the NPC you like.
  145. // At this point the pawn's head and body are set, so we can change their skins
  146. // now!
  147. ///////////////////////////////////////////////////////////////////////////////
  148. function ModifyNPC(Pawn Other)
  149. {
  150.     local int i;
  151.     Super.ModifyNPC(Other);
  152.    
  153.     // Do both the body and head separately.
  154.     ParseActor(Other);
  155.     if (P2MocapPawn(Other) != None)
  156.     {
  157.         ParseActor(P2MocapPawn(Other).MyHead);
  158.         // And while we're at it get the boltons too
  159.         for (i = 0; i < P2MocapPawn(Other).MAX_BOLTONS; i++)
  160.             ParseActor(P2MocapPawn(Other).Boltons[i].part);
  161.     }
  162. }
  163.  
  164. ///////////////////////////////////////////////////////////////////////////////
  165. // Default properties required by all P2GameMods.
  166. ///////////////////////////////////////////////////////////////////////////////
  167. defaultproperties
  168. {
  169.     // GroupName - any Game Mods with the same GroupName will be considered incompatible, and only one will be allowed to run.
  170.     // Use this if you make mods that are not designed to run alongside each other.
  171.     GroupName=""
  172.     // FriendlyName - the name of your Game Mod, displayed in the game mod menu.
  173.     FriendlyName="Farting Pistol"
  174.     // Description - optional short description of your Game Mod
  175.     Description="Makes the pistol fart, hurr"
  176.    
  177.     SoundReplace[0]=(OldSound=Sound'WeaponSounds.pistol_fire',NewSound=Sound'AmbientSounds.fart4')
  178. }
Advertisement
Add Comment
Please, Sign In to add comment