[Tutorial] Creating a Basic Mutator

  • 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/

FluX

Grizzled Veteran
Oct 26, 2010
5,395
234
63
www.fluxiserver.co.uk
Right now i've probably tested this, it's not going how I wanted it to go...For some reason it still will give players health even when the level is above 4 (5 and above).

Code:
class RegenMut extends Mutator;
function PostBeginPlay()
{
 SetTimer(1, true);
}
function Timer()
{
  local KFHumanPawn Player;
      local KFPlayerReplicationInfo KFPRI;
  
 if (KFPRI.ClientVeteranSkillLevel <=4)
   foreach DynamicActors(class 'KFHumanPawn', Player)
   {
    if (Player.Health + 2 <= Player.HealthMax)
    
    (Player).Health += 2;
    
    else 
    
     Player.Health = Player.HealthMax;
     }
 else return;
}
defaultproperties
{
    GroupName="KFRegenMutator"
    FriendlyName="KF Health Regeneration"
    Description="Mutator that regenerates health depending on perk level."
}

How can I make it so it only regenerates the health of players under level 5?
 

Benjamin

Grizzled Veteran
May 17, 2009
3,650
635
113
France
Right now i've probably tested this, it's not going how I wanted it to go...For some reason it still will give players health even when the level is above 4 (5 and above).

Code:
class RegenMut extends Mutator;
function PostBeginPlay()
{
 SetTimer(1, true);
}
function Timer()
{
  local KFHumanPawn Player;
      local KFPlayerReplicationInfo KFPRI;
  
 if (KFPRI.ClientVeteranSkillLevel <=4)
   foreach DynamicActors(class 'KFHumanPawn', Player)
   {
    if (Player.Health + 2 <= Player.HealthMax)
    
    (Player).Health += 2;
    
    else 
    
     Player.Health = Player.HealthMax;
     }
 else return;
}
defaultproperties
{
    GroupName="KFRegenMutator"
    FriendlyName="KF Health Regeneration"
    Description="Mutator that regenerates health depending on perk level."
}

How can I make it so it only regenerates the health of players under level 5?

It doesn't work because you're not pointing KFPRI to anything, it's just an empty reference. You need to set it something like this:

Code:
KFPRI = KFPlayerReplicationInfo(Player.PlayerReplicationInfo);

And of course put the IF condition inside the loop.
 

FluX

Grizzled Veteran
Oct 26, 2010
5,395
234
63
www.fluxiserver.co.uk
Sorry as you can tell im rather new to this all.

Code:
class RegenMut extends Mutator;
function PostBeginPlay()
{
 SetTimer(1, true);
}
function Timer()
{
  local KFHumanPawn Player;
      local KFPlayerReplicationInfo KFPRI;
  
  foreach DynamicActors(class 'KFHumanPawn', Player)
  {
    KFPRI = KFPlayerReplicationInfo(Player.PlayerReplicationInfo);
   if (Player.Health + 2 <= Player.HealthMax && KFPRI.ClientVeteranSkillLevel <=4)
    
   Player.Health += 2;
    
   else 
    
    Player.Health = Player.HealthMax;
   }
}
defaultproperties
{
    GroupName="KFRegenMutator"
    FriendlyName="KF Health Regeneration"
    Description="Mutator that regenerates health depending on perk level."
}

Not sure if I did what you said to do correctly but this seems to give me max health when I get damaged.
 

Benjamin

Grizzled Veteran
May 17, 2009
3,650
635
113
France
You need a seperate IF statement which first determines the level of the player, like this:

Code:
class RegenMut extends Mutator;

function PostBeginPlay()
{
	SetTimer(1, true);
}

function Timer()
{
	local KFHumanPawn Player;
	local KFPlayerReplicationInfo KFPRI;

	foreach DynamicActors(class 'KFHumanPawn', Player)
	{
		KFPRI = KFPlayerReplicationInfo(Player.PlayerReplicationInfo);
		if (KFPRI.ClientVeteranSkillLevel <= 4)
		{
			if (Player.Health + 2 <= Player.HealthMax)
				Player.Health += 2;
			else
				Player.Health = Player.HealthMax;
		}
	}
}

defaultproperties
{
	GroupName="KFRegenMutator"
	FriendlyName="KF Health Regeneration"
	Description="Mutator that regenerates health depending on perk level."
}
 

Benjamin

Grizzled Veteran
May 17, 2009
3,650
635
113
France
Thanks a lot, works perfectly. Would be better if I spaced my code out more.

It does help readability if you space out sections properly and add good indentation and comments where necessary. Not just for you but others that read it. :)
 

FluX

Grizzled Veteran
Oct 26, 2010
5,395
234
63
www.fluxiserver.co.uk
Right im trying to make a ammo mutator that gives you an ammo box every 5 minutes BUT i've come to a halt due to an error.

Code:
class AmmoMut extends Mutator;
function PostBeginPlay()
{
 SetTimer(300, true);
}
function Timer()
{
    local Pawn P;
 
 {
  P.GiveWeapon("KFMod.KFAmmoPickup");
  Pawn.ClientMessage ("You have been given an ammo box!");
  Log("Ammo Given!");
  return;
 }
}
defaultproperties
{
 GroupName="KFAmmoMutator"
 FriendlyName="KF Timed Ammo Giver Mutator"
 Description="Mutator after every 5 minutes, gives you an ammo box."
}

