• 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 [Tutorial] Creating a Basic Mutator

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?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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."
}
 
Upvote 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()
{
 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.
 
Upvote 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:
Upvote 0
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:
Upvote 0
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:
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0
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?
 
Upvote 0
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:
Upvote 0
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.
 
Upvote 0
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:
Upvote 0
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'
 
Upvote 0