UGX-Mods

Call of Duty 5: World at War => Help Desk => Scripting => Topic started by: Fire Level One on July 07, 2016, 12:40:04 am

Title: How to make it where you can drop weapon
Post by: Fire Level One on July 07, 2016, 12:40:04 am
Hey folks, how do you make it where when you hold down a certain button (on your keyboard not trigger_use) you'll drop your gun and it can be picked up by anyone?

Double Post Merge: July 07, 2016, 01:52:58 am
I did some research and I know the dvar for dropping your weapon is "dropweapon" now how do I bind that to a button?
Title: Re: Hold to bind dvar dropweapon to a button
Post by: DeletedUser on July 07, 2016, 12:34:01 pm
dropweapon is not a dvar, it's a command, so nate's solution won't work.
Title: Re: Hold to bind dvar dropweapon to a button
Post by: buttkicker845 on July 07, 2016, 01:19:18 pm
you could do something like this that will use the actionslot 1 which is supposed to be the map button but zombiemode doesnt have a map so its free to use.
Code Snippet
Plaintext

onPlayerConnect()
{
       level waittill("connecting",player);
       player thread onPlayerSpawn();
}

onPlayerSpawn()
{
       self endon("disconnect");
       while(1)
       {
                 self waittill("spawned");
                 self thread waitForWeaponDrop();
        }
}

waitForWeaponDrop()
{
         if(!isPlayer(self))
                 return;
           
         self endon("death");
         self endon("disconnect");

           while(1)
           {
                       self waittill("menuresponse", menu, response);
                       if(maps\_zombiemode_utility::is_valid_player(self) && response == "+actionslot 1")
                       {
                                 primaries = self  getWeaponsListPrimaries();
                                 if(primaries.size > 1) //checks to make sure the player has more than one weapon
                                           self thread dropPlayerWeapon( self getCurrentWeapon());
                       }
            }
}
dropPlayerWeapon(weapon)
{
       if(!isPlayer(self))
                return;
       self endon("death");
       self endon("disconnect");
       
       self takeWeapon(weapon);
       self dropPlayerWeapon(weapon, self GetWeaponAmmoClip( weapon ) , self GetWeaponAmmoStock( weapon ));
}
dropPlayerWeapon( weapon_name , clipAmmo , stockAmmo)
{
weapon = weapon_name;
item = Spawn( "weapon_" + weapon_name, self.origin + (0,0,12) );
item SetModel( GetWeaponModel(weapon) );
if(!isDefined(clipAmmo))
clipAmmo = RandomInt( WeaponClipSize(weapon) );
if(!isDefined(stockAmmo))
stockAmmo = RandomIntRange( WeaponClipSize(weapon), WeaponMaxAmmo( weapon ) + 1 );
stockMax = WeaponMaxAmmo( weapon );
if ( stockAmmo > stockMax )
stockAmmo = stockMax;

item ItemWeaponSetAmmo( clipAmmo, stockAmmo );
}

put this in your mapname.gsc and this before zombiemode::main();

Code Snippet
Plaintext
level thread onPlayerConnect();

although somewhere you might want to do a check that the player's weapon isnt a perk bottle or a grenade or something like that

Fixed my code. Should hopefully work now. I still cant test it though lol

isn't dropWeapon() an ai only function?


Edit: I added the entire funtion that im using for the weapon drop in my project, its an edited version of DUIPs tut
Title: Re: Hold to bind dvar dropweapon to a button
Post by: buttkicker845 on July 07, 2016, 01:57:51 pm
Yeah you are right. Solid code there man. Do you have a list of engine notifies? I never heard of menuresponse, but I am still new to scripting. Also you sure spawn("weapon_"+weapon ............) will work? I have never seen that either.

thanks :)
its a response from menus that is used for key press, i originally got it from a tut that blunt made. also duip made a tut on the spawn weapon part.

 i'm also currently using both the menuresponse and the weapon spawn on a non-zombie project ive been working on so i know they both work.