It wont compile with the error:
Code:
{13} : Error, '{': Bad command or expression

I've tried to use my last mutator (health regeneration) to help figure out what is the problem but I can't see it. Also how would I check to see what wave the current wave is on to make it activate as I can not find a mutator or anything that checks the current wave number.
 

Trololololololololololo

FNG / Fresh Meat
May 6, 2010
110
35
0
Right im trying to make a ammo mutator that gives you an ammo box every 5 minutes BUT i've come to a halt due to an error.

Code:
class AmmoMut extends Mutator;
function PostBeginPlay()
[B](and maybe there should a empty line here spacing)[/B]
{
 SetTimer(300, true);
}
function Timer()
{
    local Pawn P;
 
 [B]{[/B][B] (mayb it should be } or shouldnt be here either one)[/B]
  P.GiveWeapon("KFMod.KFAmmoPickup");
  Pawn.ClientMessage ("You have been given an ammo box!");
  Log("Ammo Given!");
  return;
 }
}
defaultproperties
{
 GroupName="KFAmmoMutator"
 FriendlyName="KF Timed Ammo Giver Mutator"
 Description="Mutator after every 5 minutes, gives you an ammo box."
}

It wont compile with the error:
Code:
{13} : Error, '{': Bad command or expression

I've tried to use my last mutator (health regeneration) to help figure out what is the problem but I can't see it. Also how would I check to see what wave the current wave is on to make it activate as I can not find a mutator or anything that checks the current wave number.

I dont know anything yet due to retardation but that two would be my two guess.
 
Last edited:

Excalibolg

FNG / Fresh Meat
May 3, 2009
142
27
0
KF-BioticsLab
What are you doing in that timer?

PHP:
function Timer()
{
    local Pawn P;
 
  !!!!!!!!!{!!!!!!!!
  P.GiveWeapon("KFMod.KFAmmoPickup");
  Pawn.ClientMessage ("You have been given an ammo box!");
  Log("Ammo Given!");
  return;
  !!!!!!!!!!}!!!!!!
}
Remove the brackets.

Also giving ammo boxes is kind of band.
Rather get a weapons MagCapacity and increase its ammo by that.


Edit: And I just now actually read the code and noticed that this will not work at all. I hope you know what's missing though :>
 
Last edited:

FluX

Grizzled Veteran
Oct 26, 2010
5,395
234
63
www.fluxiserver.co.uk
Change it to:
Code:
class AmmoMut extends Mutator;
function PostBeginPlay()
{
 SetTimer(300, true);
}
function Timer()
{
    local Pawn P;
 
  P.GiveWeapon("KFMod.KFAmmoPickup");
  P.ClientMessage ("You have been given an ammo box!");
  Log("Ammo Given!");
  return;
}
defaultproperties
{
 GroupName="KFAmmoMutator"
 FriendlyName="KF Timed Ammo Giver Mutator"
 Description="Mutator after every 5 minutes, gives you an ammo box."
}

But it wont work. It's because i've used "GiveItem". Can't figure it out but doesn't help i've used the AdminPlus mutator to try get this to work.
 
Last edited:

FluX

Grizzled Veteran
Oct 26, 2010
5,395
234
63
www.fluxiserver.co.uk
How to call function in a function?

How to call function in a function?

He,y right im trying to get this working again but im looking at some of the weapon mutators as a base.

Here's my code:
Code:
class AmmoMut extends Mutator;
function PostBeginPlay()
{
 SetTimer(300, true);
}
function Timer()
{ 
 [I][COLOR=yellow]Want to call my ModifyPlayer function here
[/COLOR][/I] Player.ClientMessage ("You have been given an ammo box!");
 Log("Ammo Given!");
}
function ModifyPlayer(Pawn Player)
{
     Super.ModifyPlayer(Player);
     Player.GiveWeapon("KFMod.KFAmmoPickup");
}
defaultproperties
{
 GroupName="KFAmmoMutator"
 FriendlyName="KF Timed Ammo Giver Mutator"
 Description="Mutator after every 5 minutes, gives you an ammo box."
}

How could I add my function inside the timer? Also at the moment im getting the error:
Error, 'Player': Bad command or expression
Why is this?

Probably a newb question but to learn I rather do then read etc. It actually makes me remember better.
 

Excalibolg

FNG / Fresh Meat
May 3, 2009
142
27
0
KF-BioticsLab
Player isn't some magic variable that references each player on the map. You actually need to loop through all player actors and call ModifyPlayer on them. Refer to the code examples above in this thread, where this is done. Somehow this was lost in the progress :S
 

FluX

Grizzled Veteran
Oct 26, 2010
5,395
234
63
www.fluxiserver.co.uk
Player isn't some magic variable that references each player on the map. You actually need to loop through all player actors and call ModifyPlayer on them. Refer to the code examples above in this thread, where this is done. Somehow this was lost in the progress :S

