Rewriting MasterChat
 

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

Rewriting MasterChat

Started by Smulf, 12 January, 2004, 19:58:36

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Smulf

Hi all;

I have 6 profiles; Owner, Admin, Pro_OP, Nor_OP, VIP and Reg. Yesterday I got a script for Master chat room ONLY masters. Is it posible to rewrite the script so it is ONLY Owner, Admin and Pro_OP that can talk to each other trough the chat bot?

The script is like this:

-- Master-Chat
-- Original VipChat v1.0 
-- By Guibs 10/11/2003
-- Enjoy :)
-- Simple Modify by NightLitch
-- to Master Bot Only

------------------
-- Main Function --
------------------
function Main()
	OPCHAT = "OP_MChat"
	frmHub:RegBot(OPCHAT)
end

------------------
-- Data Arrival --
------------------

function DataArrival(user,data)
	if(strsub(data,1,4) == "$To:") then
		s,e,whoTo = strfind(data,"$To:%s+(%S+)")
		if whoTo == OPCHAT then
			if user.iProfile == 0 then
				s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)
			end
		end
	end
end

function MasterChatRoom(user,msg)
	local allprofiles = GetProfiles()
	local index, profile, index2, nick
	for index, profile in allprofiles do
		local users = GetUsersByProfile(profile)
		for index2, nick in users do
			local usr = GetItemByName(nick)
			if usr ~= nil then
				if user.sName == usr.sName then
				else
					if usr.iProfile == 0 then
						usr:SendData("$To: "..usr.sName.." From: "..OPCHAT.." $<"..user.sName.."> " ..msg)
					end
				end
			end
		end
	end
end
[Smulf]

SaintSinner

what does your profiles.dat look like?
i think the scripters are going to need the profile #s
since you have added other profiles.
   


Smulf

It's like this. The Nor_OP is the last one els it would run some conflicts with the reg user script.

0|Owner|11111111111111111111000000000000
1|Admin|11110111011111111111000000000000
2|Pro_OP|11110110011101111111000000000000
3|Reg|10000000000000000000000000000000
4|VIP|10000000000001111000000000000000
5|Nor_OP|10110100011001111100000000000000

Thanks for fast reply:)
[Smulf]

SaintSinner

#3
well this is my first attempt at modding a script,
it just turned out to be a cut and paste job,
took me all day to figure it out,
but it works on my system
I hope the more experienced scripters can
maybe make it more efficient.
guys if i did anything wrong please let me know
but it works.
Thanks for the lessons guys.

-- Master-Chat
-- Original VipChat v1.0 
-- By Guibs 10/11/2003
-- Enjoy :)
-- Simple Modify by NightLitch
-- to Master Bot Only
-- Simple Mod by SaintSinner thanks to phatty for the lessons


------------------
-- Main Function --
------------------
function Main()
	OPCHAT = "OP_MChat"
	frmHub:RegBot(OPCHAT)
end

------------------
-- Data Arrival --
------------------

function DataArrival(user,data)
	if(strsub(data,1,4) == "$To:") then
		s,e,whoTo = strfind(data,"$To:%s+(%S+)")
		if whoTo == OPCHAT then
			if user.iProfile == 0 then
				s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)			
			elseif user.iProfile == 1 then
				s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)
			elseif user.iProfile == 2 then
				s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)
			end
		end
	end
end

function MasterChatRoom(user,msg)
	local allprofiles = GetProfiles()
	local index, profile, index2, nick
	for index, profile in allprofiles do
		local users = GetUsersByProfile(profile)
		for index2, nick in users do
			local usr = GetItemByName(nick)
			if usr ~= nil then
				if user.sName == usr.sName then
				else
					if usr.iProfile == 0 then
						usr:SendData("$To: "..usr.sName.." From: "..OPCHAT.." $<"..user.sName.."> " ..msg)
					elseif usr.iProfile == 1 then
						usr:SendData("$To: "..usr.sName.." From: "..OPCHAT.." $<"..user.sName.."> " ..msg)
					elseif usr.iProfile == 2 then
						usr:SendData("$To: "..usr.sName.." From: "..OPCHAT.." $<"..user.sName.."> " ..msg)
					end
				end
			end
		end
	end
end
   


plop

here's a hint saintsinner.
Levels= {["0"]=1, ["1"]=1}

if Levels[user.iProfile] then
should be easy now.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

pHaTTy

QuoteOriginally posted by plop
here's a hint saintsinner.
Levels= {["0"]=1, ["1"]=1}

if Levels[user.iProfile] then
should be easy now.

plop

hmm i dont see the point of adding a table for a simple "or" job ;)
Resistance is futile!

plop

QuoteOriginally posted by (uk-kingdom)pH?tt?
QuoteOriginally posted by plop
here's a hint saintsinner.
Levels= {["0"]=1, ["1"]=1}

