C# Method won't get selected ped weapon (Weapon drop command)

I’m trying to write a method that drops the current held weapon via a command.

However, I’m getting an error when within in “SetPedDropInventoryWeapon” native.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using CitizenFX.Core.UI;
using static CitizenFX.Core.Native.API;

namespace Weapon
{
    public class DropWeapon : BaseScript
    {
        public DropWeapon()
        {
            TriggerEvent("chat:addSuggestion", "/drop", "Drop your weapon on the ground.");
            Tick += dropWeap;
            RegisterCommand("drop", new Action<int, List<object>, string>((source, arguments, raw) =>
            {
                dropWeap();
            }), false);

        }

        private async Task dropWeap()
        {
            var ped = GetPlayerPed(-1);
            var weap = GetSelectedPedWeapon(ped);
            SetPedDropsWeaponsWhenDead(ped, true);
            RequestAnimDict("mp_weapon_drop");
            if (DoesEntityExist(GetPlayerPed(-1)) && !IsEntityDead(GetPlayerPed(-1)))
            {
                TaskPlayAnim(ped, "mp_weapon_drop", "drop_bh", 8, 2, -1, 0, 2, false, false, false);
                SetPedDropsInventoryWeapon(ped, weap, 0, 2, 0, 1000);
                SetCurrentPedWeapon(ped, 2725352035, true);
                Screen.ShowNotification("You dropped your weapon on the ground.");
            }
        }
    }
}

The error is “SetPedDropsInventoryWeapon(ped, weap, 0, 2, 0, 1000);” the “wep” integer is not able to be converted to an uint.

Any ideas?

if you have an int that you want to convert just do it like this:

int someValue = 193048083;
uint uintOfSomeValue = (uint) someValue;

I’m not sure I understand, something like this?

int wep = 193048083;
uint uintOfwep = (uint) GetSelectedPedWeapon(ped);

I think so, unless you’re trying to do something else? you mentioned your issue was that an int couldn’t be converted into a uint? so just add (uint) before the int that you want to convert.

Basically what I’m trying to do is just a drop weapon void, which all works, however, it is basing it off weapon hash, I’m trying to write it so it drops the weapon, the player has equipped in their hand,

so I’m using

int wep = GetSelectedPedWeapon(ped);

However

When I try to add it to

SetPedDropsInventoryWeapon(ped, wep, 0, 2, 0, 1000);

The wep part is supposed to be a uint weapon hash, not an int, any ideas on how to go about doing this?

it spits out this error

cannot convert from 'int' to 'uint'

Just do (try) this:

SetPedDropsInventoryWeapon(ped, (uint)wep, 0f, 2f, 0f, 1000);

Also, that 0, 2, 0 needs to each be floats. So I made them floats as well.

1 Like

Thanks that worked!

Oh I see, and it is as easy as identifying it as an (uint) with just the name and the brackets.

Thanks bro and yeah I didn’t think i had to add f to floats.