ItsMods

Full Version: Random Weapon Help?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all, I am in the process of creating a mod called Shotgun Battle. I want the players to start out with a different shotgun each time. But whenever I use my mod and test it in combat training, it doesn't give me, (or the bots) any weapon at all. Here are the essential parts of my code:
Code:
onPlayerSpawned()
{
    self endon("disconnect");

    for(;;)
    {
        self waittill("spawned_player");
        self thread doSpawnStuff();
            
        if(!isdefined(self.hud_rankscroreupdate))
        {
            self.hud_rankscroreupdate = NewScoreHudElem(self);
            self.hud_rankscroreupdate.horzAlign = "center";
            self.hud_rankscroreupdate.vertAlign = "middle";
            self.hud_rankscroreupdate.alignX = "center";
            self.hud_rankscroreupdate.alignY = "middle";
             self.hud_rankscroreupdate.x = 0;
            if( self IsSplitscreen() )
                self.hud_rankscroreupdate.y = -15;
            else
                self.hud_rankscroreupdate.y = -60;
            self.hud_rankscroreupdate.font = "default";
            self.hud_rankscroreupdate.fontscale = 2.0;
            self.hud_rankscroreupdate.archived = false;
            self.hud_rankscroreupdate.color = (0.3,0.3,0.3);
            self.hud_rankscroreupdate.alpha = 0;
            self.hud_rankscroreupdate maps\mp\gametypes\_hud::fontPulseInit();
            self.hud_rankscroreupdate.overrridewhenindemo = true;
        }
    }
}

doSpawnStuff()
{
    self takeAllWeapons();
    self clearPerks();
    self setPerk( "specialty_Lightweight" );
    self setPerk( "specialty_sleightofhand" );
    self setPerk( "specialty_unlimitedsprint" );
    self thread giveRandomWeapon();
}

giveRandomWeapon()
{
    weaponList = [];
    weaponList[weaponList.size] = "spas12_mp";
    weaponList[weaponList.size] = "olympia_mp";
    weaponList[weaponList.size] = "stakeout_mp";
    weaponList[weaponList.size] = "hs10_mp";
    
    weapon = weaponList[randomInt( weaponList.size )];
    self giveWeapon(weaponList);
    self switchToWeapon(weaponList);
}

If all else fails, I have attached the .gsc file to this post. Please help! Big Grin

1.
Stakeout - ithaca_mp
Olympia - rottweil72_mp

2.
Check the code where you copied this from.
Change:

PHP Code:
weapon weaponList[randomIntweaponList.size )];
self giveWeapon(weaponList);
self switchToWeapon(weaponList); 

to:

PHP Code:
weapon weaponList[randomIntweaponList.size )];
self giveWeapon(weapon);
self switchToWeapon(weapon); 

Before, you were giving the player the weapons array, not the weapon you got from the array.
soething like:

Code:
self.trololo = RandomInt( -number of weapon amount - 1(because of 0))

switch(self.trololo)
{

case 0: bla bla

case 1: bla bla

and then put that function on onplayerspawned. then they get every spawn a diffrent weapon : )
Thanks Guys! You solved it! Big Grin