if Levels[user.iProfile] then
should be easy now.

plop

hmm i dont see the point of adding a table for a simple "or" job ;)
if usr.iProfile == 0 or usr.iProfile == 1 or usr.iProfile == 2 then

if Levels[user.iProfile] then

well the table is shorter, so less typing and results that any1 can modify it easely 2 there needs.
nomather what profile numbers some1 uses all they have 2 do is add the profile numbers they want 2 be able 2 use the chat 2 the table.
but yes i know, i'm a table junky. lol

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

pHaTTy

Loooool ok you got me, but table is slower, altho its easier i suppose :P

better ay todo it actually and its unnoticable the difference in speed.....
Resistance is futile!

Smulf

Thx SaintSinner for using a hard days work I appreciate it very much, but I can only get it working it if "Owners" are talking trough it... Could it have something to do with:

            
s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)			
			elseif user.iProfile == 1 then
				s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)
			elseif user.iProfile == 2 then
				s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)



It's just a wild guess, but thx any way... And thx to Plop and UK for pasting codes, though I don't no what they are for:)
[Smulf]

SaintSinner

#9
i just tested and it works with the profile data that you posted, i setup 3 diffrent acct on three diffrent clients,
and i was able to chat with all off them,
did you do a hub restart?
or a restart scripts?
if not that may help.

here from the chat window:


[13:14] testowner
[13:15] testadmin
[13:15] testnor
   


SaintSinner

and i got it working with no owner in the hub


[13:26] test no owner signed into hub
[13:26] return test
   


Smulf

Yeh I'v tried to restart the scripts and the program, but it's seems that non of it works...  Well right now I'm trying to get it to work...
[Smulf]

Smulf

Wird I think I'v must have saved it the wrong way, cause when I opned it again it was the old script... Of cause now it works:) Why didn't I trust U:D Thanks alot for the help SaintSinner...
[Smulf]

SaintSinner

QuoteOriginally posted by Smulf
Wird I think I'v must have saved it the wrong way, cause when I opned it again it was the old script... Of cause now it works:) Why didn't I trust U:D Thanks alot for the help SaintSinner...


no problem, im glad it works for you.
   


SaintSinner

taking a hint from plop, and phatty,
this will also work:

-- Master-Chat
-- Original VipChat v1.0 
-- By Guibs 10/11/2003
-- Enjoy :)
-- Simple Modify by NightLitch
-- to Master Bot Only
-- Simple Mod by SaintSinner thanks to phatty for the lessons


------------------
-- Main Function --
------------------
function Main()
	OPCHAT = "OP_MChat"
	frmHub:RegBot(OPCHAT)
end

------------------
-- Data Arrival --
------------------

function DataArrival(user,data)
	if(strsub(data,1,4) == "$To:") then
		s,e,whoTo = strfind(data,"$To:%s+(%S+)")
		if whoTo == OPCHAT then
			if user.iProfile == 0 or user.iProfile == 1 or user.iProfile == 2 then 
				s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)			
			
			end
		end
	end
end

function MasterChatRoom(user,msg)
	local allprofiles = GetProfiles()
	local index, profile, index2, nick
	for index, profile in allprofiles do
		local users = GetUsersByProfile(profile)
		for index2, nick in users do
			local usr = GetItemByName(nick)
			if usr ~= nil then
				if user.sName == usr.sName then
				else
					if user.iProfile == 0 or user.iProfile == 1 or user.iProfile == 2 then
						usr:SendData("$To: "..usr.sName.." From: "..OPCHAT.." $<"..user.sName.."> " ..msg)

					end
				end
			end
		end
	end
end



I dont know if this is more efficient, but i was just messing around....

plop,
why would you do this

Levels= {["0"]=1, ["1"]=1}

if Levels[user.iProfile] then

is this telling the script that levels 0 and level 1 are both equal to level 1?
   


plop

QuoteOriginally posted by SaintSinner
plop,
why would you do this

Levels= {["0"]=1, ["1"]=1}

if Levels[user.iProfile] then

is this telling the script that levels 0 and level 1 are both equal to level 1?
the 1 is just a dummy vallue, you can use anything BUT nil here.
execute the next code with the lua command line, it whill give you a nice example whats going on.
table= {[1]=1, [5]=1, [2]=1, [9]=1, [4]=1 }

for i=1, 10 do
   if table[i] then
      print(i.." is in the table")
   else
      print(i.." isn't in the table")
   end
end
plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SaintSinner

darn i cant figure this out, i been trying this for 2 days
can i get a hint or a little more bump in the right direction, :D

------------------
-- Main Function --
------------------
function Main()
	OPCHAT = "OP_MChat"
	frmHub:RegBot(OPCHAT)
