Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Script to remove pre-set list of unwanted weapons onKeyPress


DerrikTikmann
 Share

Recommended Posts

DerrikTikmann
I'm a programmer but have no idea about GTA modding. I want to make a simple script where I can press a specific key and drop a pre-set list of my carried weapons. Essentially I want a quick way to remove my unwanted weapons every time they reappear in my weapons wheel. This is for GTA Online so the solution would of course have to work there.


This must be possible as the following code is simply assigning some existing in game functionality to a single key press.


Could someone translate this into GTA modding code and explain how it would be implemented into the game, the general idea is as follows:



// Set a trigger for weapon removal function

onKeyPress(F10,dropUnwantedWeapons); // Could be any unassigned key



// Full list of weapons in game, if drop is set to 1, weapon will be dropped, if set to 0 weapon will be kept - Set array of weapons

array weaponsList(


array('name'=>'SNS Pistol','drop'=>1),

array('name'=>'Pistol','drop'=>1),

array('name'=>'Vintage Pistol','drop'=>1),

array('name'=>'Heavy Pistol','drop'=>1),

array('name'=>'Pistol .50','drop'=>1),

array('name'=>'Combat Pistol','drop'=>1),

array('name'=>'AP Pistol','drop'=>0),

array('name'=>'Assult shotgun','drop'=>1)


);



function dropUnwantedWeapons() {


foreach (weaponsList as weapon){


if (isCarriedWeapon(weapon['name']) && weapon['drop']==1) get_Weapons().Remove(weapon['name']);


}


}

Link to comment
Share on other sites

I've translated your code into 'modding code'. In case you didn't know, you can write scripts in C# with ScriptHookVDotNet.dll.

To run this script, you need to install the basic ScriptHook and the Net Scripthook.

 

Don't forget to create a folder named 'scripts' in your main GTA V directory. The INSERT key can reload at any time all the scripts in the folder.

 

