Average Share
 

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

Average Share

Started by Herodes, 23 September, 2006, 09:32:32

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Herodes

This is a script that comments on the connecting user's share size, relative to the average share size in the hub,...

Download from here

-- AverageShare Bot
-- request: ¤ Viper ¤
-- script Herodes // 4:15 pm 31-5-2004
-- a little fix :P stupid mistake ...
-- fixed the display of mb, gb, tb
-- added categorized messages for Below(10 gb, 25 gb, 50 gb, 100 gb)
-- 			and Above( 50 gb, 100gb, 250gb, 500gb)
--- touched by Herodes again on 22-09-2006
-- made for Lua 5.x ... upon Viper's request ;)
-- Thx to Psycho_Chihuahua and TiMe†raVelleR for testing this out and giving feedback...

function NewUserConnected(user, data)
	if (frmHub:GetUsersCount() > 2) and (frmHub:GetCurrentShareAmount() > 0) and (user.iShareSize > 0) then
		local ProperUnits = function( i )
			local i = tonumber(i)
			if i == 0 then return "0.00 KB"; end
			if i >= (1024^2) then
				if i >= (1024^3) then
					if i >= (1024^4) then return string.format("%.2f", (i/(1024^4))).." TB"; end
					return string.format("%.2f", (i/(1024^3))).." GB"
				end; return string.format("%.2f", (i/(1024^2))).." MB"
			end;return string.format("%.2f", (i/(1024))).." KB"
		end
		local SafeDivide = function( a, b )
			if ( a == 0 and b ~= 0 ) or ( a == 0 and b == 0 )then return 0; end
			if b == 0 and a ~= 0 then return 1; end
			return a/b
		end
		local iAverageShare = SafeDivide( frmHub:GetCurrentShareAmount(), frmHub:GetUsersCount() )
		local m = "\r\n-=¦- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
		m = m.."\r\n-=¦=- \t"..frmHub:GetUsersCount().." Users in the hub are currently sharing "..ProperUnits(frmHub:GetCurrentShareAmount()).." giving an average of "..ProperUnits(iAverageShare).." each."
		if user.iShareSize >= iAverageShare then
			m = m.."\r\n-=¦=-\tYou are "..(ProperUnits( user.iShareSize - iAverageShare )).." above the Average per user share... you're immense!!!"
			local iShare = SafeDivide(user.iShareSize, 1024^3)
			if iShare >= 50 and iShare < 100 then m = m.."\r\n-=¦=-\tYou have boosted the average up,you're amazing!!!"
			elseif iShare >= 100 and iShare < 250 then m = m.."\r\n-=¦=-\tYou have boosted the average up,There are people that will pay for your share!!!"
			elseif iShare >=250 and iShare < 500 then m = m.."\r\n-=¦=-\tYou have boosted the average up,There are people that will kill for your share!!!"
			elseif iShare >= 500 then m = m.."\r\n-=¦=-\tThere are people that will die for your share, or even a slot!!!"
			end
			m = m.."\r\n-=¦=-\t ... and yes we need you here!  ;)"
		elseif user.iShareSize < iAverageShare then
			m = m.."\r\n-=¦=-\tYou are "..(ProperUnits( iAverageShare - user.iShareSize) ).." below the Average share... try to get more stuff in ur share & be above average!"
			local iShare = SafeDivide(user.iShareSize, 1024^3)
			if iShare >= 10 and iShare < 25 then m = m.."\r\n-=¦=-\tYou are VERY small !!!"
			elseif iShare >= 25 and iShare < 50 then m = m.."\r\n-=¦=-\tYou are small!!!"
			elseif iShare >= 50 and iShare < 100 then m = m.."\r\n-=¦=-\tI bet you can try harder to raise your sharesize!!!"
			elseif iShare >= 100 then m = m.."\r\n-=¦=-\tIt's not that your share ain't big, it's that there are bigger!!!"
			end
			m = m.."\r\n-=¦=-\t ... still,... your most welcome!  ;)"
		end
		user:SendData( "ShareBot", m.."\r\n-=¦- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " )
	end
end

OpConnected = NewUserConnected

speedX

Hey Herodes, is it possible to show the message of average share on input of a command? Plzz if possible
Thanking You,

speedX

Naithif

Seems I've missed the small-size font part  :P

Writing tutorials doesn't pay off

The solution was covered more than once at the tutorial part, where you were active poster...

Some clues

OpConnected = NewUserConnected

This won't be needed

function NewUserConnected(user, data)

This should be replaced with
function ChatArrival(user, data)
	local s,e,cmd = string.find(data, "%b<>%s+(%S+)(%S+)")
	if cmd == "!command" then

(where !command can be anything bla bla)
+ you will need an 'end' to close the if... Maybe before the last 'end' to be precise

speedX

