Similar topics
    Search
     
     

    Display results as :
     


    Rechercher Advanced Search

    Latest topics
    » Hey guys.........
    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

    Navigation
     Portal
     Index
     Memberlist
     Profile
     FAQ
     Search

    Some functions that can serve

    Go down

    Some functions that can serve

    Post by Starkkz on Fri Jun 11, 2010 3:29 pm

    Table Find - Function: find a value in a table
    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 Very Happy
    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

    View user profile

    Back to top Go down

    Re: Some functions that can serve

    Post by Debt on Wed Jul 07, 2010 8:58 pm

    More Powerful Scripts:

    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
    Imprints all values in a table to another table.

    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
    As many people know, when you try to print a table, it creates a table memory value, unhelpful to the process, this one prints the values in it.

    Debt

    Posts : 10
    Rep : 0
    Join date : 2010-06-13

    View user profile

    Back to top Go down

    Back to top

    - Similar topics

     
    Permissions in this forum:
    You cannot reply to topics in this forum