Jump to content

Useful LUA Snippets


Frequency

Recommended Posts

I didn't see any other collaborative snippet dipository, so I thought here would probably be the most appropriate place to post. With this aside, post your useful snippets here! They could be funny, wacky, interesting, useful for other scripters, or all of the above?! Let your imagination roll.

Please try to keep this topic as clean as possible. That means, refrain from getting off-topic, refrain from posting snippets already provided, and refrain from not complying to the forum rules! Ensure you have fully commented your code too (this is nessesary, as this is supposed to be an educational experience too ;) ). I'll get the ball rolling:

Simple Key Binder

This snippet allows users on your server to create binds for their keys, to display text in the chat window.

-- The bind parser.
function parseSayBind ( source, key, keyState , cmd, say)
   -- Send all clients a message in the chatbox, with the user's nick and binded text.
   outputChatBox ( getClientName ( source ) .. ": " .. say)
end

-- The command parser
function bindSay ( source , cmd , key, say)
   -- Check to see if the command has correct parameters.
   if not key or not say then
       -- Tell the player he/she has entered the command incorrectly.
       outputChatBox ( "/bindsay [key] [text]", source, 255, 0, 0 )
       return 1
   end
   -- Set the key to be binded.
   bindKey ( source, key, "down", parseSayBind , cmd, say)   
end

-- /bindsay [key] [text]
addCommandHandler ( "bindsay", bindSay )

Link to comment

Anti-Minigun

Stop unwanted minigun users on your server!

  
function removeMinigun ( previousID, newID ) 
    if newID == 38 then 
        takeWeapon(getRootElement(), 38 ) 
    end 
end 
  
addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), removeMinigun ) 
  

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...