PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: HappyTheMan on 12 September, 2006, 00:52:32

Title: Master chat don't work
Post by: HappyTheMan on 12 September, 2006, 00:52:32
Hi there!
I have found the script master chat by hawk. I changed it a bit to be able to create a chat room for OPs and Unregged users only. Problem: when the unregged chats,  OPs get the msg but when one OP chats, the unregged doesn't get the msg. What is weird is that the pb only appears with unregged users. It works fine with vips masters etc.. Of course all my other scripts are turned off.
Here is the script:

ChatRoomName = "#Garden_(GUEST-Chat)"
ChatProfiles = {
[-1] = 1, -- Guest
[0] = 1, -- Master
[1] = 1, -- Operator
[2] = 0, -- VIP
[3] = 0, -- Reg
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
}


-- Do not edit below
-- -----------------

function Main()
   frmHub:RegBot(ChatRoomName)
end

function ToArrival(user,data)
s,e,whoTo = string.find(data,"$To:%s+(%S+)")
if whoTo == ChatRoomName then
if ChatProfiles[user.iProfile] == 1 then
s,e,whoTo,from,msg = string.find(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")
MasterChatRoom(user,msg)
else
user:SendData("$To: "..user.sName.." From: "..ChatRoomName.." $You don't have the right to chat here. Your message has not been sent")
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 ChatProfiles[usr.iProfile] == 1 then
usr:SendData("$To: "..usr.sName.." From: "..ChatRoomName.." $<"..user.sName.."> " ..msg)
else
return 1
end
end
end
end
end
end


thx for your help :-)
Title: Re: Master chat don't work
Post by: HappyTheMan on 12 September, 2006, 06:21:51
Thx again and again Mutor. Or maybe i should call you Mentor because you are always the one who reply my topics LOL.
I will study that table thing!
I know its not really the goal of the Masterchat but I prefer modify scripts intsead of just taking new ones because it helps me learning this LUA langage. I am having much fun doing it :-)
Posted on: 12 September 2006, 04:28:42
ok so I wrote this:
function ChatRoom(user,msg)
for i,nick in frmHub:GetOnlineUsers() do
if user.sName ~= nick.sName and ChatProfiles[nick.iProfile] == 1 and user.sName ~= nick.sName then
nick:SendData("$To: "..nick.sName.." From: "..ChatRoomName.." $<"..user.sName.."> " ..msg)
end
end
end

but i am affraid of loops of something like that because there isn't any "return 1". But it doesn't seem to eat MBs of memory
Hawk wrote that in his script:
function ChatRoom(user,msg)
for i,nick in frmHub:GetOnlineUsers() do
if nick ~= nil then
if user.sName == nick.sName then
else
if ChatProfiles[nick.iProfile] == 1 then
usr:SendData("$To: "..nick.sName.." From: "..ChatRoomName.." $<"..user.sName.."> " ..msg)
else
return 1
end
end
end
end
end

But the line 4 kinds of disturb me: "then else return 1"
then what ? LOL
Title: Re: Master chat don't work
Post by: Samantha on 13 January, 2007, 19:02:20

--// Simple MasterChat by NightLitch 2005-03-05
--// Fixed bug with some profile not recieving chat - Blondie? 15/10/2006
--// Added Leviathan support - Blondie? 19/10/2006

MasterChatName = "?Admin-Chat?"

function Main()
frmHub:RegBot(MasterChatName)
end


function ToArrival(user,data)
local s,e,to,from,msg = string.find(data,"%$To:%s+(%S+)%s+From:%s+(%S+)%s+%$%b<>%s+(.*)%|")
if to == VipChatName then
if user.iProfile == 0 or user.iProfile == 5 or user.iProfile == 6 then
MasterChat(user,msg)
else
SendPmToNick(user.sName,MasterChatName, "*** You don't have the privileges to talk in this chat.")
return 1
end
end
end

function VipChat(user,msg)
for _,profile in pairs(GetProfiles()) do
for _,users in pairs(GetUsersByProfile(profile)) do
if GetItemByName(users) then
if GetItemByName(users).iProfile == 6 or GetItemByName(users).iProfile == 5 or GetItemByName(users).iProfile == 0 then
if GetItemByName(users).sName ~= user.sName then
GetItemByName(users):SendData("$To: "..GetItemByName(users).sName.." From: "..MasterChatName.." $<"..user.sName.."> "..msg)
end
end
end
end
end
end




i hope this is what you are looking and it been tried and tested :)
Title: Re: Master chat don't work
Post by: smeg568 on 15 January, 2007, 22:57:08
I'm probably being stupid,

The profile indicators in ptokax eg:

               [-1] = 1, -- Unreg
               
Title: Re: Master chat don't work
Post by: CrazyGuy on 15 January, 2007, 23:06:57
yes you can:

Quote
GetProfiles()            - Return table with profilenames ... table starting with 1 but real profile number is 0 !
GetProfileIdx(ProfileName)      - Return ProfileNumber or -1 failed
GetProfileName(ProfileNumber)      - Return ProfileName or nil for failed

this small code will throw all profile names plus matching number in mainchat


IdentifyProfiles = function()
local sProfiles = "Known profile numbers and names:\n\n"
for k in pairs (GetProfiles()) do
sProfiles = sProfiles.."["..(k-1).."]\t"..GetProfileName((k-1)).."\n"
end
sProfiles = sProfiles.."[-1]\tUnregistered Users\n"
SendToAll(frmHub:GetHubBotName(), sProfiles)
end


result:
Quote
<PtokaX> Known profile numbers and names:

-
  •    Master
    - [1]   Operator
    - [2]   VIP
    - [3]   Reg
    - [4]   4
    - [-1]   Unregistered Users

hmm, is it just me or does board seem to have trouble displaying  [ 0 ]  (without spaces) ??
Title: Re: Master chat don't work
Post by: smeg568 on 15 January, 2007, 23:09:40
Thanks CG 

I'll have a go at 'tweaking'    ;D
Title: Re: Master chat don't work
Post by: CrazyGuy on 15 January, 2007, 23:17:33
no probs

Profiles, although very often defined the same, are variables.
You can add and remove profiles through both scripts and PtokaX's Profile Manager.
The order the Profile Manager shows the profiles, is the order the scripts see them starting with number 0 on top.

Adding a profile through script can be done using

AddProfile(ProfileName, ProfileNumber)   - Return 1 success or -1 failed. Max ProfileName length 64 chars.

It is wise to check first what the next free ProfileNumber is.
As GetProfiles() really returns the number of profiles, you can use the highest number returned by GetProfiles() as your first free profile number.


MakeNewProfile = function(sProfileName)
local iProf = 0
for k in pairs (GetProfiles()) do
iProf = iProf +1
end
AddProfile(sProfileName, iProf)
end


will create a new profile at the next free number having the name specified in the function call
Title: Re: Master chat don't work
Post by: bastya_elvtars on 15 January, 2007, 23:31:14
#GetProfiles()+1