kasakka 4 Posted May 16, 2015 Can anyone explain to me how the hashes work in GTA V? For example if I want to get the current weapon the player has, I can use the WEAPON.GET_SELECTED_PED_WEAPON(player, weaponHash, true) to fill variable weaponHash. However, if I then want to get the weapon OBJECT, how do I do that? Is every object type (WEAPON, PLAYER, VEHICLE etc) supposed to have its own function to get an object from hash? I'm trying to make a mod that allows you to toggle weapon attachments like silencer on and off but have difficulty getting the needed weapon and attachment (referred to as weapon component in the functions I think) objects. Getting the hashes seems to be easier. Quote Share this post Link to post Share on other sites
BoXz_modder 0 Posted May 16, 2015 Can anyone explain to me how the hashes work in GTA V? For example if I want to get the current weapon the player has, I can use the WEAPON.GET_SELECTED_PED_WEAPON(player, weaponHash, true) to fill variable weaponHash. However, if I then want to get the weapon OBJECT, how do I do that? Is every object type (WEAPON, PLAYER, VEHICLE etc) supposed to have its own function to get an object from hash? I'm trying to make a mod that allows you to toggle weapon attachments like silencer on and off but have difficulty getting the needed weapon and attachment (referred to as weapon component in the functions I think) objects. Getting the hashes seems to be easier. What language are you writing in? Quote Share this post Link to post Share on other sites
sjaak327 1,026 Posted May 16, 2015 (edited) Hash weaponPed playerPed= PLAYER::PLAYER_PED_ID();WEAPON::GET_CURRENT_PED_WEAPON(playerPed,&weapon,1); Easy. You already have the hash, that hash is used to do stuff with the weapon, like adding ammo, adding attachments etc. To get the hash for say WEAPON_PISTOL you would simply do: hash Pistol=GET_HASH_KEY("WEAPON_PISTOL"); That native works for Cars, Peds Weapons and objects. Edited May 16, 2015 by sjaak327 Quote Share this post Link to post Share on other sites
BenBaron 21 Posted May 16, 2015 Hi, I don't know if I understand you correctly, but internally all is masked using hashes instead of clear names. So for each native to spawn something you'd need the object hash (object in terms of vehicle, peds and objects), so we got for example Hash GAMEPLAY::GET_HASH_KEY(char*) to translate a "clear name" into a hash that can than be used. Always provided your "clear name" is an object name that translates into a hash that is actually in the game. I didn't try, but in C++ I'd do something like this: Ped playerPed = PLAYER::PLAYER_PED_ID();Hash weaponHash = WEAPON::GET_SELECTED_PED_WEAPON(playerPed);WEAPON::GIVE_WEAPON_COMPONENT_TO_PED(playerPed, weaponHash, weaponComponentHash); Of course you'd need to test if weaponHash is actually a weapon and you need the suitable weaponComponentHash. This is not tested, though but this is, what I'd try. Quote Share this post Link to post Share on other sites
thewhitehammer99 564 Posted May 16, 2015 (edited) converted the above code to C# (looks like thats what op is using) int pedID = PLAYER_PED_ID(); int weapon = GET_SELECTED_PED_WEAPON(pedID); GIVE_WEAPON_COMPONENT_TO_PED(pedID, weapon, /*weapon component hash*/); edit - sorry i stuffed up the code, but it should be right now Edited May 16, 2015 by thewhitehammer99 Quote Share this post Link to post Share on other sites
sjaak327 1,026 Posted May 16, 2015 That's one step more than needed. GET_CURRENT_PED_WEAPON will get the weapon hash and can be directly used for GIVE_WEAPON_COMPONENT_TO_PED Unless I am missing something, but isn't the selected weapon always the current weapon ? Quote Share this post Link to post Share on other sites
kasakka 4 Posted May 16, 2015 So basically you don't need to get the weapon or attachment object first to do stuff with them, the hash is enough? So for example if in LUA I do local playerPed = PLAYER.PLAYER_PED_ID()local player = PLAYER.GET_PLAYER_PED(playerPed) Is the player variable now just a hash representing the player pedestrian? Quote Share this post Link to post Share on other sites
c39687 61 Posted May 16, 2015 So basically you don't need to get the weapon or attachment object first to do stuff with them, the hash is enough? So for example if in LUA I do local playerPed = PLAYER.PLAYER_PED_ID()local player = PLAYER.GET_PLAYER_PED(playerPed) Is the player variable now just a hash representing the player pedestrian? those functions return handles, not hashes... when you work with models for example you will have to take a model's string name and convert to hash value in order to use with natives. Quote Share this post Link to post Share on other sites