end
Levels= {["0"]=1, ["1"]=1, ["2"]=1,}

------------------
-- Data Arrival --
------------------

function DataArrival(user,data)
	if(strsub(data,1,4) == "$To:") then
		s,e,whoTo = strfind(data,"$To:%s+(%S+)")
		if whoTo == OPCHAT then
			if Levels[user.iProfile] then 
				s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)			
			
			end
		end
	end
end

function MasterChatRoom(user,msg)
	local allprofiles = GetProfiles()
	local index, profile, index2, nick
	for index, profile in allprofiles do
		local users = GetUsersByProfile(profile)
		for index2, nick in users do
			local usr = GetItemByName(nick)
			if usr ~= nil then
				if user.sName == usr.sName then
				else
					if Levels[user.iProfile] then 
						usr:SendData("$To: "..usr.sName.." From: "..OPCHAT.." $<"..user.sName.."> " ..msg)

					end
				end
			end
		end
	end
end


i cant get it to work using the tables that plop suggesterd, im not going to be using it i just want to
practice.
   


plop

your really close saintsinner.
check this it's from the scripting.txt.

iProfile      - (number) users profile index or -1 for normal user. Use GetProfileName(index) to get the profile name string

your table holds ....... (wouldn't be a hint if i would say what it holds).
thats all i'm gone say.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SaintSinner

i thought i was close
i tried many diffrent variables syntaxes
but this one made the most sense but it
does not work.....
------------------
-- Main Function --
------------------
function Main()
	OPCHAT = "OP_MChat"
	frmHub:RegBot(OPCHAT)
end
Levels= {["0"]=1, ["1"]=1, ["2"]=1,}

------------------
-- Data Arrival --
------------------

function DataArrival(user,data)
	if(strsub(data,1,4) == "$To:") then
		s,e,whoTo = strfind(data,"$To:%s+(%S+)")
		if whoTo == OPCHAT then
			if Levels[user.iProfile] then 
				s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)			
			
			end
		end
	end
end

function MasterChatRoom(user,msg)
	local allprofiles = GetProfileName(Levels)
	local index, profile, index2, nick
	for index, profile in allprofiles do
		local users = GetUsersByProfile(profile) 
		for index2, nick in users do
			local usr = GetItemByName(nick)
			if usr ~= nil then
				if user.sName == usr.sName then
				else
					if Levels[user.iProfile] then 
						usr:SendData("$To: "..usr.sName.." From: "..OPCHAT.." $<"..user.sName.."> " ..msg)

					end
				end
			end
		end
	end
end
   


plop

ok another hint.
iProfile returns a number, your table holds strings.
change the table 2 numbers and it comes alive.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SaintSinner

#20
ITS ALIVE, ITS ALIVE
I think i got it
i dont know if this is what you meant
but it works for all profiles given and are able to chat.

function Main()
	OPCHAT = "OP_MChat"
	frmHub:RegBot(OPCHAT)
end
Levels= { [0]=0, [1]=0, [2]=0, }
------------------
-- Data Arrival --
------------------

function DataArrival(user,data)
	if(strsub(data,1,4) == "$To:") then
		s,e,whoTo = strfind(data,"$To:%s+(%S+)")
		if whoTo == OPCHAT then
			if Levels[user.iProfile] then 
				s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
				MasterChatRoom(user,msg)			
			
			end
		end
	end
end

function MasterChatRoom(user,msg)
	local allprofiles = GetProfiles()
	local index, profile, index2, nick
	for index, profile in allprofiles do
		local users = GetUsersByProfile(profile)
		for index2, nick in users do
			local usr = GetItemByName(nick)
			if usr ~= nil then
				if user.sName == usr.sName then
				else
					if Levels[user.iProfile] then 
						usr:SendData("$To: "..usr.sName.." From: "..OPCHAT.." $<"..user.sName.."> " ..msg)

					end
				end
			end
		end
	end
end


anything i could have done better?.. or am i totally wrong in the way i did it?
   


NightLitch

nice. You have learnd something new... :-)

it is in my eyes correct.
//NL

plop

QuoteOriginally posted by SaintSinner
ITS ALIVE, ITS ALIVE
I think i got it
i dont know if this is what you meant
but it works for all profiles given and are able to chat.

anything i could have done better?.. or am i totally wrong in the way i did it?
thats 100% like i ment.

you earned a stickertje (hope i spelled that right). lol

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SaintSinner

WOW,...a sticker from plop
SAWEEETTT...

no really, thanks for the help.. im learning alot.
 :D  :D  :D  :D  :D
   


NightLitch

Well you could get a lollipop from me if you want. ;-D hehe

Strawberry tase...  lol...

Damn am twisted sometimes. :-P
//NL

SMF spam blocked by CleanTalk