First of all, if we want to have a thinker, we need to make the thinker (duh). So let's do that:
Code: Select all
class myThinker : Thinker
{
}
And God said, "Let there be a thinker": And there was a thinker.
Code: Select all
class myThinker: Thinker
{
}
class actorshitorsomething : actor
{
//blah blah blah actor stuff
void createThinker()
{
myThinker t = new("myThinker");
}
}
The thinker isn't doing much right now, and never will if we don't give it something that it can manipulate. So here, let's give it an actor pointer. First, we'll need to give the thinker an actor variable, and then we need to hand that variable an actor pointer. There's various ways of getting one of these, so i'm not going to go in to detail.
Code: Select all
class myThinker: Thinker
{
actor a;
}
class actorshitorsomething : actor
{
//blah blah blah actor stuff
void createThinker()
{
myThinker t = new("myThinker");
t.a = actorPointer;
}
}
We can hand our thinker more values this way - for example, if we defined an int in the thinker called "myInteger" and did something like "t.myInteger = 4;", then our thinker would get 4 assigned to myInteger.
Let's make a thinker that causes the actor to spawn health bonuses when it dies, depending on how much health it has! Let's start by creating and setting some values to help control the spawns.
Code: Select all
class myThinker: Thinker
{
actor a;
bool hasDied;
override void PostBeginPlay()
{
super.PostBeginPlay();
hasDied = false;
}
}
class actorshitorsomething : actor
{
//blah blah blah actor stuff
void createThinker()
{
myThinker t = new("myThinker");
t.a = actorPointer;
}
}
"override void PostBeginPlay()" overrides the original PostBeginPlay() function. PostBeginPlay() is a function that executes exactly once after the actor is created - so it's great for initializing variables. Basically, what overriding this does is make it so that the thinker does what we define in there instead of what PostBeginPlay() did in the class it inherited from - in this case, PostBeginPlay() did nothing useful. "super.PostBeginPlay()" executes what the class it inherited from does in PostBeginPlay() - it's nothing in this case, but putting this in anyway is probably a good practice. Why didn't we do this in createThinker()? It's totally possible, but I personally like to give the thinker the bare minimum in the part where it's being created. It's up to you what you want to do though.
Now let's move on to actually checking if the actor is dead.
Code: Select all
class myThinker: Thinker
{
actor a;
bool hasDied;
override void PostBeginPlay()
{
super.PostBeginPlay();
hasDied = false;
}
override void Tick()
{
super.Tick();
if (a != null)
{
if (a.health <= 0 && !hasDied)
{
hasDied = true;
}
}
}
class actorshitorsomething : actor
{
//blah blah blah actor stuff
myThinker t = new("myThinker");
t.a = actorPointer;
}
Code: Select all
class myThinker: Thinker
{
actor a;
bool hasDied;
override void PostBeginPlay()
{
super.PostBeginPlay();
hasDied = false;
}
override void Tick()
{
super.Tick();
if (a != null)
{
if (a.health <= 0 && !hasDied)
{
hasDied = true;
int spawnTimes = a.SpawnHealth() / 10;
for (int i = 0; i < spawnTimes; i++)
{
a.A_SpawnItemEx("HealthBonus", 0, 0, 0, random(-3, 3), random(-3, 3), random(0, 3));
}
}
}
}
class actorshitorsomething : actor
{
//blah blah blah actor stuff
myThinker t = new("myThinker");
t.a = actorPointer;
}
And that should be the basics of thinkers!