player:SetActiveWeapon() : nothing change and question

Hi all, i’m back !

So, i’m still at my inventory, witch i’m reaching the end, this time for one problem and one question :

  • My problem : Like said in the title, when i try to call ply:SetActiveWeapon(nil) or to any weapon, it changes nothing ; no errors, simply nothing changes… So my goal is to range an item from the player’s switch to his inventory, the item is succefully sended in my inventory but the weapon is not dissapearing from switch…

  • Now the question :
    So it’s a little bit hard to explain, so you know i need to save inventory data ; to do that i will use a C++ DLL. But i forgott to ask you were can i get garry’s headers files ? And were do i get a the binnarys needed for compilation ? Because Visual Studio 2012 will not be able to compile without the headers files and binarries.
    After the last thing is how do i do to pass args from lua to C++ and inverse ? I never used any Lua or Scripting librarys in C++ The only librarys i use are Direct3D or OpenGL.

It is actually:


_p:Give("admin_baton");
_p:SelectWeapon("admin_baton");

I want to remove the current player weapon ! Not adding him a new one !!

TTT uses another weapon to ‘holster’ weapons, maybe try doing that?
It uses a SWEP that has no model showing is what I mean

Yes but i can’t use a weapon… I need the slot to be empty, completely empty, no weapons, no fake weapons…

In plus the ply:SetActiveWeapon is not working in all cases : not changing when you try to put an existing weapon, doesn’t change when you put nil. This function simply does nothing, so it means that i can’t change current weapon and i can’t remove it…

I need so a function that WORKS !!

You could do this:

Where _p is Player…

Give the player a weapon ( or base of a weapon which shouldn’t take up any slot ), select it, then remove it…

It isn’t ideal, but it works… It happens so fast that the player doesn’t notice. I just tested it with my system ( which does the putting-weapon-away animation before pulling next weapon out ) and it works just fine.

The only thing you may encounter is weapon_base gives you pistol ammo; use a different base that won’t give ammo.


_p:Give( "weapon_base" );
_p:SelectWeapon( "weapon_base" );
_p:StripWeapon( "weapon_base" );

No problem !! I found a way ; a hacky way… I’m using a function that parse every entities of the map, and if it’s the current held item then i call entity:remove() ! And it’s working the weapon is dissapearing.

So now it rest last thing about inventory : the save/load system. To do that i need C++ dll. It’s not realy hard for me to do… However i said that i never used any scripting librarys in C++, so i don’t know how to pass args to lua and call functions, and of curse the inverse way calling C++ function from lua.
Also, i will need garry’s headrers files and binarys too.

What are you creating a module for? Maybe an alternative already exists.

Ah, if you wanted to store it in an inventory on holster, then just GetActiveWeapon( ) and remove it after getting the relevant information such as ammo type, ammo in mag, ammo total, gun type, etc…

You don’t need a C++ module to make an inventory system.

You can use util.JSONToTable when you read the file, make sure you do an || “{ }” to have a new table made if the file is empty… and util.TableToJSON when saving the file. All of it can be done on the server.

Alternatively, you can use SQLite database using SetPData and GetPData on the player. Or, you can use MySQL ( for which you do need a module, but MySQLOO and TMySQL both exist and work well ).

No problem i succeeded ! I made a file saved at the steamid of the player that contains a list of ItemID’s.

So done.