A use gun

can someone make me a gun that will simulate hiting the use key

basically rather than walking up to an object and hitting my use key, shoot it from a distance

I want this for cool early door opening and for activating some entities from far away

[editline]16th January 2011[/editline]

it does not have to look special, its mainly for single player use

[lua]
if ( SERVER ) then

AddCSLuaFile( "shared.lua" )

end

if ( CLIENT ) then

SWEP.PrintName = "Use Gun"
SWEP.Slot = 0
SWEP.SlotPos = 0
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true

end

SWEP.Spawnable = true // set to false if you want this weapon admin only
SWEP.AdminSpawnable = true

SWEP.Author = “Shen, requested by imptastick”
SWEP.Contact = “”
SWEP.Purpose = “Use things from far away.”
SWEP.Instructions = “Aim on anything usable and click to use.”

SWEP.ViewModel = “models/weapons/v_pistol.mdl”
SWEP.WorldModel = “models/weapons/w_pistol.mdl”

SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = “none”

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “none”

function SWEP:Think() // This is the heart of the code.

if ( self.Owner:KeyDown( IN_ATTACK ) ) then // This checks if the owner is holding MOUSE1

	self.Owner:ConCommand( "+use" ) // If so, we'll make him run the use command.
	
else // Else, if he's not..

	self.Owner:ConCommand( "-use" ) // This cancels our use command.
	
end

end

function SWEP:PrimaryAttack()

// does nothing

end

function SWEP:SecondaryAttack()

// does nothing

end

function SWEP:Reload()

// does nothing

end
[/lua]

http://www.garrysmod.org/img/?t=dll&id=116542

[editline]16th January 2011[/editline]

Tested and working.

Shen, why you rate undefined late? Atleast he provides a fully working addon.

Also, mine actually works over a distance. Making the player run +use from a distance will do nothing.

This might come in handy…

thank you sir, plus 1000 awesome points