paccoderpster Posted August 17, 2018 Posted August 17, 2018 (edited) tl;dr: - How to check if player is carrying a specific weapon - How to check how much ammo he is carrying Hello, i hope that this is the right subforum for my problem. I am trying to make an armory where players can take and put weapons/ammo. The "take" is working fine, but I don't find a way to check (on server-side) if a player carries the weapon he wants to put in and how much ammo he is carrying, so when a player wants to put a weapon in the armory, i don't know if hes actually carrying the weapon. In the wiki i have found: Player::getWeaponAmmo (not working with weapon hash, always returns 0) Player::weaponAmmo (don't know how to use) Player::weapons (don't know how to use) Player::allWeapons (returns "{}") Regards, Pacco (i'm not a native english speaker, so please have indulgence) Edited August 17, 2018 by paccoderpster
Doom Posted August 19, 2018 Posted August 19, 2018 It's a known issue. Most of the functions related to weapons should be fixed in 0.4 Afaik you can use the player.weapon property to get the current armed weapon. https://wiki.rage.mp/index.php?title=Player::weapon 1
notsosmart Posted August 21, 2018 Posted August 21, 2018 Send the request event to the client, get the data, then bounce back to the server with the data. Use these natives; mp.game.invoke("0x8DECB02F88F428BC", mp.players.local.handle, mp.game.joaat("weapon_SpecialCarbine"), 0); //Check specific weapon mp.game.invoke("0x015A522136D7F951", mp.players.local.handle, mp.game.joaat("weapon_SpecialCarbine")); //Check ammo count on weapon 1
togn Posted September 11, 2018 Posted September 11, 2018 I'm trying to save players' weapons on DC and load them when player reconnects. Tested this way, however, it doesn't seem to work reliably: for some weapons it works, but for most, it doesn't. For instance, for pistol it works perfectly, but for the same SpecialCarbine it returns 0's. While I hold SpecialCarbine in hand and test it for specialcarbine_mk2, it returns correct ammo count. I've tried using hashes plainly, same result. I don't think I'm messing anything up though. Any other way to save player weapons?
togn Posted September 12, 2018 Posted September 12, 2018 (edited) Found a list of weaponSlots, cycling through them, checking for weapon and then checking for ammo with natives, then parsing the same in the list. Works somewhat ok, but again, not for all weapons. Seems like weaponslot list isn't up to date - missing newer weapons. Cannot seem to find a better one though. Tried gettings the slot ids with GET_WEAPONTYPE_SLOT(Hash weaponHash) but it returns 0s for most of the newer weapons. Ridiculous. const localPlayer = mp.players.local; const weaponSlots = new Set([1993361168,1277010230,932043479,690654591,1459198205,195782970,-438797331,896793492,495159329,-1155528315,-515636489,-871913299,-1352759032,-542958961,1682645887,-859470162,-2125426402,2067210266,-538172856,1783244476,439844898,-24829327,1949306232,-1941230881,-1033554448,320513715,-695165975,-281028447,-686713772,347509793,1769089473,189935548,248801358,386596758,-157212362,436985596,-47957369, 575938238]); function getWeaponTypeInSlot (weaponSlot) { return mp.game.invoke('0xEFFED78E9011134D', localPlayer.handle, weaponSlot); } function getAmmoWeapon (weaponhash) { return mp.game.invoke('0x015A522136D7F951', localPlayer.handle, weaponhash); } function getAllWeapons() { const weapons = {}; weaponSlots.forEach(weaponSlot => { const weapon = getWeaponTypeInSlot(weaponSlot); if (weapon !== 0) { weapons[weapon] = { ammo: getAmmoWeapon(weapon) }; } }); return weapons; } Edited September 12, 2018 by togn
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now