HOWTO :: Work with awsome editable commands
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

HOWTO :: Work with awsome editable commands

Started by Corayzon, 28 May, 2004, 07:35:12

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Corayzon

hey guys...i just wrote this the other day for the new cslave, and thought it fukin rocks!

this is a basic system that shows you how to make COMPLETLY! editable commands and how to call them in a very effective manner.

This script uses the method addCommand(sName, iLevel, sFunc, iArgCount, bReturn) to completly build the commands. This means that commands can be added by hub owners, or they can be returned if another script uses it(multi script support)

-- :: This is built in LUA 4.0
-------------------------------------------------------------------------------------
tCommands = {}
tPrefixs = {}
-------------------------------------------------------------------------------------
-- :: SETTING METHODS
-------------------------------------------------------------------------------------
function addPrefix(sPrefix)
	if sPrefix ~= nil then
		tPrefixs[sPrefix] = 1
	end
end
-------------------------------------------------------------------------------------
function addCommand(sName, iLevel, sFunc, iArgCount, bReturn)
	if sName ~= nil and iLevel ~= nil and sFunc and iArgCount ~= nil then
		tCommands[sName] = {[1] = iLevel, [2] = sInfo, [3] = sFunc, [4] = iArgCount, [5] = bReturn or nil}
	else
		assert(nil, "Error in settings file 'commands.txt' - addCommand()")
	end
end
-------------------------------------------------------------------------------------
-- :: EDITABLE METHODS
-------------------------------------------------------------------------------------
-- :: addPrefix(sPrefix)
addPrefix("+")
-------------------------------------------------------------------------------------
-- :: addCommand(sName, iLevel, sFunc, iArgCount, bReturn)
addCommand("rules", 1, "tUser:SendData(\"dont share porn!\")", 1)
addCommand("kick", 3, "tUser:SendData((arg[1] or \"none\") .. \" - \" .. (arg[2] or \"none\") .. \" - \" .. (arg[3] or \"none\"))", 3, 1)
addCommand("say", 3, "SendToAll(arg[2], arg[3])", 3, 1)
-------------------------------------------------------------------------------------
-- :: SCRIPT START
-------------------------------------------------------------------------------------
function Main()
	frmHub:EnableSearchData(1)
	frmHub:EnableFullData(1)
	if bHideBot == no then frmHub:RegBot(sBot) end
	SetTimer(dInterval)
end

function DataArrival(tUser, sData)
	if strsub(sData, 1, strlen(tUser.sName) + 2) == "<" .. tUser.sName .. ">" then
		local _,_, sMessage = strfind(sData, "%b<>%s+(.*)|")
		if tPrefixs[strsub(sMessage, 1, 1)] == 1 then
			local sCmd = getCommand(sMessage)
			if tCommands[sCmd] then
				local tArgs = buildArgTable(sMessage, tCommands[sCmd][4])
				setglobal("tUser", tUser)
				setglobal("arg", tArgs)
				dostring(tCommands[sCmd][3], "addCommand Error!")
				setglobal("tUser", nil)
				setglobal("arg", nil)
				if tCommands[sCmd][5] then return 1 end
			end
		end
	end
end

function getCommand(sMessage)
	sMessage = "|" .. sMessage
	local _,_, sCmd = strfind(sMessage, "|(%S+)")
	sCmd = strsub(sCmd, 2, strlen(sCmd))
	return sCmd
end

function buildArgTable(sArgs, iArgCount)
	sArgs = "|" .. sArgs .. "|"
	local tOut, iCount = {}, 0
	while 1 do
		if sArgs ~= nil then
			iCount = iCount + 1
			local _, sArg
			if iCount == iArgCount then
				_,_, sArg = strfind(sArgs, "|(.*)|")
			else
				_,_, sArg = strfind(sArgs, "|(%S+)")
			end

			if sArg ~= nil then
				if strsub(sArg, strlen(sArg), strlen(sArg)) == "|" then sArg = strsub(sArg, 1, strlen(sArg) - 1) end
				tOut[iCount] = sArg
				sArgs = "|" .. strsub(sArgs, strlen(sArg) + 3, strlen(sArgs))
			else
				return tOut
			end
		else
			return tOut
		end
	end
end

Corayzon

allright...there is some issues in the above posts script, but i have sorted it all out thankz to the help of a few ppl =]...

will post a new copy in the next few days

SMF spam blocked by CleanTalk