ItsMods

Full Version: How to store a weapon so you spawn with it?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
setspawnweapon didnt seem to work? does it work and i just done it wrong or?

is there a way to do it with a variable?
The function works. It probably doesn't work because _class.gsc::giveLoadout() overwrites it. Try to use the giveLoadout() function to give weapons

edit: In _globallogic_spawn:ConfusedpawnPlayer() giveloadout get's called. Try to edit that...
could you give an example of how giveloadout works? ive never heard of it before & cant find crap on google Big Grin
Code:
giveLoadout( team, class )
{
        self takeAllWeapons();
        
        /*
        if ( level.splitscreen )
                primaryIndex = 0;
        else
                primaryIndex = self.pers["primary"];
        */
        
        primaryIndex = 0;
        
        // initialize specialty array
        self.specialty = [];

        primaryWeapon = undefined;
        
        // ============= custom class selected ==============
        if( isSubstr( class, "CLASS_CUSTOM" ) )
        {      
                // gets custom class data from stat bytes
                self cac_getdata();
        
                // obtains the custom class number
                class_num = int( class[class.size-1] )-1;
                self.class_num = class_num;
                
                assertex( isdefined( self.custom_class[class_num]["primary"] ), "Custom class "+class_num+": primary weapon setting missing" );
                assertex( isdefined( self.custom_class[class_num]["secondary"] ), "Custom class "+class_num+": secondary weapon setting missing" );
                assertex( isdefined( self.custom_class[class_num]["specialty1"] ), "Custom class "+class_num+": specialty1 setting missing" );
                assertex( isdefined( self.custom_class[class_num]["specialty2"] ), "Custom class "+class_num+": specialty2 setting missing" );
                assertex( isdefined( self.custom_class[class_num]["specialty3"] ), "Custom class "+class_num+": specialty3 setting missing" );
                
                // clear of specialty slots, repopulate the current selected class' setup
                self reset_specialty_slots( class_num );
                self get_specialtydata( class_num, "specialty1" );
                self get_specialtydata( class_num, "specialty2" );
                self get_specialtydata( class_num, "specialty3" );
                
                // set re-register perks to code
                self register_perks();
                // at this stage, the specialties are loaded into the correct weapon slots, and special slots
                
                // weapon override for round based gametypes
                // TODO: if they switched to a sidearm, we shouldn't give them that as their primary!
                if ( isDefined( self.pers["weapon"] ) && self.pers["weapon"] != "none" )
                        weapon = self.pers["weapon"];
                else
                        weapon = self.custom_class[class_num]["primary"];
                
                sidearm = self.custom_class[class_num]["secondary"];

                self GiveWeapon( sidearm );
                if ( self cac_hasSpecialty( "specialty_extraammo" ) )
                        self giveMaxAmmo( sidearm );
                        
                // give primary weapon
                primaryWeapon = weapon;
                
                assertex( isdefined( self.custom_class[class_num]["camo_num"] ), "Player's camo skin is not defined, it should be at least initialized to 0" );

                primaryTokens = strtok( primaryWeapon, "_" );
                self.pers["primaryWeapon"] = primaryTokens[0];
                
                self maps\mp\gametypes\_teams::playerModelForWeapon( self.pers["primaryWeapon"] );
                
                self GiveWeapon( weapon, self.custom_class[class_num]["camo_num"] );
                if ( self cac_hasSpecialty( "specialty_extraammo" ) )
                        self giveMaxAmmo( weapon );
                self setSpawnWeapon( weapon );
                
                // give secondary weapon
                
                self SetActionSlot( 1, "nightvision" );
                
                secondaryWeapon = self.custom_class[class_num]["inventory"];
                if ( secondaryWeapon != "" )
                {
                        self GiveWeapon( secondaryWeapon );
                        
                        self setWeaponAmmoOverall( secondaryWeapon, self.custom_class[class_num]["inventory_count"] );
                        
                        self SetActionSlot( 3, "weapon", secondaryWeapon );
                        self SetActionSlot( 4, "" );
                }
                else
                {
                        self SetActionSlot( 3, "altMode" );
                        self SetActionSlot( 4, "" );
                }
                
                // give frag for all no matter what
                grenadeTypePrimary = self.custom_class[class_num]["grenades"];
                if ( grenadeTypePrimary != "" )
                {
                        grenadeCount = self.custom_class[class_num]["grenades_count"];
        
                        self GiveWeapon( grenadeTypePrimary );
                        self SetWeaponAmmoClip( grenadeTypePrimary, grenadeCount );
                        self SwitchToOffhand( grenadeTypePrimary );
                }
                
                // give special grenade
                grenadeTypeSecondary = self.custom_class[class_num]["specialgrenades"];
                if ( grenadeTypeSecondary != "" )
                {
                        grenadeCount = self.custom_class[class_num]["specialgrenades_count"];
        
                        if ( grenadeTypeSecondary == level.weapons["flash"])
                                self setOffhandSecondaryClass("flash");
                        else
                                self setOffhandSecondaryClass("smoke");
                        
                        self giveWeapon( grenadeTypeSecondary );
                        self SetWeaponAmmoClip( grenadeTypeSecondary, grenadeCount );
                }
                
                self thread logClassChoice( class, primaryWeapon, grenadeTypeSecondary, self.specialty );
        }
        else
        {      
                // ============= selected one of the default classes ==============
                                
                // load the selected default class's specialties
                assertex( isdefined(self.pers["class"]), "Player during spawn and loadout got no class!" );
                selected_class = self.pers["class"];
                specialty_size = level.default_perk[selected_class].size;
                
                for( i = 0; i < specialty_size; i++ )
                {
                        if( isdefined( level.default_perk[selected_class][i] ) && level.default_perk[selected_class][i] != "" )
                                self.specialty[self.specialty.size] = level.default_perk[selected_class][i];
                }
                assertex( isdefined( self.specialty ) && self.specialty.size > 0, "Default class: " + self.pers["class"] + " is missing specialties " );
                
                // re-registering perks to code since perks are cleared after respawn in case if players switch classes
                self register_perks();
                
                // weapon override for round based gametypes
                // TODO: if they switched to a sidearm, we shouldn't give them that as their primary!
                if ( isDefined( self.pers["weapon"] ) && self.pers["weapon"] != "none" )
                        weapon = self.pers["weapon"];
                else
                        weapon = level.classWeapons[team][class][primaryIndex];
                
                sidearm = level.classSidearm[team][class];
                
                self GiveWeapon( sidearm );
                if ( self cac_hasSpecialty( "specialty_extraammo" ) )
                        self giveMaxAmmo( sidearm );

                // give primary weapon
                primaryWeapon = weapon;

                primaryTokens = strtok( primaryWeapon, "_" );
                self.pers["primaryWeapon"] = primaryTokens[0];
                
                if ( self.pers["primaryWeapon"] == "m14" )
                        self.pers["primaryWeapon"] = "m21";
        
                self maps\mp\gametypes\_teams::playerModelForWeapon( self.pers["primaryWeapon"] );              

                self GiveWeapon( weapon );
                if( self cac_hasSpecialty( "specialty_extraammo" ) )
                        self giveMaxAmmo( weapon );
                self setSpawnWeapon( weapon );
                
                // give secondary weapon
                self SetActionSlot( 1, "nightvision" );
        
                secondaryWeapon = level.classItem[team][class]["type"];
                if ( secondaryWeapon != "" )
                {
                        self GiveWeapon( secondaryWeapon );
                        
                        self setWeaponAmmoOverall( secondaryWeapon, level.classItem[team][class]["count"] );
                        
                        self SetActionSlot( 3, "weapon", secondaryWeapon );
                        self SetActionSlot( 4, "" );
                }
                else
                {
                        self SetActionSlot( 3, "altMode" );
                        self SetActionSlot( 4, "" );
                }
                
                grenadeTypePrimary = level.classGrenades[class]["primary"]["type"];
                if ( grenadeTypePrimary != "" )
                {
                        grenadeCount = level.classGrenades[class]["primary"]["count"];
        
                        self GiveWeapon( grenadeTypePrimary );
                        self SetWeaponAmmoClip( grenadeTypePrimary, grenadeCount );
                        self SwitchToOffhand( grenadeTypePrimary );
                }
                
                grenadeTypeSecondary = level.classGrenades[class]["secondary"]["type"];
                if ( grenadeTypeSecondary != "" )
                {
                        grenadeCount = level.classGrenades[class]["secondary"]["count"];
        
                        if ( grenadeTypeSecondary == level.weapons["flash"])
                                self setOffhandSecondaryClass("flash");
                        else
                                self setOffhandSecondaryClass("smoke");
                        
                        self giveWeapon( grenadeTypeSecondary );
                        self SetWeaponAmmoClip( grenadeTypeSecondary, grenadeCount );
                }

                self thread logClassChoice( class, primaryWeapon, grenadeTypeSecondary, self.specialty );
        }

        switch ( weaponClass( primaryWeapon ) )
        {
                case "rifle":
                        self setMoveSpeedScale( 0.95 );
                        break;
                case "pistol":
                        self setMoveSpeedScale( 1.0 );
                        break;
                case "mg":
                        self setMoveSpeedScale( 0.875 );
                        break;
                case "smg":
                        self setMoveSpeedScale( 1.0 );
                        break;
                case "spread":
                        self setMoveSpeedScale( 1.0 );
                        break;
                default:
                        self setMoveSpeedScale( 1.0 );
                        break;
        }
        
        // cac specialties that require loop threads
        self cac_selector();
}
i meant to store a premade class, i already read that, thanks for melting my head again though.

