Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Code for getting stun-gun for Player results in flashlight

Featured Replies


I have an odd result with this code:

if (Game.IsKeyDown(System.Windows.Forms.Keys.D2))
{
WeaponAsset stunner = new WeaponAsset("WEAPON_STUNGUN");
Game.LocalPlayer.Character.Inventory.GiveNewWeapon(stunner, 1000, true);
}


Instead of the stun-gun, i get the flashlight !
I get one new flash-light every time i press (digit)-2-key (D2)
Is my syntax wrong?
I cant see any option to put the item into a specific slot in the inventory.
Of cause i could select that my Player is of type  stun-gun-patrol in police-locker, but there is a glitch. Even though Random is omitted, the inventory changes content asa avatar leaves the car 2. time. The Avatar is given the shotgun, and the stun-gun is removed from inventory. Because it is difficult to make a ped surrender See:

these 'take-downs' all to often end with a 'dead' AI.
So the stun-gun is important if you want to make the suspect-ped surrender.
The flashlight is not efficient for that (could be an interesting thing actually, if a ped would surrender when it had been in flashlight for ~5 secd..)
What in new WeaponAsset("WEAPON_STUNGUN") could result in a flashlight?
Is there a hash that should be used instead?

Edited by GTAbear
code not formatted

See my plugin here:
https://www.youtube.com/watch?v=peqSXuTfIyY

Let me know if you find it interesting.
Best Regards.

Something like 

if (!keyJustPressed && Game.IsKeyDows(Keys.D2)) 
{
  Game.LocalPlayer.Character.Inventory.GiveNewWeapon(WeaponHash.StunGun, 1, true);
  keyJustPressed = true;
}
else if (!keyJustPressed)
  keyJustPressed = false;
    

should work. keyJustPressed is a class attribute that prevents executing the if-branch each tick the key is being pressed. 

Check out my FIB HRT Callouts script for LSPDFR!

1 hour ago, AchilleX said:

Something like 

if (!keyJustPressed && Game.IsKeyDows(Keys.D2)) 
{
  Game.LocalPlayer.Character.Inventory.GiveNewWeapon(WeaponHash.StunGun, 1, true);
  keyJustPressed = true;
}
else if (!keyJustPressed)
  keyJustPressed = false;
    

should work. keyJustPressed is a class attribute that prevents executing the if-branch each tick the key is being pressed. 

IsKeyDown only triggers once per press anyway, no need to put an extra bool for it

 

 

2 hours ago, GTAbear said:


I have an odd result with this code:

if (Game.IsKeyDown(System.Windows.Forms.Keys.D2))
{
WeaponAsset stunner = new WeaponAsset("WEAPON_STUNGUN");
Game.LocalPlayer.Character.Inventory.GiveNewWeapon(stunner, 1000, true);
}


Instead of the stun-gun, i get the flashlight !
I get one new flash-light every time i press (digit)-2-key (D2)
Is my syntax wrong?
I cant see any option to put the item into a specific slot in the inventory.
Of cause i could select that my Player is of type  stun-gun-patrol in police-locker, but there is a glitch. Even though Random is omitted, the inventory changes content asa avatar leaves the car 2. time. The Avatar is given the shotgun, and the stun-gun is removed from inventory. Because it is difficult to make a ped surrender See:

these 'take-downs' all to often end with a 'dead' AI.
So the stun-gun is important if you want to make the suspect-ped surrender.
The flashlight is not efficient for that (could be an interesting thing actually, if a ped would surrender when it had been in flashlight for ~5 secd..)
What in new WeaponAsset("WEAPON_STUNGUN") could result in a flashlight?
Is there a hash that should be used instead?

Do you have UltimateBackup or StopThePed running in the background? One of them has an option that disables specific weapons, maybe one of them takes away the spawned stungun immediately

  • Author
On 9/26/2022 at 8:50 PM, AchilleX said:
Character.Inventory.GiveNewWeapon(WeaponHash.StunGun, 1, true);


WeaponHash  !!! I did not have that in any of the examples i have studied!
That could be the explanation.
Is that an update from earlier syntax?
That could perhaps also be a reason for a fail for sound-files i have made experiments with, should a hash also be used in that circumstance..(?)
Also maybe for Props
Here i have

But the issue for getting the stunGun that You have solved!
It was tricky to test, because the content of the inventory is changing almost randomly, even after specifically having made shure that non of the Random options are chosen in police-locker, but i then found a way to disarm Player:
 

        if (Game.IsKeyDown(System.Windows.Forms.Keys.ControlKey))
                    {
                        NativeFunction.Natives.RemoveAllPedWeapons(Game.LocalPlayer.Character, true, -1);

}

Then after doing that,  then calling

                   

Game.LocalPlayer.Character.Inventory.GiveNewWeapon(WeaponHash.StunGun, 1, true);

Gives Player a stungun!

Should it been possible to build with

                    WeaponAsset stunner = new WeaponAsset("WEAPON_STUNGUN");
                    Game.LocalPlayer.Character.Inventory.GiveNewWeapon(stunner, 1000, true);

I fear i have a outdated assembly -But It does say 1.95.1310163.60 in properties| Details, though (?)


> "IsKeyDown only triggers once per press anyway, no need to put an extra bool for it"
Yes, I did thought IsKeyDown was singularity, and isKeyDownRightNow was multiplets
Many thanks for pointing that out @RicyVasco
Btw , no i have no plugins running. Only LSPDfr. Sorry for forgetting to mention that.

Edited by GTAbear
forgot the part about STP

See my plugin here:
https://www.youtube.com/watch?v=peqSXuTfIyY

Let me know if you find it interesting.
Best Regards.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Similar Content

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.