Now you can create a .cs file (video of the script in action : https://vid.me/e/D7Yh) in that folder, and paste the following code :

 

(I've documented the code but if you need more explainations feel free to ask)

using System;using System.Drawing;using GTA;using GTA.Math;using GTA.Native;using System.Collections.Generic;using System.Windows.Forms;namespace RemoveWeapons{    public class Main : Script    {        /* First we need to create our dictionnary which contains all the weapons hashes and their rules         * FYI : - a 'Hash' in GTA V is a Uint32 variable         *       - here is the known weapons hash list : http://pastebin.com/0wwDZgkF          */        public Dictionary<UInt32, int> WeaponsRules = new Dictionary<UInt32, int>();  // (Weapon as Hash, Rule as Int)        public Main() // This function is only called once : at the loading        {            base.Interval = 10; // Interval            KeyDown += OnKeyDown; //Key Handler                       /*Example :              * WeaponsRules.Add(Hash, Int)              *      where Hash is the original Uint32 value and Int the condition (0 = dontRemove, 1=remove)*/            WeaponsRules.Add(0x1B06D571, 1); //Pistol            WeaponsRules.Add(0xBFEFFF6D, 1); //AssaultRifle            // ...        }        public void OnKeyDown(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.F11)            {                CheckInventory();            }        }        public void CheckInventory()        {            int n = 0;            int rule;            foreach (var weapon in WeaponsRules)            {                if(Function.Call<bool>(Hash.HAS_PED_GOT_WEAPON, Game.Player.Character, weapon.Key, false) == true)                {                    if (WeaponsRules.TryGetValue(weapon.Key, out rule))                    {                        if(rule==1) // If rule for this weapon is 'remove' then...                        {                            Function.Call(Hash.REMOVE_WEAPON_FROM_PED, Game.Player.Character, weapon.Key);                            n++;                        }                    }                 }            }            if (n != 0) { UI.ShowSubtitle("Found ~b~" + n + " ~w~banned weapons.~n~Removed them."); }            else { UI.ShowSubtitle("Everything's fine."); }        }    }}
Edited by ins1de
Link to comment
Share on other sites

[...]

here is the known weapons hash list : http://pastebin.com/0wwDZgkF

[...]

That list is outdated... Use this one:

 

 

{ 0xA2719263, "weapon_unarmed" },{ 0xF9FBAEBE, "weapon_animal" },{ 0x08D4BE52, "weapon_cougar" },{ 0x99B507EA, "weapon_knife" },{ 0x678B81B1, "weapon_nightstick" },{ 0x4E875F73, "weapon_hammer" },{ 0x958A4A8F, "weapon_bat" },{ 0x440E4788, "weapon_golfclub" },{ 0x84BD7BFD, "weapon_crowbar" },{ 0x1B06D571, "weapon_pistol" },{ 0x5EF9FEC4, "weapon_combatpistol" },{ 0x22D8FE39, "weapon_appistol" },{ 0x99AEEB3B, "weapon_pistol50" },{ 0x13532244, "weapon_microsmg" },{ 0x2BE6766B, "weapon_smg" },{ 0xEFE7E2DF, "weapon_assaultsmg" },{ 0xBFEFFF6D, "weapon_assaultrifle" },{ 0x83BF0278, "weapon_carbinerifle" },{ 0xAF113F99, "weapon_advancedrifle" },{ 0x624FE830, "weapon_compactrifle" },{ 0x9D07F764, "weapon_mg" },{ 0x7FD62962, "weapon_combatmg" },{ 0x1D073A89, "weapon_pumpshotgun" },{ 0x7846A318, "weapon_sawnoffshotgun" },{ 0xE284C527, "weapon_assaultshotgun" },{ 0x9D61E50F, "weapon_bullpupshotgun" },{ 0xEF951FBB, "weapon_dbshotgun" },{ 0x3656C8C1, "weapon_stungun" },{ 0x05FC3C11, "weapon_sniperrifle" },{ 0x0C472FE2, "weapon_heavysniper" },{ 0x33058E22, "weapon_remotesniper" },{ 0xA284510B, "weapon_grenadelauncher" },{ 0x4DD2DC56, "weapon_grenadelauncher_smoke" },{ 0xB1CA77B1, "weapon_rpg" },{ 0x166218FF, "weapon_passenger_rocket" },{ 0x13579279, "weapon_airstrike_rocket" },{ 0x687652CE, "weapon_stinger" },{ 0x42BF8A85, "weapon_minigun" },{ 0x93E220BD, "weapon_grenade" },{ 0x2C3731D9, "weapon_stickybomb" },{ 0xFDBC8A50, "weapon_smokegrenade" },{ 0xA0973D5E, "weapon_bzgas" },{ 0x24B17070, "weapon_molotov" },{ 0x060EC506, "weapon_fireextinguisher" },{ 0x34A67B97, "weapon_petrolcan" },{ 0xFDBADCED, "weapon_digiscanner" },{ 0x88C78EB7, "weapon_briefcase" },{ 0x01B79F17, "weapon_briefcase_02" },{ 0x23C9F95C, "weapon_ball" },{ 0x497FACC3, "weapon_flare" },{ 0xBEFDC581, "weapon_vehicle_rocket" },{ 0x48E7B178, "weapon_barbed_wire" },{ 0xFF58C4FB, "weapon_drowning" },{ 0x736F5990, "weapon_drowning_in_vehicle" },{ 0x8B7333FB, "weapon_bleeding" },{ 0x92BD4EBB, "weapon_electric_fence" },{ 0x2024F4E8, "weapon_explosion" },{ 0xCDC174B0, "weapon_fall" },{ 0x364A29EC, "weapon_exhaustion" },{ 0xCC34325E, "weapon_hit_by_water_cannon" },{ 0x07FC7D7A, "weapon_rammed_by_car" },{ 0xA36D413E, "weapon_run_over_by_car" },{ 0x145F1012, "weapon_heli_crash" },{ 0xDF8E89EB, "weapon_fire" },{ 0xDD5DF8D9, "weapon_machete" },{ 0xDB1AA450, "weapon_machinepistol" },{ 0x8BB05FD7, "weapon_flashlight" },{ 0x6D544C99, "weapon_railgun" },{ 0xF9DCBF2D, "weapon_hatchet" },{ 0x7F7497E5, "weapon_firework" },{ 0xBFD21232, "weapon_snspistol" },{ 0xD205520E, "weapon_heavypistol" },{ 0x083839C4, "weapon_vintagepistol" },{ 0xDC4DB296, "weapon_marksmanpistol" },{ 0x0A3D4D34, "weapon_combatpdw" },{ 0x61012683, "weapon_gusenberg" },{ 0xC0A3098D, "weapon_specialcarbine" },{ 0x7F229F94, "weapon_bullpuprifle" },{ 0xC734385A, "weapon_marksmanrifle" },{ 0xF9E6AA4B, "weapon_bottle" },{ 0x47757124, "weapon_flaregun" },{ 0xD8DF3C3C, "weapon_knuckle" },{ 0xA89CB99E, "weapon_musket" },{ 0x3AABBBAA, "weapon_heavyshotgun" },{ 0x63AB0442, "weapon_hominglauncher" },{ 0xAB564B93, "weapon_proxmine" },{ 0x0787F0BB, "weapon_snowball" },{ 0xE232C28C, "weapon_garbagebag" },{ 0x92A27487, "weapon_dagger" },{ 0xC1B3C3D1, "weapon_revolver" },{ 0xDFE37640, "weapon_switchblade" }

 

 

Edited by Unknown_Modder
Link to comment
Share on other sites

DerrikTikmann


First of all, I'd like to say what you did and the response time is absolutely amazing. I had no problems following your code even though I don't have experience of the exact syntax in this programming language. Having seen this, if I could get it working myself I would be very interested to play about with this scripting more if there were some resources to learn from.


Personally I'm happy with the game as it is and want to play through normally but just very frustrated spending time dropping my weapons 1 by 1 just to have them come back when I change sessions so want to find or create a solution.


My idea of including all the weapons in the list and setting the ones you want to keep to 0 was just for universal ease for anyone who used it. Could just as easily created a list of just the weapons to remove or commented out the ones you want to keep from the full list to make the function a bit simpler but I think this solution is good.


So I just have a couple of questions:


Will this setup work with the code and links you have provided, online with the latest version of the game downloaded? - On the Script Hook V page it says this:


Script Hook V is the library that allows to use GTA V script native functions in custom *.asi plugins. Note that it doesn't work in GTA Online, script hook disables custom scripts when player goes in multiplayer.


If so, when the game updates is it essential to download an updated version of Script Hook V?


It looked like from your video, the weapons disappeared rather than be dropped to the ground. Actually I want and think the functionality should be to completely remove them rather than drop them so just checking. For information purposes, what is the command to drop rather than remove... Hash.REMOVE_WEAPON_FROM_PED - Hash.DROP_WEAPON_FROM_PED???


Finally, with a .cs file and the code you have written, does this need to be compiled first or can it be run as is?

Edited by DerrikTikmann
Link to comment
Share on other sites

Will this setup work with the code and links you have provided, online with the latest version of the game downloaded? - On the Script Hook V page it says this:

 

Script Hook V is the library that allows to use GTA V script native functions in custom *.asi plugins. Note that it doesn't work in GTA Online, script hook disables custom scripts when player goes in multiplayer.

No. Well, you can open up ScriptHookV.dll with a Hex Editor and replace 74 3A 48 8D 0D 84 CF 0C 00 E8 DF 48 00 with EB 3A 48 8D 0D 84 CF 0C 00 E8 DF 48 00. Now it will work online but I don't recommend going online with ScriptHookV because it WILL get you banned.

 

If so, when the game updates is it essential to download an updated version of Script Hook V?

Yes.

 

It looked like from your video, the weapons disappeared rather than be dropped to the ground. Actually I want and think the functionality should be to completely remove them rather than drop them so just checking. For information purposes, what is the command to drop rather than remove... Hash.REMOVE_WEAPON_FROM_PED - Hash.DROP_WEAPON_FROM_PED???

You can use SET_PED_DROPS_INVENTORY_WEAPON.

Link to comment
Share on other sites

DerrikTikmann

Thanks for the info. Obviously I don't want to get banned so that's a concern. Is there any way of achieving this dropping weapons functionality without Scripthook?

 

What I don't understand is how I see so many modders online who aren't getting banned, how do they get away with it or are they using a different system?

Link to comment
Share on other sites

They use Mod Menus with the DLL injection method (e.g. Jordans Menu).

Link to comment
Share on other sites

DerrikTikmann

And that way won't allow for custom script such as what you have written?

Link to comment
Share on other sites

Unknown_Modder has pretty well answered to your questions.

I've edited the script so it makes the weapon drop :

using System;using System.Drawing;using GTA;using GTA.Math;using GTA.Native;using System.Collections.Generic;using System.Windows.Forms;namespace RemoveWeapons{    public class Main : Script    {        /* First we need to create our dictionnary which contains all the weapons hashes and their rules         * FYI : - a 'Hash' in GTA V is a Uint32 variable         *       - here is the known weapons hash list : http://pastebin.com/0wwDZgkF          */        public Dictionary<UInt32, int> WeaponsRules = new Dictionary<UInt32, int>();  // (Weapon as Hash, Rule as Int)        public Main() // This function is only called once : at the loading        {            base.Interval = 10; // Interval            KeyDown += OnKeyDown; //Key Handler                       /*Example :              * WeaponsRules.Add(Hash, Int)              *      where Hash is the original Uint32 value and Int the condition (0 = dontRemove, 1=remove)*/            WeaponsRules.Add(0x1B06D571, 1); //Pistol            WeaponsRules.Add(0xBFEFFF6D, 1); //AssaultRifle            // ...        }        public void OnKeyDown(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.F11)            {                CheckInventory();            }        }        public void CheckInventory()        {            int n = 0;            int rule;            foreach (var weapon in WeaponsRules) //loop through our list of weapons            {                if(Function.Call<bool>(Hash.HAS_PED_GOT_WEAPON, Game.Player.Character, weapon.Key, false) == true) //if the player has this weapon in his inventory that is part of the weapon list                {                    if (WeaponsRules.TryGetValue(weapon.Key, out rule)) //read the value that says whether the weapon has to be dropped or not                    {                        if(rule==1) // If rule for this weapon is 'drop' then...                        {							Vector3 somewhere = Game.Player.Character.Position.Around(5F); // Get a random position (X,Y,Z) around the player so that he doesn't pick up instantly what he dropped                            Function.Call(Hash.SET_PED_DROPS_INVENTORY_WEAPON, Game.Player.Character, weapon.Key, somewhere.X, somewhere.Y, somewhere.Z, 0);                             n++;                        }                    }                 }            }            if (n != 0) { UI.ShowSubtitle("Found ~b~" + n + " ~w~banned weapons.~n~Removed them."); }            else { UI.ShowSubtitle("Everything's fine."); }        }    }}
Edited by ins1de
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.