Modme Forums

How do I turn this script into a multiple use function?

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


ModmeBot:

Thread By: TrueGamerCalls
I'm working on a PUBG like looting system and was wondering how I can turn this script into a script that can be used several times.

I'm looking to being able to place as many trigger_use named "loot_spawned" as I want with each trigger_use having different weapons.

Note: This isn't the final script, its just something I made in 20min, judge me many.

function loot()
{
 loot_spawn = GetEnt("loot_spawn", "targetname");
 loot_array = array("ar_standard", "lmg_light", "ray_gun", "ar_damage");
 loot_select = array::random(loot_array);
 loot_weapon_world = GetWeaponWorldModel(GetWeapon(loot_select));
 loot_weapon_m = Spawn("script_model", loot_spawn.origin);
 loot_weapon_m SetModel(loot_weapon_world);
 loot_weapon_t = Spawn("trigger_use", loot_spawn.origin);
 loot_weapon_t = GetEnt("loot_weapon_t", "targetname");
 loot_weapon_t SetHintString("Hold ^3&&1 ^7To Take Weapon");
 loot_weapon_t SetCursorHint("HINT_NOICON");
 loot_weapon_t waittill("trigger", player); 
 oldWeapon = player GetCurrentWeapon();
 weapons = player GetWeaponsListPrimaries();
 if( weapons.size >= 2 )
 player TakeWeapon( oldWeapon );
 player GiveWeapon(GetWeapon(loot_select));
 player SwitchToWeapon(GetWeapon(loot_select)); 
 loot_weapon_t Hide();
}


ModmeBot:

Reply By: mathfag
How high were you when you did this

loot_weapon_t = Spawn("trigger_use", loot_spawn.origin);
 loot_weapon_t = GetEnt("loot_weapon_t", "targetname");

anyway...

I made a little something. It may work, it may not, I didn't really try to make something good. Basically every 60 seconds a gun spawns on a random struct and then what you wanted to do happens. You should probably look into how to not make 2 guns spawn on the same struct.
function spawn_loot()
{
loot_spawn = struct::get_array("loot_spawn", "targetname") //place structs where loot will spawn

while(1)
	{
	spawn_select = array::random(loot_spawn);
	spawn_select thread loot();
	while(60);
	}	
}

function loot() //self = spawn point
{
loot_array = array("ar_standard", "lmg_light", "ray_gun", "ar_damage");
loot_select = array::random(loot_array);
loot_weapon_world = GetWeaponWorldModel(GetWeapon(loot_select));
loot_weapon_m = Spawn("script_model", self.origin);
loot_weapon_m SetModel(loot_weapon_world);

loot_weapon_t = Spawn("trigger_radius_use", self.origin, 32, 32);

loot_weapon_t SetHintString("Hold ^3&&1 ^7To Take Weapon");
loot_weapon_t SetCursorHint("HINT_NOICON");
loot_weapon_t waittill("trigger", player); 

zm_weapons::weapon_give(GetWeapon(loot_select), is_upgrade = false, magic_box = false, nosound = false, b_switch_weapon = true); //edit this

loot_weapon_t Delete();
loot_weapon_m Delete();

/* skip all this
 oldWeapon = player GetCurrentWeapon();
 weapons = player GetWeaponsListPrimaries();
 if( weapons.size >= 2 )
 player TakeWeapon( oldWeapon );
 player GiveWeapon();
 player SwitchToWeapon(GetWeapon(loot_select)); 
 loot_weapon_t Hide();
*/
}

wait(60) in the first function


ModmeBot:

Reply By: Harry Bo21
you could edit the post you know...

also this doesnt check for last stand and other 'is_valid' stuff, and will allow guns to spawn on the same spot repeatedly potentially - and is missing some code to allow trigger_radius_use to actually display the hintstrings


ModmeBot:

Reply By: ihmiskeho
Did this pretty quickly. Seemed to work when I did a quick test, however.
Should not spawn multiple weapons on the same struct.

function loot_logic()
{
	level endon("end_game");

	n_loot_respawn = 60;		//Time until new loot respawns

	a_loot_spawn = struct::get_array( "loot_spawn", "targetname" );
	if(!isdefined(a_loot_spawn) || a_loot_spawn.size <= 0)		//Tells if you didn't place any structs or mispelled kvps
	{
		IPrintLnBold("No loot structs found");
		return;
	}

	while(1)
	{
		selected_loot = array::random(a_loot_spawn);
		if(IS_TRUE(selected_loot.loot_active))
		{
			WAIT_SERVER_FRAME;
			continue;
		}

		else 
		{
			selected_loot thread LootSpawnWeapon();
			wait(n_loot_respawn);
		}
	}
}

