• I need help with some code, that I cant solve.
    7 replies, posted
Hello! I'm DrFineSir, and i'm working on this addon but I came across a problem. Let me try to explain. Lets say there is an entity, this entity can be picked up and put into your hotbar. BUT when you pick it up you have to place it back down and cant't use anything else, the only thing you can do is place this down, meaning you cant use any weapons or tools, the only thing you can do is place it down. When you place it back down you then have access to use your weapons again. I can't think of how I should do this. Anyone willing to help? Example: A ammo box can be placed down for your team to use. But you can pick it up and pack it to move somewhere else. But can't use any tools, weapons, ect, only place it down before you have access to use your weapons/tools ect. [B]SORRY FOR BAD WORDING ENGLISH IS NOT MY MAIN LANGUAGE![/B] I'm hoping you guys can help me do this..
[QUOTE=DrFineSir;50380350]Hello! I'm DrFineSir, and i'm working on this addon but I came across a problem. Let me try to explain. Lets say there is an entity, this entity can be picked up and put into your hotbar. BUT when you pick it up you have to place it back down and cant't use anything else, the only thing you can do is place this down, meaning you cant use any weapons or tools, the only thing you can do is place it down. When you place it back down you then have access to use your weapons again. I can't think of how I should do this. Anyone willing to help? Example: A ammo box can be placed down for your team to use. But you can pick it up and pack it to move somewhere else. But can't use any tools, weapons, ect, only place it down before you have access to use your weapons/tools ect. [B]SORRY FOR BAD WORDING ENGLISH IS NOT MY MAIN LANGUAGE![/B] I'm hoping you guys can help me do this..[/QUOTE] Well one way (If I think your trying to do what your doing) could be to make a backup of the players weapons, Then strip them. Once they have placed it, Give them there weapons back. For example : [CODE]function BackupWeapons(ply) --Remove all there weapons ply.backupWeapons = ply:GetWeapons() --Back them up on the player ply:StripWeapons() --Strip all there weapons end function RestoreWeapons(ply) --Give them all back if ply.backupWeapons then for k ,v in pairs(ply.backupWeapons) do p:Give(v) --Give them all there weapons back end end end[/CODE] The code is untested but something along them lines should be what your looking for, good luck.
[QUOTE=0V3RR1D3;50382287]Well one way (If I think [del]your[/del] [B]you're[/B] trying to do what your doing)[/QUOTE] I don't think that's what he's trying to do... he means that he wants to be able to access and use his weapons and tools while holding a prop, which he can't do until he puts the prop back down (since they get hidden). I'm not 100% sure, but I don't think that is possible to code in, since I believe it's a default engine thing that can't be changed
[QUOTE=MPan1;50382300]I don't think that's what he's trying to do... he means that he wants to be able to access his weapons (as in shoot, have the weapon visible, etc) while holding a prop, which he can't do until he puts the prop back down. I'm not 100% sure, but I don't think that is possible to code in, since I believe it's a default engine thing that can't be changed[/QUOTE] Yeh sorry about the spelling, Im dyslexic, And from the way he worded it that is what it seems. My bad for misreading. But yeh I can imagine engine changes would be needed for that. Alternatively you could write your own script for picking up objects and allowing them to shoot with it.
Actually, I think I thought of a way to fake the picking-up thing so the weapon will still be available (using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/AllowPlayerPickup]GM:AllowPlayerPickup[/url])... I'll just test some stuff and get back to you Also 0V3RR1D3, sorry for being a spelling nazi
So, i think, you must create a simple SWEP for this entity. Then you can simply block holstering by [url]http://wiki.garrysmod.com/page/WEAPON/Holster[/url]
Right, I've been trying all kinds of nonsense for ages now and the closest I've got is this: [CODE] hook.Add( 'AllowPlayerPickup', 'testpickup', function( ply, ent ) ply:SendLua( "LocalPlayer():GetActiveWeapon():RemoveEffects( EF_NODRAW )" ) -- unhides the world model ply:SendLua( "LocalPlayer():GetViewModel(0):RemoveEffects( EF_NODRAW )" ) -- doesn't seem to do anything end ) hook.Add( "KeyPress", "pickupshoottest", function( ply, key ) if ( key == IN_ATTACK ) then ply:DoAttackEvent() -- doesn't actually fire the weapon (why is this so hard to do?) end end ) [/CODE] And all that does is show the weapon's worldmodel when you're holding a prop rather than it being hidden, which is far from helpful, I know :( [editline]24th May 2016[/editline] Yeah, as the post above says, it's probably a better idea to use a SWEP for this... although it would be good to have this done without one
thanks
Sorry, you need to Log In to post a reply to this thread.