Pawn and Controller relationship

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

artyom.anon

FNG / Fresh Meat
Aug 25, 2014
12
0
0
So, from some tutorials I figured out a way to change the PlayerControllerClass with your mod. I am trying to add an exec function that does something, and the way I think this is how people do it:

function postBeginPlay(){
level.Game.PlayerControllerClass = class'MyMutator.MyController';
}

and then in the MyController you can have some sort of exec function that can be called

class MyController extends PlayerController;

exec function MyFunction()
{
local KFHumanPawn p;
foreach DynamicActors(class 'KFHumanPawn', p){
p.Health = 50;
}
}

So, the way I have it written when MyFunction() is called it sets all players health to 50. Logically, there absolutely has to be a unique instance of PlayerController for each KFHumanPawn since
level.Game.PlayerControllerClass = class'MyMutator.MyController';
I would assume executes client side (so separate thread for each player), it makes perfect sense how each KFHumanPawn gets their own instance. Now, my question is how would I reference between the controller and the pawn that belong to me, and pass instance variables between those? Ultimately at this time I am trying to make it so that MyFunction() only sets MY health to 50.
 

artyom.anon

FNG / Fresh Meat
Aug 25, 2014
12
0
0
Also a follow up on previous question - can anyone point me in the right direction to find source code for KFHumanPawn?
 

Skell

Active member
Mar 21, 2013
1,242
2
38
On the Internet.
So, from some tutorials I figured out a way to change the PlayerControllerClass with your mod. I am trying to add an exec function that does something, and the way I think this is how people do it:

function postBeginPlay(){
level.Game.PlayerControllerClass = class'MyMutator.MyController';
}

and then in the MyController you can have some sort of exec function that can be called

class MyController extends PlayerController;

exec function MyFunction()
{
local KFHumanPawn p;
foreach DynamicActors(class 'KFHumanPawn', p){
p.Health = 50;
}
}

So, the way I have it written when MyFunction() is called it sets all players health to 50. Logically, there absolutely has to be a unique instance of PlayerController for each KFHumanPawn since
level.Game.PlayerControllerClass = class'MyMutator.MyController';
I would assume executes client side (so separate thread for each player), it makes perfect sense how each KFHumanPawn gets their own instance. Now, my question is how would I reference between the controller and the pawn that belong to me, and pass instance variables between those? Ultimately at this time I am trying to make it so that MyFunction() only sets MY health to 50.
You can call a controller's pawn class (the pawn it controls) by simply writing Pawn. For example:
Code:
[COLOR=Gray]var Weapon CurrentWeapon;[/COLOR]
[COLOR=Gray][...][/COLOR]
if(Pawn != None)
{
    CurrentWeapon = Pawn.Weapon;
}
This will get the Pawn's weapon.
Also a follow up on previous question - can anyone point me in the right direction to find source code for KFHumanPawn?
Decompile all scripts using the Killing Floor SDK. Go to the actor browser and click File > Export All Scripts. This will take a while. All packages in the EditPackages section of the KillingFloor.ini will be decompiled and placed into <package name>.Classes.
 

artyom.anon

FNG / Fresh Meat
Aug 25, 2014
12
0
0
Yeah, I just figured it out via trial and error. It threw me off that sometimes myController.Pawn references the instance, sometimes the class. Wierd .... I guess there's a certain degree of black magic here.

Thanks for the input however. Maybe you could help me with a new issue - how to use multiple timers in one class. Passing a third argument into setTimer() like some UT forums suggest causes a compile time error.
 

Skell

Active member
Mar 21, 2013
1,242
2
38
On the Internet.
Thanks for the input however. Maybe you could help me with a new issue - how to use multiple timers in one class. Passing a third argument into setTimer() like some UT forums suggest causes a compile time error.
Use Tick() with booleans for sections you want running. The Unreal Engine 2 does not support multiple timers. The SetTimer() function only calls the function Timer(). Most classes already use their allotted timer so it's best to avoid it anyways.