how to make Prefix?
 

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

how to make Prefix?

Started by Madman, 08 May, 2004, 01:07:39

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Madman

Hi, i am working on a little ascii bot... =)
just to learn some lua but most becuse i am bored....

If some one use the command !lol
It show a ascii picture

but i want it to respond to +lol and !lol
something like

Prefix = "!" and "+"
if cmd == Prefix"lol" then

But i dont know how to do that...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Corayzon

hey... you can use a table to achieve this like so...

-- Defines a table
Prefix = {}

-- Adds + to the table and sets it to 1
Prefix["+"] = 1

-- Adds ! to the table and sets it to 1
Prefix["!"] = 1

then u would do the following to execute on one of the prefixs...

Prefix = {}
Prefix["+"] = 1
Prefix["!"] = 1

-- if cmd not equal nil
if cmd ~= nil then 

	-- if the first char in command is equal to 1
	if Prefix[strsub(cmd, 1, 1) == 1 then

		-- remove the prefix from the cmd
		cmd = strsub(cmd, 2, strlen(cmd) - 1)
		

	end
end

and now you check for the command name and do whatever u like

Prefix = {}
Prefix["+"] = 1
Prefix["!"] = 1

-- if cmd not equal nil
if cmd ~= nil then 
	if Prefix[strsub(cmd, 1, 1) == 1 then
		cmd = strsub(cmd, 2, strlen(cmd) - 1)

		if cmd == "lol" then
			-- put ur code here
		end
	end
end

hope this helps ;)

Madman

#2
I cant get it to work...

I tested with this code

Bot = "Doo"

--// This function is fired at the serving start
function Main()
	frmHub:RegBot(Bot)
end
Prefix = {}
Prefix["+"] = 1
Prefix["!"] = 1


--// This function is fired when a new data arrives
function DataArrival(curUser,data)
	if strsub(data, 1, 1) == "<" then
	data=strsub(data,1,strlen(data)-1)
	s,e,cmd = strfind(data,"%b<>%s+(%S+)")
-- if cmd not equal nil
if cmd ~= nil then 
if Prefix[strsub](cmd, 1, 1) == 1 then
cmd = strsub(cmd, 2, strlen(cmd) - 1) --//line 20
if cmd == "lol" then
SendToAll(Bot,"Wooo")

end
end
end
end
end
Got the error
Syntax error: attempt to call a nil value
stack traceback:
   1:  function `DataArrival' at line 20 [file `D:\Program\Hub\PtokaX-0.330\scripts\prfix.lua']

And btw you forgot the ] in this line =)
if Prefix[strsub](cmd, 1, 1) == 1 then
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Corayzon

wops...i never really test the shit i put helping other ppl but...

if Prefix[strsub(cmd, 1, 1) == 1 then

should have been

if Prefix[strsub(cmd, 1, 1)]= 1 then

and

cmd = strsub(cmd, 2, strlen(cmd) - 1)

shoulda been

cmd = strsub(cmd, 2, strlen(cmd))


so here the complete script with dataarrival

Prefix = {}
Prefix["+"] = 1
Prefix["!"] = 1

function DataArrival(user, data)

	data = strsub(data, 1, strlen(data) -1) 
	local _,_,cmd=strfind(data, "%b<>%s+(%S+)")

	if cmd ~= nil then
		if Prefix[strsub(cmd, 1, 1)] == 1 then
			cmd = strsub(cmd, 2, strlen(cmd))

			if cmd == "lol" then
				user:SendData("testing", "lol called!")
			end
		end
	end
end

;)

Madman

Thanx i got it working now =)
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

SMF spam blocked by CleanTalk