the only thing im not positive is the "+actionslot 1" as the response name. thats what its listed as under in the options_pc_mis menu file so it should work

edit: actually looking at the tutorial again it opens a scriptmenu during the key bind so its possible this wont work with the map key. but he can fallow the original tut and make his own keybinding for it if he wants to do it this way.
Title: Re: Hold to bind dvar dropweapon to a button
Post by: Fire Level One on July 07, 2016, 09:52:10 pm
Completely untested because I am at work but paste this in the bottom of your mapname.gsc

Code Snippet
Plaintext
drop_weapon_func()
{
players = getplayers();
for( i=0;i<players.size;i   )
{
players[i] setactionslot( 2, "weapon", "colt" ); // iirc this colt is different than the colt you spawn with
players[i] thread drop_weapon_notify();
players[i] thread drop_weapon_watch();
}
}

drop_weapon_notify()
{
self endon("disconnect");
while(1)
{
self.weapon_to_drop = getcurrentweapon();
wait(0.05);
self.check_if_colt = getcurrentweapon();
if( self.check_if_colt == "colt" && self.weapon_to_drop != self.check_if_colt )
self notify( "drop_the_weap" );
wait(0.05);
}
}

drop_weapon_watch()
{
self endon("disconnect");
while(1)
{
self waittill("drop_the_weap");
iprintlnbold("weapon should drop at this point unless I used dropweapon wrong");
self takeweapon("colt");
self switchtoweapon(self.weapon_to_drop);
self dropweapon( self.weapon_to_drop, "left", 0.9 );
}
}

and then under maps\_zombiemode::main(); add this:
Code Snippet
Plaintext
thread drop_weapon_func();

