Modme Forums

Help with a section of a script

Game Modding | Call of Duty: Black Ops 3 | Scripting


Thread By: Wild
Hey, as some of you may or may not know from my last post, I have been learning to script. I have started my next few projects. The next project that I am started involves a random drop system, similar to how the Origins dig site have random drops. Basically what I am asking is in a script how to you make a list of items, have the script only choose one to spawn and have it be random and have the drop/item spawn at a specific point, for example at the origin of the trigger. I would assume for the list of items/drops you would use some sort of array I think and have the script pick 1 of them. So yeah, how do you set up the list, have one item randomly selected and then spawn at the origin of the trigger or a set point. Any help is appreciated! Thanks.


Reply By: Akrime
I'd do something like this. Remember, if you're going to copy & paste this code, you need to set the targetname for your trigger to "droptrigger". If you need to add more drops to the array, just add them behind "part_drop" and seperate them with a blank space like in the code or delete the previous items.

// Array & Variables
drops = strTok("grenade_falling_out weapon_drop part_drop "," ");
trigger GetEnt("droptrigger", "targetname");

// Hintstring
trigger setHintString("Press &&1 to get a random drop");

// Wait for the player to interact with the trigger
trigger waittill("trigger", player);

// Random picking
choosenDrop = array::random(drops);

// Then I'd do something like this
    case "grenade_falling_out":
    	// CODE: Do stuff, drop grenade from the drop etc..

	case "weapon_drop":
		// CODE: spawn a weapon powerup for the player to pick up etc..

	case "part_drop":
		// CODE: spawn the part for the player to pick up etc..

		IPrintLn("ERROR: No case for this variable!");