Search
Latest topics
Some functions that can serve
2 posters
Monolith Forums :: Scripting :: Scripts
Page 1 of 1
Some functions that can serve
Table Find - Function: find a value in a table
String Split - Function: split a word every space
Sound 3 X, Y - Function: make a sound in a position -- This is made by Me
- Code:
function table.find(t,v)
if type(t)=="table" then
for _, value in ipairs(t) do
if value == v then
return true
end
end
end
return false
end
String Split - Function: split a word every space
- Code:
function string.split(t,b)
local cmd = {}
if not b then match = "[^%s]+" else match = "[^"..b.."]+" end
for word in string.gmatch(t,match) do
table.insert(cmd,word)
end
return cmd
end
Sound 3 X, Y - Function: make a sound in a position -- This is made by Me
- Code:
function sound3(file,x,y)
for _, id in pairs(player(0,"table")) do
local dist = math.sqrt((player(id,"x")-x)^2 + (player(id,"y")-y^2))
if dist < 150 then
parse("sv_sound2 "..id.." "..file)
end
end
end
Starkkz- Posts : 30
Rep : 0
Join date : 2010-06-11
Re: Some functions that can serve
More Powerful Scripts:
Script by weiwen:
Script by Weiwen:
Script by weiwen:
- Code:
function deepcopy(object)
local lookup_table = {}
local function _copy(object)
if type(object) ~= "table" then
return object
elseif lookup_table[object] then
return lookup_table[object]
end
local new_table = {}
lookup_table[object] = new_table
for index, value in pairs(object) do
new_table[_copy(index)] = _copy(value)
end
return setmetatable(new_table, getmetatable(object))
end
return _copy(object)
end
Script by Weiwen:
- Code:
function table.tostring( tbl )
local result, done = {}, {}
for k, v in ipairs( tbl ) do
if k ~= 'tmp' then
table.insert( result, table.val_to_str( v ) )
done[ k ] = true
end
end
for k, v in pairs( tbl ) do
if not done[ k ] then
table.insert( result,
table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
end
end
return "{" .. table.concat( result, ", " ) .. "}"
end
Debt- Posts : 10
Rep : 0
Join date : 2010-06-13
Monolith Forums :: Scripting :: Scripts
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Fri Sep 09, 2011 4:58 pm by WhiteWolf
» Last to post wins
Fri Sep 09, 2011 4:57 pm by WhiteWolf
» COMBAT ARMS WOOOOO
Tue Oct 19, 2010 10:59 pm by viperjake31
» Its over (Bye)
Wed Sep 22, 2010 10:05 pm by Supanooba
» Sorry guys...
Wed Sep 22, 2010 10:01 pm by Supanooba
» bad feeling...
Tue Sep 21, 2010 1:16 pm by Supanooba
» This game...
Sun Sep 19, 2010 10:01 am by Supanooba
» Me, D@rk T3mpl4r, Hacking?
Sun Sep 19, 2010 12:36 am by D@rk T3mpl4r
» fractured my arm and leg
Sat Sep 18, 2010 9:08 pm by Supanooba