Thx for the help Naithif again. I had made a small bot by mixing some codes wich showed me errors :( (I have posted on Lesson 8) , but no one responded. Please have a look on it. http://forum.ptokax.org/index.php?topic=489.0
Thanking You,

speedX

speedX

Thank you Mutor and Naithif for replying, but the script now doesn't work :(
when I type the command it doesn't give any result. No errors found in Ptokax
Thanking You,

speedX

speedX

Quote from: Mutor on 23 November, 2006, 15:46:11
Firstly, stop crossposting. Your post in the Lesson 8 thread has no bearing here.
It serves only to move this thread off it's topic.

Secondly, what I've posted in that thread for you certainly works as it was tested.
What you may have done with it since, I cannot say.

??? When did I say tht the code u posted on tht topic is incorrect? I just said tht the after making the changes said by Naithif, it doesnt show any result....
Thanking You,

speedX

speedX

Sorry for tht Mutor,

Here is the script after making the changes
-- AverageShare Bot
-- request: ? Viper ?
-- script Herodes // 4:15 pm 31-5-2004
-- a little fix :P stupid mistake ...
-- fixed the display of mb, gb, tb
-- added categorized messages for Below(10 gb, 25 gb, 50 gb, 100 gb)
-- 			and Above( 50 gb, 100gb, 250gb, 500gb)
--- touched by Herodes again on 22-09-2006
-- made for Lua 5.x ... upon Viper's request ;)
-- Thx to Psycho_Chihuahua and TiMe?raVelleR for testing this out and giving feedback...

function ChatArrival(user, data)
	local s,e,cmd = string.find(data, "%b<>%s(%p%w+)")
	if cmd == "!shares" then
	if (frmHub:GetUsersCount() > 2) and (frmHub:GetCurrentShareAmount() > 0) and (user.iShareSize > 0) then
		local ProperUnits = function( i )
			local i = tonumber(i)
			if i == 0 then return "0.00 KB"; end
			if i >= (1024^2) then
				if i >= (1024^3) then
					if i >= (1024^4) then return string.format("%.2f", (i/(1024^4))).." TB"; end
					return string.format("%.2f", (i/(1024^3))).." GB"
				end; return string.format("%.2f", (i/(1024^2))).." MB"
			end;return string.format("%.2f", (i/(1024))).." KB"
		end
		local SafeDivide = function( a, b )
			if ( a == 0 and b ~= 0 ) or ( a == 0 and b == 0 )then return 0; end
			if b == 0 and a ~= 0 then return 1; end
			return a/b
		end
		local iAverageShare = SafeDivide( frmHub:GetCurrentShareAmount(), frmHub:GetUsersCount() )
		local m = "\r\n-=?- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
		m = m.."\r\n-=?=- \t"..frmHub:GetUsersCount().." Users in the hub are currently sharing "..ProperUnits(frmHub:GetCurrentShareAmount()).." giving an average of "..ProperUnits(iAverageShare).." each."
		if user.iShareSize >= iAverageShare then
			m = m.."\r\n-=?=-\tYou are "..(ProperUnits( user.iShareSize - iAverageShare )).." above the Average per user share... you're immense!!!"
			local iShare = SafeDivide(user.iShareSize, 1024^3)
			if iShare >= 50 and iShare < 100 then m = m.."\r\n-=?=-\tYou have boosted the average up,you're amazing!!!"
			elseif iShare >= 100 and iShare < 250 then m = m.."\r\n-=?=-\tYou have boosted the average up,There are people that will pay for your share!!!"
			elseif iShare >=250 and iShare < 500 then m = m.."\r\n-=?=-\tYou have boosted the average up,There are people that will kill for your share!!!"
			elseif iShare >= 500 then m = m.."\r\n-=?=-\tThere are people that will die for your share, or even a slot!!!"
			end
			m = m.."\r\n-=?=-\t ... and yes we need you here!  ;)"
		elseif user.iShareSize < iAverageShare then
			m = m.."\r\n-=?=-\tYou are "..(ProperUnits( iAverageShare - user.iShareSize) ).." below the Average share... try to get more stuff in ur share & be above average!"
			local iShare = SafeDivide(user.iShareSize, 1024^3)
			if iShare >= 10 and iShare < 25 then m = m.."\r\n-=?=-\tYou are VERY small !!!"
			elseif iShare >= 25 and iShare < 50 then m = m.."\r\n-=?=-\tYou are small!!!"
			elseif iShare >= 50 and iShare < 100 then m = m.."\r\n-=?=-\tI bet you can try harder to raise your sharesize!!!"
			elseif iShare >= 100 then m = m.."\r\n-=?=-\tIt's not that your share ain't big, it's that there are bigger!!!"
			end
			m = m.."\r\n-=?=-\t ... still,... your most welcome!  ;)"
		end
		user:SendData( "ShareBot", m.."\r\n-=?- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " )
	end
	end
end


Not showing the result, no errors found in ptokax
Thanking You,

speedX

Naithif

With Mutors version you shouldn't need the ! before the command, it's already in the reading (or maybe I'm wrong)

local s,e,cmd = string.find(data, "%b<>%s(%p%w+)")
if cmd == "!shares" then

Naithif

Yip, I seem to misunderstand that code :D
I thought it would read the punctuation mark %p and after some chars that need to be '!cmd' making it equal to '!!cmd'... I've missed that only one word is read - 'local s,e,cmd' so that mark should be inside !cmd, making it double checking as you say, and not doubling the marks
Thanks for enlighting me Mutor  :D Again  ::)

speedX

Means? wat shud I do to fix tht thing??
Thanking You,

speedX

Naithif

3 criterias are there as Mutor showed

if (frmHub:GetUsersCount() > 2)
More than 2 users in the hub
and
(frmHub:GetCurrentShareAmount() > 0)
More share at the hub in sum than 0
and
(user.iShareSize > 0)
More share for the user who types the command than 0

If any of these fails, it won't return anything

speedX

#11
Quote from: Naithif on 23 November, 2006, 18:37:13
3 criterias are there as Mutor showed

if (frmHub:GetUsersCount() > 2)
More than 2 users in the hub
and
(frmHub:GetCurrentShareAmount() > 0)
More share at the hub in sum than 0
and
(user.iShareSize > 0)
More share for the user who types the command than 0

If any of these fails, it won't return anything

ohhhh, I was testing with only one user in the hub :P sorryyyyyyyy

2 last requests:
1) I would if the command comes b4 the result and be seen by all
2) How can I use more than 1 prefix?
Thanking You,

speedX

SMF spam blocked by CleanTalk