I need to do other things similar to this, but this is the most important.
How would I do this? I need it to happen to all monsters, hopefully also including monsters spawned in through scripts.
*EDIT: Specifically, I want it to affect any thing with the ISMONSTER flag.
Multiply monster Health based on amount of players
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
-
- Posts: 5043
- Joined: Sun Nov 14, 2010 12:59 am
Re: Multiply monster Health based on amount of players
One way to do it is with a [wiki=Events_and_handlers#WorldThingSpawned]WorldThingSpawned[/wiki] event (yes, this is ZScript):
Here's a demo:
https://www.dropbox.com/s/2y2szjshpya8g ... p.pk3?dl=1
Code: Select all
class AdjustHealthEvent : EventHandler
{
// Returns how many players are currently in the game.
private int CountPlayers ()
{
int count = 0;
for (int i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i])
{
count++;
}
}
return count;
}
override void WorldThingSpawned (WorldEvent e)
{
// On spawn, adjust a monster's health depending on the number of players.
if (e.Thing.bIsMonster)
{
e.Thing.health *= CountPlayers();
}
}
}
https://www.dropbox.com/s/2y2szjshpya8g ... p.pk3?dl=1
Re: Multiply monster Health based on amount of players
Does the file with that code in it have to be named zscript.txt? The page for Zscript on the zdoom wiki says I should rename it to avoid conflict.
Also, what it looks like it is doing is multiplying the monster health by the number of players. How would I make it be a smaller multiplier, like only 1.2x per player?
Also, what it looks like it is doing is multiplying the monster health by the number of players. How would I make it be a smaller multiplier, like only 1.2x per player?
-
- Posts: 5043
- Joined: Sun Nov 14, 2010 12:59 am
Re: Multiply monster Health based on amount of players
Just like DECORATE, ZScript is cumulative, which means you can have multiple ZScript lumps without them conflicting with each other.Mini--Joe wrote:Does the file with that code in it have to be named zscript.txt? The page for Zscript on the zdoom wiki says I should rename it to avoid conflict.
Would this do?Also, what it looks like it is doing is multiplying the monster health by the number of players. How would I make it be a smaller multiplier, like only 1.2x per player?
Code: Select all
override void WorldThingSpawned (WorldEvent e)
{
if (e.Thing.bIsMonster)
{
int pcount = CountPlayers();
// For every additional player in the game, add 20% to the monster's health.
if (--pcount > 0)
{
int adjusted_hp = e.Thing.health + int(e.Thing.health * pcount * 0.2);
// Make sure the adjusted health is greater than zero before setting it.
if (adjusted_hp > 0)
{
e.Thing.health = adjusted_hp;
}
}
}
}
Re: Multiply monster Health based on amount of players
Where do I place that?
If i put it after the AdjustHealthEvent, I just get the error "Unexpected 'override' Expecting end of file or 'include' or 'extend' or 'class' or 'struct' or 'const' or 'enum'".
If i put it after the AdjustHealthEvent, I just get the error "Unexpected 'override' Expecting end of file or 'include' or 'extend' or 'class' or 'struct' or 'const' or 'enum'".
-
- Posts: 5043
- Joined: Sun Nov 14, 2010 12:59 am
Re: Multiply monster Health based on amount of players
Check the demo file. It should replace the same function in there.
Re: Multiply monster Health based on amount of players
Ok I figured out the problem, I placed it in the wrong spot; I am not knowledgeable with scripting at all. Thanks for your help, it makes this experience so much better.