This binds the drop weapon to action slot 2 if it works properly
(https://ujwtng-sn3302.files.1drv.com/y3mKe2acQz3RdnSBGe_OGMOPtz36zC-o3BOsPKMd00bJlCIvPECpaLb1g2J6F93G8IN7rowRN1p6r9R6BwvmcSWN5Azw8r8qMRzif5oLKePZ3eMg_xtgFcOIRpMqKz-5zJBSRbGeSslOfzHii7eze4RTmWdWK0J-Ti4ETm3Kl8Xmcw?width=1921&height=182&cropmode=none)
I got an error (the pictures kinda hard to read, sorry.)
Title: Re: How to make it where you can drop weapon
Post by: buttkicker845 on July 07, 2016, 09:57:19 pm
its it should look like this in the drop_weapon_notify()

Code Snippet
Plaintext
                self.weapon_to_drop = self getcurrentweapon(); 
wait(0.05);
self.check_if_colt = self getcurrentweapon();

but youre probably still going to run into the problem that dropweapon is for AI and not players
Title: Re: Hold to bind dvar dropweapon to a button
Post by: Fire Level One on July 07, 2016, 10:03:56 pm
you could do something like this that will use the actionslot 1 which is supposed to be the map button but zombiemode doesnt have a map so its free to use.
Code Snippet
Plaintext

onPlayerConnect()
{
       level waittill("connecting",player);
       player thread onPlayerSpawn();
}

onPlayerSpawn()
{
       self endon("disconnect");
       while(1)
       {
                 self waittill("spawned");
                 self thread waitForWeaponDrop();
        }
}

waitForWeaponDrop()
{
         if(!isPlayer(self))
                 return;
           
         self endon("death");
         self endon("disconnect");

           while(1)
           {
                       self waittill("menuresponse", menu, response);
                       if(maps\_zombiemode_utility::is_valid_player(self) && response == " actionslot 1")
                       {
                                 primaries = self  getWeaponsListPrimaries();
                                 if(primaries.size > 1) //checks to make sure the player has more than one weapon
                                           self thread dropPlayerWeapon( self getCurrentWeapon());
                       }
            }
}
dropPlayerWeapon(weapon)
{
       if(!isPlayer(self))
                return;
       self endon("death");
       self endon("disconnect");
       
       self takeWeapon(weapon);
       self dropPlayerWeapon(weapon, self GetWeaponAmmoClip( weapon ) , self GetWeaponAmmoStock( weapon ));
}
dropPlayerWeapon( weapon_name , clipAmmo , stockAmmo)
{
weapon = weapon_name;
item = Spawn( "weapon_"   weapon_name, self.origin   (0,0,12) );
item SetModel( GetWeaponModel(weapon) );
if(!isDefined(clipAmmo))
clipAmmo = RandomInt( WeaponClipSize(weapon) );
if(!isDefined(stockAmmo))
stockAmmo = RandomIntRange( WeaponClipSize(weapon), WeaponMaxAmmo( weapon )   1 );
stockMax = WeaponMaxAmmo( weapon );
if ( stockAmmo > stockMax )
stockAmmo = stockMax;

item ItemWeaponSetAmmo( clipAmmo, stockAmmo );
}

put this in your mapname.gsc and this before zombiemode::main();

Code Snippet
Plaintext
level thread onPlayerConnect();

although somewhere you might want to do a check that the player's weapon isnt a perk bottle or a grenade or something like that

isn't dropWeapon() an ai only function?


Edit: I added the entire funtion that im using for the weapon drop in my project, its an edited version of DUIPs tut
I got this error
(https://ujwsng-sn3302.files.1drv.com/y3mlDS3lI-SCCmpeZfD9W1Z84_L7txuzl9oQhXzriQxwJJPizdkBUZx02sJT-x6CAGf6eboON9g9QGOviD6lmg6B_y4jczh9OJDiU4-FpDYWPdL6xYYTY_E1eqyV2DFDM50Pgznc3SqNLBoQgwIQhcJ2Iq3s_3LI__NOR6OvgEou-Y?width=1920&height=1080&cropmode=none)
Title: Re: How to make it where you can drop weapon
Post by: buttkicker845 on July 07, 2016, 10:10:56 pm
huh, the odds of me naming a two different functions the same from two different scripts and like 6 months apart?  :troll:

anyways heres the fix

Code Snippet
Plaintext
onPlayerConnect()
{
       level waittill("connecting",player);
       player thread onPlayerSpawn();
}

onPlayerSpawn()
{
       self endon("disconnect");
       while(1)
       {
                 self waittill("spawned");
                 self thread waitForWeaponDrop();
        }
}

waitForWeaponDrop()
{
         if(!isPlayer(self))
                 return;
           
         self endon("death");
         self endon("disconnect");

           while(1)
           {
                       self waittill("menuresponse", menu, response);
                       if(maps\_zombiemode_utility::is_valid_player(self) && response == " actionslot 1")
                       {
                                 primaries = self  getWeaponsListPrimaries();
                                 if(primaries.size > 1) //checks to make sure the player has more than one weapon
                                           self thread dropPlayerWeapon( self getCurrentWeapon());
                       }
            }
}
dropPlayerWeapon(weapon)
{
       if(!isPlayer(self))
                return;
       self endon("death");
       self endon("disconnect");
       
       self takeWeapon(weapon);
       self placeTheWeaponOnTheGround(weapon, self GetWeaponAmmoClip( weapon ) , self GetWeaponAmmoStock( weapon ));
}
placeTheWeaponOnTheGround( weapon_name , clipAmmo , stockAmmo)
{
weapon = weapon_name;
item = Spawn( "weapon_"   weapon_name, self.origin   (0,0,12) );
item SetModel( GetWeaponModel(weapon) );
if(!isDefined(clipAmmo))
clipAmmo = RandomInt( WeaponClipSize(weapon) );
if(!isDefined(stockAmmo))
stockAmmo = RandomIntRange( WeaponClipSize(weapon), WeaponMaxAmmo( weapon )   1 );
stockMax = WeaponMaxAmmo( weapon );
if ( stockAmmo > stockMax )
stockAmmo = stockMax;

item ItemWeaponSetAmmo( clipAmmo, stockAmmo );
}
Title: Re: How to make it where you can drop weapon
Post by: DidUknowiPwn on July 07, 2016, 11:25:35 pm
huh, the odds of me naming a two different functions the same from two different scripts and like 6 months apart?  :troll:

anyways heres the fix

Code Snippet
Plaintext
onPlayerConnect()
{
       level waittill("connecting",player);
       player thread onPlayerSpawn();
}

onPlayerSpawn()
{
       self endon("disconnect");
       while(1)
       {
                 self waittill("spawned");
                 self thread waitForWeaponDrop();
        }
}

waitForWeaponDrop()
{
         if(!isPlayer(self))
                 return;
           
         self endon("death");
         self endon("disconnect");

           while(1)
           {
                       self waittill("menuresponse", menu, response);
                       if(maps\_zombiemode_utility::is_valid_player(self) && response == " actionslot 1")
                       {
                                 primaries = self  getWeaponsListPrimaries();
                                 if(primaries.size > 1) //checks to make sure the player has more than one weapon
                                           self thread dropPlayerWeapon( self getCurrentWeapon());
                       }
            }
}
dropPlayerWeapon(weapon)
{
       if(!isPlayer(self))
                return;
       self endon("death");
       self endon("disconnect");
       
       self takeWeapon(weapon);
       self placeTheWeaponOnTheGround(weapon, self GetWeaponAmmoClip( weapon ) , self GetWeaponAmmoStock( weapon ));
}
placeTheWeaponOnTheGround( weapon_name , clipAmmo , stockAmmo)
{
weapon = weapon_name;
item = Spawn( "weapon_"   weapon_name, self.origin   (0,0,12) );
item SetModel( GetWeaponModel(weapon) );
if(!isDefined(clipAmmo))
clipAmmo = RandomInt( WeaponClipSize(weapon) );
if(!isDefined(stockAmmo))
stockAmmo = RandomIntRange( WeaponClipSize(weapon), WeaponMaxAmmo( weapon )   1 );
stockMax = WeaponMaxAmmo( weapon );
if ( stockAmmo > stockMax )
stockAmmo = stockMax;

item ItemWeaponSetAmmo( clipAmmo, stockAmmo );
}

For some reason you're missing the "+" in important places.
i.e. "weapon_"   weapon_name , self.origin   (0,0,12) , WeaponMaxAmmo( weapon )   1 )
Title: Re: How to make it where you can drop weapon
Post by: buttkicker845 on July 07, 2016, 11:30:33 pm
you could do something like this that will use the actionslot 1 which is supposed to be the map button but zombiemode doesnt have a map so its free to use.
Code Snippet
Plaintext

onPlayerConnect()
{
       level waittill("connecting",player);
       player thread onPlayerSpawn();
}

onPlayerSpawn()
{
       self endon("disconnect");
       while(1)
       {
                 self waittill("spawned");
                 self thread waitForWeaponDrop();
        }
}

waitForWeaponDrop()
{
         if(!isPlayer(self))
                 return;
           
         self endon("death");
         self endon("disconnect");

           while(1)
           {
                       self waittill("menuresponse", menu, response);
                       if(maps\_zombiemode_utility::is_valid_player(self) && response == "+actionslot 1")
                       {
                                 primaries = self  getWeaponsListPrimaries();
                                 if(primaries.size > 1) //checks to make sure the player has more than one weapon
                                           self thread dropPlayerWeapon( self getCurrentWeapon());
                       }
            }
}
dropPlayerWeapon(weapon)
{
       if(!isPlayer(self))
                return;
       self endon("death");
       self endon("disconnect");
       
       self takeWeapon(weapon);
       self dropPlayerWeapon(weapon, self GetWeaponAmmoClip( weapon ) , self GetWeaponAmmoStock( weapon ));
}
dropPlayerWeapon( weapon_name , clipAmmo , stockAmmo)
{
weapon = weapon_name;
item = Spawn( "weapon_" + weapon_name, self.origin + (0,0,12) );
item SetModel( GetWeaponModel(weapon) );
if(!isDefined(clipAmmo))
clipAmmo = RandomInt( WeaponClipSize(weapon) );
if(!isDefined(stockAmmo))
stockAmmo = RandomIntRange( WeaponClipSize(weapon), WeaponMaxAmmo( weapon ) + 1 );
stockMax = WeaponMaxAmmo( weapon );
if ( stockAmmo > stockMax )
stockAmmo = stockMax;

item ItemWeaponSetAmmo( clipAmmo, stockAmmo );
}

put this in your mapname.gsc and this before zombiemode::main();

Code Snippet
Plaintext
level thread onPlayerConnect();
thats weird? its in the original post
Title: Re: How to make it where you can drop weapon
Post by: Fire Level One on July 08, 2016, 03:04:30 am
huh, the odds of me naming a two different functions the same from two different scripts and like 6 months apart?  :troll:

anyways heres the fix

Code Snippet
Plaintext
onPlayerConnect()
{
       level waittill("connecting",player);
       player thread onPlayerSpawn();
}

onPlayerSpawn()
{
       self endon("disconnect");
       while(1)
       {
                 self waittill("spawned");
                 self thread waitForWeaponDrop();
        }
}

waitForWeaponDrop()
{
         if(!isPlayer(self))
                 return;
           
         self endon("death");
         self endon("disconnect");

           while(1)
           {
                       self waittill("menuresponse", menu, response);
                       if(maps\_zombiemode_utility::is_valid_player(self) && response == " actionslot 1")
                       {
                                 primaries = self  getWeaponsListPrimaries();
                                 if(primaries.size > 1) //checks to make sure the player has more than one weapon
                                           self thread dropPlayerWeapon( self getCurrentWeapon());
                       }
            }
}
dropPlayerWeapon(weapon)
{
       if(!isPlayer(self))
                return;
       self endon("death");
       self endon("disconnect");
       
       self takeWeapon(weapon);
       self placeTheWeaponOnTheGround(weapon, self GetWeaponAmmoClip( weapon ) , self GetWeaponAmmoStock( weapon ));
}
placeTheWeaponOnTheGround( weapon_name , clipAmmo , stockAmmo)
{
weapon = weapon_name;
item = Spawn( "weapon_"   weapon_name, self.origin   (0,0,12) );
item SetModel( GetWeaponModel(weapon) );
if(!isDefined(clipAmmo))
clipAmmo = RandomInt( WeaponClipSize(weapon) );
if(!isDefined(stockAmmo))
stockAmmo = RandomIntRange( WeaponClipSize(weapon), WeaponMaxAmmo( weapon )   1 );
stockMax = WeaponMaxAmmo( weapon );
if ( stockAmmo > stockMax )
stockAmmo = stockMax;

item ItemWeaponSetAmmo( clipAmmo, stockAmmo );
}
bad syntax
(https://utwlng-sn3302.files.1drv.com/y3m-8PqSvUVPH-TsxZu2B462-5BOk6T5xGkWZ-1HMx0VM8GzehKToTgzIV-6kjw3i_myUDvM83ChqsFXzNcdcxEDJz4OBkws0BmbTrJUBUXXfYPUOOmAhrUdaAlbPwCQhvXYsuCSUsYvQ8lCKiPjH2U0ykr2pbE-SKzZukzYgv071w?width=1920&height=1080&cropmode=none)
Title: Re: How to make it where you can drop weapon
Post by: DidUknowiPwn on July 08, 2016, 03:59:52 am
bad syntax
(https://utwlng-sn3302.files.1drv.com/y3m-8PqSvUVPH-TsxZu2B462-5BOk6T5xGkWZ-1HMx0VM8GzehKToTgzIV-6kjw3i_myUDvM83ChqsFXzNcdcxEDJz4OBkws0BmbTrJUBUXXfYPUOOmAhrUdaAlbPwCQhvXYsuCSUsYvQ8lCKiPjH2U0ykr2pbE-SKzZukzYgv071w?width=1920&height=1080&cropmode=none)
as I said it's missing all the necessary  's