function LootSpawnWeapon()
{
	self.loot_active = true;	//Added so that multiple weapons can't spawn on one struct
	a_weapons = array( "ar_standard", "lmg_light", "ray_gun", "ar_damage" );
	selected_weapon = GetWeapon( array::random(a_weapons) );
	e_gun = Spawn("script_model", self.origin);
	e_gun SetModel(GetWeaponWorldModel( selected_weapon) );
	//trigger stuff
	t_loot = Spawn("trigger_radius", e_gun.origin, 0, 32, 32);
	t_loot SetHintString( "Hold ^3&&1 ^7To Take Weapon" );
	t_loot SetCursorHint( "HINT_NOICON" );
	while(1)
	{
		t_loot waittill("trigger", user);
		if(IsPlayer(user) && user UseButtonPressed())
		{
			if( user HasWeapon(GetWeapon("minigun") ) || user laststand::player_is_in_laststand() )
			{
				continue;
			}

			if( user HasWeapon( selected_weapon ))
			{
				user SwitchToWeapon( selected_weapon );
				user GiveMaxAmmo( selected_weapon );
				break;
			}

			else
			{
				user zm_weapons::weapon_give(selected_weapon);			//_zm_weapons.gsc, line 2603       function weapon_give( weapon, is_upgrade = false, magic_box = false, nosound = false, b_switch_weapon = true )
				break;

			}
		}
	}
	e_gun Delete();
	t_loot Delete();
	self.loot_active = false;
}
Just place as many script_structs (targetname = loot_spawn) around the map. Can also edit the respawn time

Let me know if there is any issues with this


ModmeBot:

Reply By: Harry Bo21
that actually looks pretty good


ModmeBot:

Reply By: TrueGamerCalls

