Start weapon randomizer for multiplayer

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

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!)
User avatar
nakkemake
Posts: 237
Joined: Fri Apr 24, 2015 3:31 am
Location: ┌П┐(▀̿Ĺ̯▀̿ ̿)

Start weapon randomizer for multiplayer

Post by nakkemake »

I'm looking for making randomizer for equipped startup weapons. How to do? I have no idea.
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him

Re: Start weapon randomizer for multiplayer

Post by Caligari87 »

There's two ways, broadly speaking. The first is to define a new player class, and have it start with some kind of dummy CustomInventory item that gives/takes weapons and equipment as needed. The second, more flexable method, involves using ACS or (preferably) ZScript to define a script that runs when the player enters the map, and adjust inventory accordingly.

For example, this is a ZScript event handler I wrote for my mod, which gives the player several inventory items needed for my hunger tracking system (as well as an "marker/flag" inventory item to make sure it only runs once).

Code: Select all

class HungerInitialized : Inventory {}

class HDScav_Hunger_Bootstrap : EventHandler {
	//initialize additional player inventory
	override void PlayerEntered(PlayerEvent e) {
		PlayerInfo player = players[e.PlayerNumber];
		if(!player.mo.countinv("HungerInitialized")) {
			player.mo.giveinventory("HDScav_HungerTracker", 1);
			player.mo.giveinventory("HDScav_MessKit", 1);
			player.mo.giveinventory("HDScav_Ration", 3);
			player.mo.giveinventory("HungerInitialized", 1);
		}
	}
}
You can use the same principle to add/remove unwanted inventory according to a random selection.

8-)
User avatar
nakkemake
Posts: 237
Joined: Fri Apr 24, 2015 3:31 am
Location: ┌П┐(▀̿Ĺ̯▀̿ ̿)

Re: Start weapon randomizer for multiplayer

Post by nakkemake »

Nice!

May I ask whats the syntax for random in Zcript?
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him

Re: Start weapon randomizer for multiplayer

Post by Caligari87 »

Much like ACS. You can do something like --

Code: Select all

if(random(0,1) == 1) {
    giveinventory("myweapon", 1);
}
--for a 50% chance to do the action. This is a simplified example of course.

Return to “Scripting”