-
Notifications
You must be signed in to change notification settings - Fork 1
Useful Functions
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!
This function retrieves the hex number of a specified color.
tocolor( r, g, b, a ) -- alpha is optionalA single value representing the color.
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)
endEvent.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)This function checks if a value is of type integer. Equivalent to IsNum from the Squirrel VCMP plugin.
isNumeric(string)A boolean indicating whether the text used is integer.
function isNumeric(string)
if tonumber(string) ~= nil then
return true
end
return false
endEvent.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)