ihmiskeho
Did this pretty quickly. Seemed to work when I did a quick test, however. Should not spawn multiple weapons on the same struct. function loot_logic() { level endon("end_game"); n_loot_respawn = 60; //Time until new loot respawns a_loot_spawn = struct::get_array( "loot_spawn", "targetname" ); if(!isdefined(a_loot_spawn) || a_loot_spawn.size <= 0) //Tells if you didn't place any structs or mispelled kvps { IPrintLnBold("No loot structs found"); return; } while(1) { selected_loot = array::random(a_loot_spawn); if(IS_TRUE(selected_loot.loot_active)) { WAIT_SERVER_FRAME; continue; } else { selected_loot thread LootSpawnWeapon(); wait(n_loot_respawn); } } } function LootSpawnWeapon() { self.loot_active = true; //Added so that multiple weapons can't spawn on one struct a_weapons = array( "ar_standard", "lmg_light", "ray_gun", "ar_damage" ); selected_weapon = GetWeapon( array::random(a_weapons) ); e_gun = Spawn("script_model", self.origin); e_gun SetModel(GetWeaponWorldModel( selected_weapon) ); //trigger stuff t_loot = Spawn("trigger_radius", e_gun.origin, 0, 32, 32); t_loot SetHintString( "Hold ^3&&1 ^7To Take Weapon" ); t_loot SetCursorHint( "HINT_NOICON" ); while(1) { t_loot waittill("trigger", user); if(IsPlayer(user) && user UseButtonPressed()) { if( user HasWeapon(GetWeapon("minigun") ) || user laststand::player_is_in_laststand() ) { continue; } if( user HasWeapon( selected_weapon )) { user SwitchToWeapon( selected_weapon ); user GiveMaxAmmo( selected_weapon ); break; } else { user zm_weapons::weapon_give(selected_weapon); //_zm_weapons.gsc, line 2603 function weapon_give( weapon, is_upgrade = false, magic_box = false, nosound = false, b_switch_weapon = true ) break; } } } e_gun Delete(); t_loot Delete(); self.loot_active = false; } Just place as many script_structs (targetname = loot_spawn) around the map. Can also edit the respawn time Let me know if there is any issues with this

This works amazingly, but I have one problem. How do I change this to only spawn a weapon once at a location?


ModmeBot:

Reply By: ihmiskeho

TrueGamerCalls
ihmiskeho Did this pretty quickly. Seemed to work when I did a quick test, however. Should not spawn multiple weapons on the same struct. function loot_logic() { level endon("end_game"); n_loot_respawn = 60; //Time until new loot respawns a_loot_spawn = struct::get_array( "loot_spawn", "targetname" ); if(!isdefined(a_loot_spawn) || a_loot_spawn.size <= 0) //Tells if you didn't place any structs or mispelled kvps { IPrintLnBold("No loot structs found"); return; } while(1) { selected_loot = array::random(a_loot_spawn); if(IS_TRUE(selected_loot.loot_active)) { WAIT_SERVER_FRAME; continue; } else { selected_loot thread LootSpawnWeapon(); wait(n_loot_respawn); } } } function LootSpawnWeapon() { self.loot_active = true; //Added so that multiple weapons can't spawn on one struct a_weapons = array( "ar_standard", "lmg_light", "ray_gun", "ar_damage" ); selected_weapon = GetWeapon( array::random(a_weapons) ); e_gun = Spawn("script_model", self.origin); e_gun SetModel(GetWeaponWorldModel( selected_weapon) ); //trigger stuff t_loot = Spawn("trigger_radius", e_gun.origin, 0, 32, 32); t_loot SetHintString( "Hold ^3&&1 ^7To Take Weapon" ); t_loot SetCursorHint( "HINT_NOICON" ); while(1) { t_loot waittill("trigger", user); if(IsPlayer(user) && user UseButtonPressed()) { if( user HasWeapon(GetWeapon("minigun") ) || user laststand::player_is_in_laststand() ) { continue; } if( user HasWeapon( selected_weapon )) { user SwitchToWeapon( selected_weapon ); user GiveMaxAmmo( selected_weapon ); break; } else { user zm_weapons::weapon_give(selected_weapon); //_zm_weapons.gsc, line 2603 function weapon_give( weapon, is_upgrade = false, magic_box = false, nosound = false, b_switch_weapon = true ) break; } } } e_gun Delete(); t_loot Delete(); self.loot_active = false; } Just place as many script_structs (targetname = loot_spawn) around the map. Can also edit the respawn time Let me know if there is any issues with this This works amazingly, but I have one problem. How do I change this to only spawn a weapon once at a location?

Sorry, I misread what you wanted. If you only want them to spawn once you could simply do this:
function loot_logic()
{
	a_loot_spawn = struct::get_array( "loot_spawn", "targetname" );
	if(!isdefined(a_loot_spawn) || a_loot_spawn.size &lt;= 0)		//Tells if you didn&#39;t place any structs or mispelled kvps
	{
		IPrintLnBold("No loot structs found");
		return;
	}
	foreach(struct in a_loot_spawn)
	{
		struct thread LootSpawnWeapon();
	}
}

function LootSpawnWeapon()
{
	a_weapons = array( "ar_standard", "lmg_light", "ray_gun", "ar_damage" );
	selected_weapon = GetWeapon( array::random(a_weapons) );
	e_gun = Spawn("script_model", self.origin);
	e_gun SetModel(GetWeaponWorldModel( selected_weapon) );
	//trigger stuff
	t_loot = Spawn("trigger_radius", e_gun.origin, 0, 32, 32);
	t_loot SetHintString( "Hold ^3&amp;&amp;1 ^7To Take Weapon" );
	t_loot SetCursorHint( "HINT_NOICON" );
	while(1)
	{
		t_loot waittill("trigger", user);
		if(IsPlayer(user) &amp;&amp; user UseButtonPressed())
		{
			if( user HasWeapon(GetWeapon("minigun") ) || user laststand::player_is_in_laststand() )
			{
				continue;
			}

			if( user HasWeapon( selected_weapon ))
			{
				user SwitchToWeapon( selected_weapon );
				user GiveMaxAmmo( selected_weapon );
				break;
			}

			else
			{
				user zm_weapons::weapon_give(selected_weapon);			//_zm_weapons.gsc, line 2603       function weapon_give( weapon, is_upgrade = false, magic_box = false, nosound = false, b_switch_weapon = true )
				break;

			}
		}
	}
	e_gun Delete();
	t_loot Delete();
}

This will spawn all weapons instantly and they wont respawn. If you want to have a delay between the spawns, you can add a wait in the foreach loop


ModmeBot:

Reply By: TrueGamerCalls

ihmiskeho
TrueGamerCalls ihmiskeho Did this pretty quickly. Seemed to work when I did a quick test, however. Should not spawn multiple weapons on the same struct. function loot_logic() { level endon("end_game"); n_loot_respawn = 60; //Time until new loot respawns a_loot_spawn = struct::get_array( "loot_spawn", "targetname" ); if(!isdefined(a_loot_spawn) || a_loot_spawn.size <= 0) //Tells if you didn't place any structs or mispelled kvps { IPrintLnBold("No loot structs found"); return; } while(1) { selected_loot = array::random(a_loot_spawn); if(IS_TRUE(selected_loot.loot_active)) { WAIT_SERVER_FRAME; continue; } else { selected_loot thread LootSpawnWeapon(); wait(n_loot_respawn); } } } function LootSpawnWeapon() { self.loot_active = true; //Added so that multiple weapons can't spawn on one struct a_weapons = array( "ar_standard", "lmg_light", "ray_gun", "ar_damage" ); selected_weapon = GetWeapon( array::random(a_weapons) ); e_gun = Spawn("script_model", self.origin); e_gun SetModel(GetWeaponWorldModel( selected_weapon) ); //trigger stuff t_loot = Spawn("trigger_radius", e_gun.origin, 0, 32, 32); t_loot SetHintString( "Hold ^3&&1 ^7To Take Weapon" ); t_loot SetCursorHint( "HINT_NOICON" ); while(1) { t_loot waittill("trigger", user); if(IsPlayer(user) && user UseButtonPressed()) { if( user HasWeapon(GetWeapon("minigun") ) || user laststand::player_is_in_laststand() ) { continue; } if( user HasWeapon( selected_weapon )) { user SwitchToWeapon( selected_weapon ); user GiveMaxAmmo( selected_weapon ); break; } else { user zm_weapons::weapon_give(selected_weapon); //_zm_weapons.gsc, line 2603 function weapon_give( weapon, is_upgrade = false, magic_box = false, nosound = false, b_switch_weapon = true ) break; } } } e_gun Delete(); t_loot Delete(); self.loot_active = false; } Just place as many script_structs (targetname = loot_spawn) around the map. Can also edit the respawn time Let me know if there is any issues with this This works amazingly, but I have one problem. How do I change this to only spawn a weapon once at a location? Sorry, I misread what you wanted. If you only want them to spawn once you could simply do this: function loot_logic() { a_loot_spawn = struct::get_array( "loot_spawn", "targetname" ); if(!isdefined(a_loot_spawn) || a_loot_spawn.size <= 0) //Tells if you didn't place any structs or mispelled kvps { IPrintLnBold("No loot structs found"); return; } foreach(struct in a_loot_spawn) { struct thread LootSpawnWeapon(); } } function LootSpawnWeapon() { a_weapons = array( "ar_standard", "lmg_light", "ray_gun", "ar_damage" ); selected_weapon = GetWeapon( array::random(a_weapons) ); e_gun = Spawn("script_model", self.origin); e_gun SetModel(GetWeaponWorldModel( selected_weapon) ); //trigger stuff t_loot = Spawn("trigger_radius", e_gun.origin, 0, 32, 32); t_loot SetHintString( "Hold ^3&&1 ^7To Take Weapon" ); t_loot SetCursorHint( "HINT_NOICON" ); while(1) { t_loot waittill("trigger", user); if(IsPlayer(user) && user UseButtonPressed()) { if( user HasWeapon(GetWeapon("minigun") ) || user laststand::player_is_in_laststand() ) { continue; } if( user HasWeapon( selected_weapon )) { user SwitchToWeapon( selected_weapon ); user GiveMaxAmmo( selected_weapon ); break; } else { user zm_weapons::weapon_give(selected_weapon); //_zm_weapons.gsc, line 2603 function weapon_give( weapon, is_upgrade = false, magic_box = false, nosound = false, b_switch_weapon = true ) break; } } } e_gun Delete(); t_loot Delete(); } This will spawn all weapons instantly and they wont respawn. If you want to have a delay between the spawns, you can add a wait in the foreach loop

This works perfectly, thanks!

Also don't be sorry, I should've been more clearer myself.