Modme Forums
Menu:

help random weapon wallbuy

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


ModmeBot:

Thread By: xdferpc
I want is a wallbuy that when buying a weapon give you a random weapon

I tried it but it does not work out

function wallbuy1()
{
	trigweapon = GetEnt("trigweapon", "targetname");
	trigweapon setHintString("press &&1 to buy random weapon (1500 points required )");
        trigweapon SetCursorHint("HINT_NOICON");
	rand_weapons = array( "smg_standard", "smg_versatile", "ar_standard", "ar_longburst" );
	while ( 1 )
	{
		trigweapon waittill("trigger", player);
		
		
                if(player.score >= 1500)
		{
			a_weapon = rand_weapons[ randomInt( rand_weapons.size ) ]; 
			player TakeWeapon( a_weapon );
                        player.score -= 1500;
			
	
		}
	}

}


ModmeBot:

Reply By: Abnormal202
I believe here:

player TakeWeapon( a_weapon );


you meant to use the GiveWeapon() function instead of the TakeWeapon() function, cause this would mean the script is looking for if the player has that random weapon and will try to take it from them, instead of give it to them.

so should be:
player GiveWeapon( a_weapon );


ModmeBot:

Reply By: xdferpc
thanks for the help
but it still does not give me the weapon . I don´t know


ModmeBot:

Reply By: Abnormal202

xdferpc
thanks for the help but it still does not give me the weapon . I don´t know

oh right I just remembered you have to get the actual weapon entity, instead of just the string for the weapon. You can do this using the GetWeapon() function. for example:

a_weapon_string = rand_weapons[ randomInt( rand_weapons.size ) ]; 
a_weapon = GetWeapon( a_weapon_string );
player GiveWeapon( a_weapon );

			
	
		
	


ModmeBot:

Reply By: Harry Bo21
you should be using


player zm_weapons::weapon_give( weapon, is_upgrade = false, magic_box = false, nosound = false, b_switch_weapon = true )


Lots of issues can occur if you dont handle them the other way, eg not taking your old weapon, not allowing for weapons that should / should not switch to automatically, mule kick not counting triggering the too many guns thing or monkeys not working, melees not being registered, grenades being added rather than replacing the current ones etc etc etc


ModmeBot:

Reply By: Abnormal202
yeah and probably also using this function:

player zm_score::minus_to_player_score( 1500 );


instead of
player.score -= 1500;


ModmeBot:

Reply By: Harry Bo21
also should check if the player already has the weapon it chooses or one of its variants, in those cases - choose another

and check if the player is valid ( eg downed etc )

if ( isPlayer( e_player ) || zm_utility::is_player_valid( e_player ) )


ModmeBot:

Reply By: xdferpc
I do not know where I have to put this

if ( isPlayer( e_player ) || zm_utility::is_player_valid( e_player ) )



UNRECOVERABLE ERROR:
^1SCRIPT ERROR: No generated data for 'scripts/zm/zm_test1.gsc'
ERR(0) scripts/zm/zm_test1.gsc (275,57) in "wallbuy1()" : syntax error, unexpected TOKEN_EQUALS, expecting TOKEN_RIGHT_PAREN : player zm_weapons::weapon_give( a_weapon, is_upgrade =


ModmeBot:

Reply By: Harry Bo21

player zm_weapons::weapon_give( weapon, is_upgrade = false, magic_box = false, nosound = false, b_switch_weapon = true )


is a example of what arguments you can set... dont copy paste it...

player zm_weapons::weapon_give( weapon, 0, 0, 0, 1 )