Skip to content
Necroso edited this page Sep 16, 2022 · 11 revisions

Following is a list of useful functions created by users of this plugin and decided to share!

tocolor

Description

This function retrieves the hex number of a specified color.

tocolor( r, g, b, a ) -- alpha is optional

Returns

A single value representing the color.

Function

tocolor = function( r, g, b, a )
    local hexadecimal = '0x'
    local a = a or 255

	for key, value in pairs({r, g, b, a}) do
		local hex = ''

		while(value > 0)do
			local index = math.fmod(value, 16) + 1
			value = math.floor(value / 16)
			hex = string.sub('0123456789ABCDEF', index, index) .. hex			
		end

		if(string.len(hex) == 0)then
			hex = '00'

		elseif(string.len(hex) == 1)then
			hex = '0' .. hex
		end

		hexadecimal = hexadecimal .. hex
	end

	return tonumber(hexadecimal)
end

Example

Event.bind('onPlayerConnect', function( player )
    player:msg( "Welcome to the server " .. player.name .. "!", tocolor(255,255,255) ) -- white
    player:msg( "Don't forget your password.", tocolor(255,0,0) ) -- red
end)

isNumeric

Description

This function checks if a value is of type integer. Equivalent to IsNum from the Squirrel VCMP plugin.

isNumeric(string)

Returns

A boolean indicating whether the text used is integer.

Function

function isNumeric(string)
    if tonumber(string) ~= nil then
        return true
    end
    return false
end

Example

Event.bind('onPlayerCommand' function(player, command, args)
    if command == "test" then
        if not args then player:msg("Please write a text!", 0xFF4040)
        else
            if isNumeric(args) then
                player:msg(args .. " is a numeric value!", 0x90EE90)
            else player:msg(args .. " is not a numeric value!", 0xFFFF00)
            end
        end
    end
end)

Clone this wiki locally