LUA:Using Tables in Lua

From GMod Wiki

Revision as of 19:41, 21 August 2010 by Donkie (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Warning 64 severe.pngThis page has multiple issues.
See the Page Details section for information.


You can create a table by simply typing local TableName = { }
In the { } you can place data, be sure to use commas!


To execute the stuff you will need to use string.find and for commands which will be showed in the example below.

DescriptionDisables the listed props
Used onNewerServer.png
Code
 
Here is an example:
local Models = { "models/props_combine/CombineTrain02b.mdl", //Declares the start of the table
"models/props_combine/CombineTrain02a.mdl",//Add a prop
"models/props_combine/CombineTrain01.mdl" };//Add last prop and finish table
 
local function BlockProps( Player, Model )//Create the function
	for _, Value in pairs( Models ) do// If found run do
		if string.find( Model, Value ) then //Finds the string
			return false; //Returns pop false
		end //ends the for
	end //ends the if
end //ends the function
hook.Add( "PlayerSpawnProp", "BlockProps", BlockProps ); //Creates the hook on PlayerSpawnProp
 
OutputChecks if the prop is on the table and disables spawning of that prop


Page Details

Mess.pngThis page has been deemed a mess. It may contain unnecessary information or be poorly organized. You can discuss changes on this article's talk page.
Warning 64.pngThis page needs to be edited as it contains information that is unclear or incorrect. Improvement can be discussed on the talk page. Find more pages that need work here.
Details: None given.
Stub.pngThis article is a stub.
You can help the GMod Wiki by expanding it.
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox