Jump to content

Semi-automatic weapons


Forrest

Recommended Posts

Right, I'm a little bit of a noob to scripting, though I am learning as much and as fast as I can.

Right now, I'm trying to make a script for toggle-able semi-auto/auto firearms, and I'm completely stumped as to how I could do it!

Does anyone have say, an example, or an idea of how I could do it? Thanks, much appreciated!

Link to comment
  • Moderators

CLIENT

function setWeaponFire (key, keyState) 
 if keyState == "down" then 
setControlState(getLocalPlayer(), "fire", true ) 
 elseif keyState == "up" then  
setControlState(getLocalPlayer(), "fire", false ) 
 end 
end 
  
addEventHandler ( "onClientResourceStart", resourceRoot, 
function () 
bindKey ("mouse1", "both",setWeaponFire) 
bindKey ("lctrl", "both",setWeaponFire) 
toggleControl ("fire", false ) 
end) 

OR

server ( not recommended when high ping)

  
function setWeaponFire (key, keyState) 
 if keyState == "down" then 
setControlState(source, "fire", true ) 
 elseif keyState == "up" then  
setControlState(source, "fire", false ) 
 end 
  
addEventHandler ( "onResourceStart", resourceRoot, 
function () 
for _, player in pairs ( getElementsByType 'player' ) do 
bindKey (player,"mouse1", "both",setWeaponFire) 
bindKey (player,"lctrl", "both",setWeaponFire) 
toggleControl ( player, "fire", false ) 
end 
end) 
  
addEventHandler ( "onPlayerJoin", getRootElement( ), 
function () 
bindKey (source,"mouse1", "both",setWeaponFire) 
bindKey (source,"lctrl", "both",setWeaponFire) 
toggleControl ( source, "fire", false ) 
end) 
  

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...