you mean by adding this section:
Code:
	local KFHumanPawn Player;
	local KFPlayerReplicationInfo KFPRI;

	foreach DynamicActors(class 'KFHumanPawn', Player)
	{
		KFPRI = KFPlayerReplicationInfo(Player.PlayerReplicationInfo);

Would I have to keep the ModifyPlayer as a seperate function, if so how I make it do the function?
 

FluX

Grizzled Veteran
Oct 26, 2010
5,395
234
63
www.fluxiserver.co.uk
Right I have now got it to be able to compile by having this:
Code:
class AmmoMut extends Mutator;
function PostBeginPlay()
{
 SetTimer(300, true);
}
function Timer()
{
 local KFHumanPawn Player;
 foreach DynamicActors(class 'KFHumanPawn', Player)
 {
  Player.GiveWeapon("KFMod.KFAmmoPickup");
  Player.ClientMessage ("You have been given an ammo box!");
  Log("Ammo Given!");
 }
}
defaultproperties
{
 GroupName="KFAmmoMutator"
 FriendlyName="KF Timed Ammo Giver Mutator"
 Description="Mutator after every 5 minutes, gives you an ammo box."
}

The only problem I have now is that it wont actually give the players the ammo box. I know this is atleast working through the rest of the code cause the player gets the client message.

I have noticed I get this message spamming my log:
Code:
Warning: KFGameType KF-FluXiDefence.KFGameType (Function KFmod.KFGameType.MatchInProgress.SetupPickups:023F) Accessed None 'AmmoPickups'
Error: KFGameType KF-FluXiDefence.KFGameType (Function KFmod.KFGameType.MatchInProgress.SetupPickups:023F) Accessed array 'AmmoPickups' out of bounds (0/0)

and after that I get the
Code:
ScriptLog: Ammo Given!
ScriptLog: Ammo Given!
ScriptLog: Ammo Given!
ScriptLog: Ammo Given!

Can someone help me please?
 

Excalibolg

FNG / Fresh Meat
May 3, 2009
142
27
0
KF-BioticsLab
Does that message only appear with your mut on? Try disabling it and then check your log. Some maps get that if they don't have ammo spawns I think. Then we can safely say if it's an error with your mut or the map

also I'd suggest not giving the players the ammo boxes and instead just running the KFAmmoPickup.uc code in your mut
 
Last edited:

FluX

Grizzled Veteran
Oct 26, 2010
5,395
234
63
www.fluxiserver.co.uk
Does that message only appear with your mut on? Try disabling it and then check your log. Some maps get that if they don't have ammo spawns I think. Then we can safely say if it's an error with your mut or the map

also I'd suggest not giving the players the ammo boxes and instead just running the KFAmmoPickup.uc code in your mut

For some reason im getting an error:
AmmoMut.uc(50) : Error, Bad or missing expression in 'If'

Code:
function Timer()
{
 local KFHumanPawn Player;
 
 foreach DynamicActors(class 'KFHumanPawn', Player)
 {
  if (WaveNum >= 6) && (NumPlayers >= 8)
  {
   GiveAmmo(Player);
   Player.ClientMessage ("You have been given an ammo box!");
   Player.PlaySound( Sound'KF_InventorySnd.Ammo_GenericPickup',,1.0,,600.f);
  }
  else return;
 }
}

Tried many things but all saying same error.
 

braindead

FNG / Fresh Meat
Aug 22, 2009
918
346
0
Merry Ol' England
Code:
class AmmoMut extends Mutator;

var  KFGameReplicationInfo   KFGRI;

function PostBeginPlay() 
{  
SetTimer(300, true); 
} 

function Timer()
{
 local KFHumanPawn Player;
 
 foreach DynamicActors(class 'KFHumanPawn', Player)
 {
  if (KFGRI.WaveNum >= 6) && (Level.game.NumPlayers >= 8)
  {
   GiveAmmo(Player);
   Player.ClientMessage ("You have been given an ammo box!");
   Player.PlaySound( Sound'KF_InventorySnd.Ammo_GenericPickup',,1.0,,600.f);
  }
  else return;
 }
}


however without testing I am not sure whether the KFGRI should be local or var? try both


hope it helps
 
Last edited:

FluX

Grizzled Veteran
Oct 26, 2010
5,395
234
63
www.fluxiserver.co.uk
Code:
class AmmoMut extends Mutator;
 
var  KFGameReplicationInfo   KFGRI;
 
function PostBeginPlay() 
{  
SetTimer(300, true); 
} 
 
function Timer()
{
 local KFHumanPawn Player;
 
 foreach DynamicActors(class 'KFHumanPawn', Player)
 {
  if (KFGRI.WaveNum >= 6) && (Level.game.NumPlayers >= 8)
  {
   GiveAmmo(Player);
   Player.ClientMessage ("You have been given an ammo box!");
   Player.PlaySound( Sound'KF_InventorySnd.Ammo_GenericPickup',,1.0,,600.f);
  }
  else return;
 }
}


however without testing I am not sure whether the KFGRI should be local or var? try both


hope it helps

Both version show an error of:
Code:
Unrecognized member 'WaveNum' in class 'KFGameReplicationInfo'