Page 1 of 1

Start weapon randomizer for multiplayer

Posted: Mon Jul 16, 2018 6:31 am
by nakkemake
I'm looking for making randomizer for equipped startup weapons. How to do? I have no idea.

Re: Start weapon randomizer for multiplayer

Posted: Mon Jul 16, 2018 6:57 am
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-)

Re: Start weapon randomizer for multiplayer

Posted: Mon Jul 16, 2018 9:58 am
by nakkemake
Nice!

May I ask whats the syntax for random in Zcript?

Re: Start weapon randomizer for multiplayer

Posted: Mon Jul 16, 2018 11:02 am
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.