Jump to content
  • 0

Best way to detect a pistol start with ACS?


Nevander

Question

I was thinking, in many maps that are intended to be played continuous, often players will struggle or run into problems with pistol starts. Adding more things for pistol starts is great and all, but then it becomes too easy for continuous play.

 

So I was thinking of a solution: spawn specific items at specific places in the map using MapSpots and ACS. Except I only want them if the player is pistol starting.

 

What would be the best way to do this?

 

I was thinking to check against something like:

  • Having any other gun besides the pistol (since if you are pistol starting, you won't have anything else). Then if the script detects the player has a shotgun already at the first tic, it's not a pistol start. But it assumes every map after the first has a shotgun, and that the player will get one, but I suppose it's possible to not get a shotgun and end the map, so that's one possible error.
  • Check if health is 101 or higher. If the player has 101 or more at the first tic, it's also not a pistol start, however the player could end with 100 health but a bunch of everything else and that's an error.
  • Or if armor is 1 or higher. If the player has even 1 point of armor, it's not a pistol start. But also, once again, the player can end with 0 armor but everything else.

 

Can't do ammo because it's possible to end a map with 0 of each, and can't check for 100 health exactly because it's possible to end a map with exactly 100 health.

 

Or just check against every single possibility: if the player has any other gun OR the player has 101 or more health or less than 100 health OR the player has 1 or more armor OR checking all the ammo.

 

I just want the least error prone and simplest method. Ideas or suggestions for best method are most appreciated.

Share this post


Link to post

3 answers to this question

Recommended Posts

  • 0

I think rather than checking what equipment/health/armor the player has, a better approach would be to keep track of whether or not the player was alive prior to starting the current level. This way the script will still work as intended, even if the player happens to run the game with a mod that for example changes the starting equipment.

 

I think one way of keeping track of this, would be with a special inventory item, which would be used to check if the player survived the previous map. On entering the map, a script would check if the player has the item, if they do, it's NOT a pistol start. If they don't have it (the player died and lost the item), it IS a pistol start. After these checks, and whatever actions follow them, the script would give the player the special inventory item again, so that on the next map load, the script can properly check for pistol start again.

 

Decorate example:

Spoiler

ACTOR ExitItem : Inventory
{
  +INVENTORY.UNTOSSABLE
}

 

ACS example:

Spoiler

#include "zcommon.acs"

// Runs for each player when first entering the map
script "PlayerEnter" ENTER 
{
	if (CheckInventory("ExitItem") > 0)
	{
		//NOT A PISTOL START
		//Do nothing.
		Print(s:"Not a pistol start!");
	}
	else
	{
		//PISTOL START
		Print(s:"You pistol started!");
		GiveInventory("Shell", 20);
		
		ACS_NamedExecute("PistolStartEvent", 0, 0,0,0);
		
		// Give the player the ExitItem so that if they survive
		// to the next map, we can detect it by checking for this item.
		GiveInventory("ExitItem", 1);
	}
}

// Runs for each player when respawning in multiplayer
script "PlayerRespawn" RESPAWN
{
	// Treat respawning as a pistol start?
	GiveInventory("Shell", 20);
	
	// Give the player the ExitItem so that if they survive
	// to the next map, we can detect it by checking for this item.
	GiveInventory("ExitItem", 1);
}

bool bEventScriptExecuted = FALSE;
script "PistolStartEvent" (void)
{
	// Prevent the script from running more than once per map,
	// regardless of how many player ENTER scripts try to execute it.
	if (bEventScriptExecuted == TRUE) Terminate;
	
	bEventScriptExecuted = TRUE;
	PrintBold(s:"Pistol start event!");
	
	// Code that adjusts the MAP during pistol start
	Spawn("Cyberdemon", 0.0, 0.0, 0.0);
}

 

 

 

I guess another possible approach could be using global variables and both an OPEN and UNLOADING script to keep track if a map was exited prior to loading the current map.

Share this post


Link to post
  • 0

The item-based check should work also for other ways of resetting player inventory. I suppose one would have to try if it works with the automatic pistol start mods; there are at least two and I haven't checked how they work. If they just remove known weapons and ammo, reduce armor to 0, and set health back to 100, they wouldn't remove the exit item and thus create false negatives for that test.

Edited by Gez

Share this post


Link to post
  • 0
4 minutes ago, Gez said:

The item-based check should work also for other ways of resetting player inventory. I suppose one would have to try if it works with the automatic pistol start mods; there are at least two and I haven't checked how they work. If they just remove known weapons and ammo, reduce armor to 0, and set health back to 100, they wouldn't remove the exit item and thus create false negatives for that test.

That's true, if they happen to use ClearInventory or ClearActorInventory, and then supply the player with starting gear, then the exit item would also be removed since it does not have the INVENTORY.UNCLEARABLE flag set.

 

But now that I think about it, there is also the possiblity that another pistol start mod could break this script if it runs right after this, and calls ClearInventory/ClearActorInventory and then removes the exit item, that this script gives the player at the end of the ENTER script. It does depend on which ENTER script gets executed first, but perhaps there should be a short delay before giving the player the exit item, to reduce the chance of another mod removing it right as they spawn.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...