#Bullets ammount and FireMode

116 messages · Page 1 of 1 (latest)

boreal onyx
#

How can I get the number of bullets in the clip of a machine gun and what firing mode it has, given that the player is holding it and I have UnturnedPlayer

weary vine
#

How about you even try what i sent you?

#
if (player.Player.equipment.asset is ItemGunAsset gunAsset) {
    if (Assets.find(EAssetType.ITEM, gunAsset.getMagazineID()) is ItemMagazineAsset itemMagazineAsset) {
        itemMagazineAsset.amount //Ammo
    }
}```
#

That should work

#

FireMode should also be in ItemGunAssets

weary vine
boreal onyx
#

Sort of

weary vine
#

no

#

thats the assets of what the player is holding

#

goober

#

i told you that already

weary vine
#

what????

#

what do you mean

boreal onyx
#

This is from ItemGunAsset

weary vine
#

huh

#

use what i sent you trythat

#

maybe

#

maybe

boreal onyx
#

Thanks, I'll try, but I doubt it

weary vine
# boreal onyx

you are clearly doing something wrong and not following what i gave you

#

everything untill getting the magazine works 100%

#

after that im not that sure

weary vine
boreal onyx
#

HUD

weary vine
#

send me your code since you are doing something and not following what i atleast tried to make for you

weary vine
#
var oFiremode = typeof(EFiremode).GetField("firemode", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(itemGunAsset);
if ((EFiremode)oFiremode == EFiremode.AUTO) {
    //Do stuff
}```
Try this, using reflections.
chrome trout
#

Thats not how you get the data from a gun

#

Youll have to look at its state

weary vine
weary vine
#

@boreal onyx

#
if (UnturnedPlayer.Player.equipment.asset is ItemGunAsset itemGunAsset) {
    byte[] state = itemGunAsset.getState();
    if (state[11]==0) {
        //Safety
    }
    else if (state[11]==1) {
        //Semi-Auto
    }
    else if (state[11]==2) {
        //Auto
    }
    else if (state[11] == 3) {
        //Burst
    }
    int AmmoCount = state[10];
}```
Heres what you need.
boreal onyx
boreal onyx
#

And FireMode doesn't work

#

Also, if you remove the magazine, it will show bullets that are not there :0

boreal onyx
# boreal onyx

It shows the numbers 1-(Number of max bullets in the magazine)

weary vine
#

State[10] is the ammo

boreal onyx
weary vine
#

Will play around with it

boreal onyx
#

and it random numbers

weary vine
#

wait

#

im testing it

boreal onyx
#

oh stop

#

why we getting from asset

#

:////////////

weary vine
#

bro

#

do you know what even asset is?

boreal onyx
#

byte[] state = Player.Player.equipment.state;

weary vine
#

that gets the state fromever the player is holding

#

asset is any kind of an assets class the player is holding

#

and you dont want to get state for example for a gas can

boreal onyx
weary vine
#

very wheir why that is broken

weary vine
#

you need to check if the player is holding a gun

boreal onyx
#

The game code is too strange

weary vine
#
public void Execute(IRocketPlayer caller, string[] command) {
    if (caller == null) return;
    UnturnedPlayer uCaller = caller as UnturnedPlayer;
    if (uCaller.Player.equipment.asset == null)
        return;

    if (uCaller.Player.equipment.asset is ItemGunAsset gun) {
        byte[] state = gun.getState();
        ChatManager.serverSendMessage($"Ammo: {state[10]} | FireMode: {state[11]}", Color.green, null, uCaller.SteamPlayer()
            , EChatMode.SAY, "https://dl.rbmkblaze.org/images/Sausageface.png", false);
    }
}```

@keen crater @chrome trout Any idea why?
boreal onyx
#

xd

#

for getting magazine asset(There can be several magazines for a weapon)

weary vine
#

gun's attachments?

boreal onyx
#

yes

chrome trout
#

Youll want to use PlayerEquipment.state

weary vine
#

ohhh

#

alright

weary vine
# boreal onyx yes
if (player.Player.equipment.asset is ItemGunAsset) {
     int ammo = player.Player.equipment.state[10];
}```
chrome trout
#

Yes

weary vine
#

alright

boreal onyx
#

🤓

boreal onyx
weary vine
#

btw @chrome trout where is the exampleui gone, in what package is it, i want to try something

weary vine
weary vine
#

did you even read it?

weary vine
#

didnt relize it was in the description of bt's vid

weary vine
#

sight state[0],state[1] tactical state[2],state[3] grip state[4],state[5] barrel state[6],state[7] ammo state[8],state[9]

chrome trout
weary vine
#

even tho i could tell you everything, its better to read it all so you can actually understand how it works

chrome trout
#

Use Attachments.parseFromItemState() its static

boreal onyx
#

ty guys

stiff crescent
stiff crescent
# boreal onyx

You did a big L here when you used Provider.findTransportConnection, especially since there are properties in the SDG.Unturned.Player class that have the player's transport connection.

Please use player.Player.channel.owner.transportConnection before I begin a rampage of rage.

#

Also, you are adding variables to strings the old way, just use $"this is a string with a var in the middle {var1} and a var at the very end {var2}"

#

Don't do "this is a string with a var in the middle " + var1.ToString() + " and a var at the very end " + var2.ToString()

keen crater
#

Nelson should deprecate that method ngl

#

See people use it all the time

keen crater
keen crater
#

Sry forgot to turn off ping

stiff crescent
stiff crescent
boreal onyx
#

Apologies for the ping, logically yes