im guna be here a week :x




could i just set the guns selected to a variable when selected then have them given to me on spawn after a second or something? and give an example?


soz sorta new to this, only been modding a week.
You can edit classes in the Private Match settings, so you can also edit them with GSC files. I remember Eekhoorn used this for his early cmMOD versions.
i got it working with variables, thanks guys.
ok i ran into a problem, when i save the variable like this in the menu

if( response == "give_asp" )
{
self thread takepistols();
self giveWeapon( "asp_mp" );
self switchToWeapon( "asp_mp" );
level.pistol = "asp_mp";
}


then on spawn i have...

if( level.pistol != undefined) {
self thread takepistols();
self giveweapon( level.pistol );
self switchtoweapon( level.pistol );
}

It seems to only store it if i die, like run off and kill myself, though, if the round switches in SND the variable is no longer stored, why is that?
else if( response == "give_asp" )
{
self thread takepistols();
self giveWeapon( "asp_mp" );
self switchToWeapon( "asp_mp" );
self.pers["mod_pistol"] = "asp_mp";
}

then use
Code:
self giveWeapon( self.pers["mod_pistol"] );
thanks.. ill try it out..
If it doesn't work, then try this:

Code:
game["mod_pistol"] = "asp_mp";

Otherwise

Code:
setDvar( "mod_pistol", "asp_mp" );

Code:
self giveWeapon( getDvar( "mod_pistol" ) );
Pages: 1 2