UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

How to give players their weapons back when they respawn?

broken avatar :(
Created 10 years ago
by jbird
0 Members and 1 Guest are viewing this topic.
1,935 views
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 years ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
×
jbird's Groups
I'm trying to give players their weapons back that they had before they downed after they respawn under a certain condition, but I can't seem to give players any weapons at all after they are spawned in.
Here is all the code I have for it:
(Keep in mind this is for BO1 not WAW)
_zombiemode.gsc
Code Snippet
Plaintext
checkForAllDead()
{
players = get_players();
count = 0;
for( i = 0; i < players.size; i++ )
{
if( !(players[i] maps\_laststand::player_is_in_laststand()) && !(players[i].sessionstate == "spectator") )
{
count++;
}
}

if( count==0 )
{
zombs = getaispeciesarray("axis");
for(i=0;i<zombs.size;i++)
{
zombs[i] delete(); //removes all currently spawned in zombies
}

//maps\_zombiemode_powerups::powerup_round_start(); //restarts the amount of powerups you can earn this round
//array_thread( players, maps\_zombiemode_blockers_new::rebuild_barrier_reward_reset ); //restarts your barrier points this round
level thread round_restart();

players = get_players();
for(i=0;i<players.size;i++)
{
players[i] thread spectator_respawn();
players[i] [[level.spawnPlayer]]();
while(1)
{
if(players[i] hasWeapon("m1911_zm"))
{
//iprintln("Found the weapon");
                                        wait_network_frame();
players[i] laststand_giveback_player_weapons();
if( isDefined( players[i].has_altmelee ) && players[i].has_altmelee )
{
players[i] SetPerk( "specialty_altmelee" );
}
level thread award_grenades_for_survivors(); //get 2 extra grenades when you spawn back in, optional
break;
}
wait(0.05);
}
}
iprintlnbold("You have been given another chance"); //message letting you know the round restarted, optional
}
}

laststand_giveback_player_weapons()
{
ASSERTEX( IsDefined( self.weaponInventory ), "player.weaponInventory is not defined - did you run laststand_take_player_weapons() first?" );

self TakeAllWeapons();

for( i = 0; i < self.weaponInventory.size; i++ )
{
weapon = self.weaponInventory[i];

switch( weapon )
{
// this player was killed while reviving another player
case "syrette":
// player was killed drinking perks-a-cola
case "zombie_perk_bottle_doubletap":
case "zombie_perk_bottle_revive":
case "zombie_perk_bottle_jugg":
case "zombie_perk_bottle_sleight":
case "zombie_bowie_flourish":
case "zombie_knuckle_crack":
continue;
}

self GiveWeapon( weapon );
self SetWeaponAmmoClip( weapon, self.weaponAmmo[weapon]["clip"] );

if ( WeaponType( weapon ) != "grenade" )
self SetWeaponAmmoStock( weapon, self.weaponAmmo[weapon]["stock"] );
}

// if we can't figure out what the last active weapon was, try to switch a primary weapon
//CHRIS_P: - don't try to give the player back the mortar_round weapon ( this is if the player killed himself with a mortar round)
if( self.lastActiveWeapon != "none" && self.lastActiveWeapon != "mortar_round" && self.lastActiveWeapon != "mine_bouncing_betty" )
{
self SwitchToWeapon( self.lastActiveWeapon );
}
else
{
primaryWeapons = self GetWeaponsListPrimaries();
if( IsDefined( primaryWeapons ) && primaryWeapons.size > 0 )
{
self SwitchToWeapon( primaryWeapons[0] );
}
}
}
_laststand.gsc
Code Snippet
Plaintext
PlayerLastStand( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration )
{
if( GetDvar( #"zombiemode" ) != "1" && sMeansOfDeath == "MOD_CRUSH" )
{
if( self player_is_in_laststand() )
{
self mission_failed_during_laststand( self );
}
return;
}
if( self player_is_in_laststand() )
{
return;
}

self.downs++;

self.stats["downs"] = self.downs;
dvarName = "player" + self GetEntityNumber() + "downs";
setdvar( dvarName, self.downs );

self AllowJump(false);

if( IsDefined( level.playerlaststand_func ) )
{
[[level.playerlaststand_func]]( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration );
}





if ( !laststand_allowed( sWeapon, sMeansOfDeath, sHitLoc ) )
{
self mission_failed_during_laststand( self );
return;
}

if ( player_all_players_in_laststand() )
{
self mission_failed_during_laststand( self );
return;
}

if ( GetDvar( #"zombiemode" ) == "1" )
{
self VisionSetLastStand( "zombie_last_stand", 1 );
}
else
{
self VisionSetLastStand( "laststand", 1 );
}

self.health = 1;

self thread laststand_bleedout( GetDvarFloat( #"player_lastStandBleedoutTime" ) );

self notify( "player_downed" );

self revive_trigger_spawn();

self laststand_take_player_weapons();

wait(0.05);

self laststand_disable_player_weapons();
//self laststand_give_pistol();

self.ignoreme = true;
}

laststand_take_player_weapons()
{
self.weaponInventory = self GetWeaponsList();
self.lastActiveWeapon = self GetCurrentWeapon();
self.laststandpistol = undefined;

//ASSERTEX( self.lastActiveWeapon != "none", "Last active weapon is 'none,' an unexpected result." );

self.weaponAmmo = [];

for( i = 0; i < self.weaponInventory.size; i++ )
{
weapon = self.weaponInventory[i];

if ( WeaponClass( weapon ) == "pistol" && !IsDefined( self.laststandpistol ) )
{
self.laststandpistol = weapon;
}

switch( weapon )
{
// this player was killed while reviving another player
case "syrette":
// player was killed drinking perks-a-cola
case "zombie_perk_bottle_doubletap":
case "zombie_perk_bottle_revive":
case "zombie_perk_bottle_jugg":
case "zombie_perk_bottle_sleight":
case "zombie_bowie_flourish":
case "zombie_knuckle_crack":
self.lastActiveWeapon = "none";
continue;
}

self.weaponAmmo[weapon]["clip"] = self GetWeaponAmmoClip( weapon );
self.weaponAmmo[weapon]["stock"] = self GetWeaponAmmoStock( weapon );
}

self TakeAllWeapons();

if ( !IsDefined( self.laststandpistol ) )
{
self.laststandpistol = level.laststandpistol;
}
}
Last Edit: September 19, 2015, 05:37:34 am by jbird
broken avatar :(
×
broken avatar :(
Location: usCali
Date Registered: 11 July 2015
Last active: 9 years ago
Posts
21
Respect
Forum Rank
Legless Crawler
Primary Group
Member
Personal Quote
Live and Learn
×
louisfm16's Groups
louisfm16's Contact & Social LinksPortfolio
Im doing this for a waw map im making so im not sure if it will help you much since your doing this for bo1. what i did is check for a certain condition(in my case when all players are inside a trigger_radius) and when a player dies completely save his weapons by using getweaponslist function (getweaponslist would return an array) to the level object and then when you want to give them back loop through the weapons array and use giveweapon function(to give that player all his old weapons).
if you want to do this for all players just use a 2d array(an array inside an array) so for example:

Code Snippet
Plaintext
level.allPlayersWeapons = [['ak47', 'bazooka', 'minigun'], ['M1911', 'RPG'], ['Olympia', 'M14', 'M16'], ['B23R', 'UZI']]; // I know you cant make arrays this way in gsc syntax but its just for simplicity purposes
players = getPlayers();
for(i = 0; i < players.size; i++) {
    for(j = 0; j < allPlayersWeapons[i].size; j++) {
        players[i] giveWeapon(allPlayersWeapons[i][j]);
    }
}

P.S. make sure you take the default weapon the player spawns with so that he doesnt have an extra weapon(the M1911).

so something like that I might of gotten 1 or 2 things wrong i made this like 2 months ago so yeah
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 years ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
jbird's Groups
Update 1: I was able to get it to remove the starting pistol that it gives you when you respawn by waiting a frame, but it still does not give players their weapons back.
Update 2: I actually got it working by combining the 2 functions and putting it in the same script, although it's not flawless yet. For whatever reason, the first respawn will give me the starting pistol only with 8/24 ammo but everytime after the first restart of a game it works
Update 3: Got it working, the problem was that it was taking my weapons before I spawned in initially so when I would respawn it give me the weapons it had saved when the game was loading which was none
Last Edit: September 19, 2015, 07:23:58 pm by jbird
broken avatar :(
×
broken avatar :(
Location: usCali
Date Registered: 11 July 2015
Last active: 9 years ago
Posts
21
Respect
Forum Rank
Legless Crawler
Primary Group
Member
Personal Quote
Live and Learn
×
louisfm16's Groups
louisfm16's Contact & Social LinksPortfolio
Awesome glad you got it working, I'm not the best or worst scripted but if you need any more help or ideas let me know

 
Loading ...