PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Conversion Requests => Topic started by: TZB on 26 August, 2009, 10:56:23

Title: Kitchen Sink.
Post by: TZB on 26 August, 2009, 10:56:23
Please Let us have some more Fun madman If you can make your creation for newer ptokax also. :P
-- Kitchen Sink made by Madman, 28.02.06
--[[--
Made beacuse of bastya_elvtars comment on the board
quote: These scripts contain everything but the kitchen sink. :)
But now this board does ;)
Warning! Use with caution!
This script will disconnect a random number of users when a Op use the cmd !sink

How? How the hell did i came up with the idea of this script?
If you figured it out, please let me know
--]]--

function ChatArrival(curUser, data)
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+%#](%S+)")
if curUser.bOperator then
if cmd == "sink" then
Sink(curUser) return 1
end
end
end

function Sink(user)
local TmpTable,WhileTable,Dissed = {}, {0,}, ""
if frmHub:GetUsersCount() == 1 then
user:SendData("*** We need more users before we pull the plug") return 1
end
for _,oUser in frmHub:GetOnlineUsers() do
if oUser.sName == user.sName then
-- Don't add user that used the cmd
else
table.insert(TmpTable, oUser.sName)
end
end
SinkNr = math.random(0, (frmHub:GetUsersCount()-1))
if SinkNr == 0 then
SendToAll(user.sName.. " pulled the plug in the kitchen sink, but no user went down the drain") return 1
end
WhileTable[1] = SinkNr
while WhileTable[1] > 0 do
UserDis = TmpTable[math.random(table.getn(TmpTable))]
DisconnectByName(UserDis)
WhileTable[1] = WhileTable[1] - 1
Dissed = Dissed..UserDis..", "
end
Msg = user.sName.. " pulled the plug and the following users went down the drain " ..Dissed
SendToAll(Msg)
end

Fun Script had been awesome way to keep the main chat alive can this script be brought back to work on new ptokax.
Title: Re: Kitchen Sink.
Post by: ?ippe?? on 26 August, 2009, 18:59:15

Here comes the converted script using the API Convertor
Tested in my hub and working fine.


--[[
-- Kitchen Sink made by Madman

Made beacuse of bastya_elvtars comment on the board
quote: These scripts contain everything but the kitchen sink. :)
But now this board does ;)
Warning! Use with caution!
This script will disconnect a random number of users when a Op use the cmd !sink

How? How the hell did i came up with the idea of this script?
If you figured it out, please let me know

Changes :-
-- This script is converted to API 2 using PtokaX LUA API Converter v1.0

]]--

function ChatArrival(curUser,data)
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+%#](%S+)")
if Core.GetUserValue(curUser,11) then
if cmd == "sink" then
Sink(curUser) return true
end
end
end

function Sink(user)
local TmpTable,WhileTable,Dissed = {}, {0,}, ""
if Core.GetUsersCount() == 1 then
Core.SendToUser(user,"*** We need more users before we pull the plug") return 1
end
for _,oUser in Core.GetOnlineUsers(false) do
if oUser.sNick == user.sNick then
-- Don't add user that used the cmd
else
table.insert(TmpTable, oUser.sNick)
end
end
SinkNr = math.random(0, (Core.GetUsersCount()-1))
if SinkNr == 0 then
Core.SendToAll(user.sNick.. " pulled the plug in the kitchen sink, but no user went down the drain") return 1
end
WhileTable[1] = SinkNr
while WhileTable[1] > 0 do
UserDis = TmpTable[math.random(#TmpTable)]
Core.Disconnect(UserDis)
WhileTable[1] = WhileTable[1] - 1
Dissed = Dissed..UserDis..", "
end
Msg = user.sNick.. " pulled the plug and the following users went down the drain " ..Dissed
Core.SendToAll(Msg)
end
Title: Re: Kitchen Sink.
Post by: TZB on 26 August, 2009, 19:05:15
What should i say i actually tried already what you did but there is a problem for me its not getting done when i type !sink.
Title: Re: Kitchen Sink.
Post by: TZB on 26 August, 2009, 19:16:10
To the max to what i seen so far the converter which even i used it could only do the function till.
Quotefunction Sink(user)
   local TmpTable,WhileTable,Dissed = {}, {0,}, ""
   if Core.GetUsersCount() == 1 then
      Core.SendToUser(user,"*** We need more users before we pull the plug") return 1
   end
i.e when user count is 1
But when user count increased the script failed for some reason on my side i got no idea if you tested the script in hub with users more than 1.
Please update me with your results so that i could recheck my problems.
Title: Re: Kitchen Sink.
Post by: ?ippe?? on 27 August, 2009, 05:46:35
 
Sorry to say that the script is failing at my end too when the users exceed more that one.

When i type "!sink" the following error occurs :-

Syntax C:\Myhub\scripts\KitchenSink.lua:33: attempt to call a table value

Something is wrong in this part of the script

            SinkNr = math.random(0, (Core.GetUsersCount()-1))
if SinkNr == 0 then
Core.SendToAll(user.sNick.. " pulled the plug in the kitchen sink, but no user went down the drain") return 1
end
WhileTable[1] = SinkNr
while WhileTable[1] > 0 do
UserDis = TmpTable[math.random(#TmpTable)]
Core.Disconnect(UserDis)
WhileTable[1] = WhileTable[1] - 1
Dissed = Dissed..UserDis..", "
end


Hope i can solve this with some R&D.... lol

Regards,
?ippe??
Title: Re: Kitchen Sink.
Post by: TZB on 27 August, 2009, 07:04:49
Thank Goodness by analysis were right.
now i can just go ahead for editing but its madman's script so am not sure if he permits. got to ask him first. :P
Madman please help with this script if you have time.
Title: Re: Kitchen Sink.
Post by: Madman on 27 August, 2009, 13:25:03
the problem is that for loops requiers pairs or ipairs, depending if it's an array or table.
Table is
t = {
["one"] = true,
["two"] = true,
}

while array is
a = {
[1] = true,
[2] = true,
}

so the line for _,oUser in Core.GetOnlineUsers(false) do  needs a ipairs. ipairs(Core.GetOnlineUsers())  btw, the false is not needed either.

I attached the converted version I wrote.
I made some improvement, but it still does the same thing.

As for editing my scripts, it's free to use/rewrite anything, aslong as the I'm credited in someway.
Title: Re: Kitchen Sink.
Post by: TZB on 27 August, 2009, 13:29:47
Thanks a lot madman.
QuoteHow? How the hell did i came up with the idea of this script?
If you figured it out, please let me know
Any answer for this question its bit curious thing in the script :P if you could please reveal the mystery behind the script.
Thanks once again.
Title: Re: Kitchen Sink.
Post by: Madman on 27 August, 2009, 22:16:53
The mystery?
I have no idea. I just wrote the script... And I don't really know why...