[Help] Read inside <G>
 

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

[Help] Read inside

Started by Snooze, 24 March, 2004, 07:09:24

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Snooze

well... here goes ..


I've made this kick function my following you guys help, though need some help on finishing it ...
Function:

function KickUser(user, data)
			if (user.bOperator) then
				local s,e,arg,reason = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
				if (arg == nil or reason == nil) then
					user:SendData(Bot, "Syntax error, !kick  , must have a nick and reason.")
				else
     				 local tmp = GetProfileOffline(arg)
					if (GetItemByName(arg) == nil) then
						user:SendData(Bot, "No user named "..arg.." online.")
   				else
      					local tmp = GetProfileOffline(arg)
     					 if tmp < user.iProfile then
        				 user:SendData(Bot, "The user "..arg.." has a higher level then you. All Ops has been notified about this violation!")
        				 SendPmToOps(Bot, "**WARNING** The Operator "..user.sName.." tryed to kick the Operator " ..arg.." with a higher level. ")
					appendto(sOplog)
					write("\r\n", "The Operator "..user.sName.." tryed to kick a higher ranking Operator: "..arg.." on "..GetTime())
					writeto()
					else
						local userToBeKicked = GetItemByName(arg)
					if (tKickCounter[userToBeKicked.sName] == 3) then
					BanUser(user, data)
					end
					if (tKickCounter[userToBeKicked.sName] == nil) then
						tKickCounter[userToBeKicked.sName] = 1
					else
						tKickCounter[userToBeKicked.sName] = tKickCounter[userToBeKicked.sName] + 1
					end
						SendToAll(Bot, "User "..userToBeKicked.sName.." was kicked by "..user.sName.." because: "..reason.." 

"..tKickCounter[userToBeKicked.sName].." time(s)")
						userToBeKicked:SendPM(Bot, "You have been kicked because: "..reason)
						appendto(sOplog)
						write("\r\n", "*"..user.sName.." kicked "..arg..". Reason: "..reason.." on "..GetTime())
						writeto()
					userToBeKicked:TempBan()
					end
				    end
				end
			else
	user:SendData(Bot, "You don?t have permission to use this command.")
	end
end

I have two problems:

1) I cant seam to end the function after this ..

if (tKickCounter[userToBeKicked.sName] == 3) then
					BanUser(user, data)
					end

It should only goto the ban function and skip over the kick part in this one ..

2) I need to buil in a "if tmp == nil then" so that the function skips over the userlevel check .. Right now it will stop on a nil error if the user is not regged :(


Please advice..


**Snooze
- getting better..

Corayzon

yoyo =]

im not to sure but u dont seem to return after the process comes to an end...and it continues to exec...

remember after all main if and else's to return and not let the statement end and continue the process...

this very well could be ur problem...

i also feel this statement is to complex and needs to be broken down into sub functions to make more ease for ppl debuging it...

anyways...if u still have probs after u tri and sort it out i will give a a hand... ;)

function doKick(user, data)

	_,_,_,username,reason = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s+(.+)")
	if username == nil then _,_,_,username = strfind(data, "%b<>%s+(%S+)%s+(.+)") end
	if username == nil then sendUsage(user, cmdkick, cmdkickusage) return end

	pName = GetProfileName(user.iProfile)
	toKill = GetItemByName(username)
	if toKill ~= nil then toKillpName = GetProfileName(toKill.iProfile) else user:SendData(sBot, kickmsg7) return end
	if toKillpName == nil then toKillpName = "none" end

	if profiles[pName] < profiles[toKillpName] then
		if reason == nil then
			if sendrulesonkick == "yes" then showFile(toKill, sysPath..file["rules"]) end
			toKill:SendPM(sBot, translateString(kickmsg3, toKill.sName, user.sName, "Extra2"))
			SendToAll(sBot, translateString(kickmsg1, toKill.sName, user.sName, "Extra2"))
		else
			if sendrulesonkick == "yes" then showFile(toKill, sysPath..file["rules"]) end
			toKill:SendPM(sBot, translateString(kickmsg4, toKill.sName, user.sName, reason))
			SendToAll(sBot, translateString(kickmsg2, toKill.sName, user.sName, reason))
		end
		toKill:TimeBan(kicktime)
		DisconnectByName(toKill.sName)
		return 1
	else
		user:SendData(sBot, kickmsg6)
		return
	end
end

This is how i go about it...but then its very complex and is interlaced with settings.lua and the main function...

function doKickBanCommand(user, data, cmd)

	if 	cmd == cmdkick 		or 
		cmd == cmdban 		or 
		cmd == cmdtimeban 		or 
		cmd == cmdunban 		or
		cmd == cmdshowkicks	then

		_,_,_,username = strfind(data, "%b<>%s+(%S+)%s+(%S+)")
		pName = GetProfileName(user.iProfile)
		if pName == nil then pName = "none" end
		
		if user.bOperator then
			if cmd == cmdkick then
				if cmdkicklevel > profiles[pName] then
					if doKickCount(user, data) then
						if doKick(user, data) then
							countKick(user.sName, "kick")
						end
					end
				end
				return 1

			elseif cmd == cmdban then
				if cmdbanlevel > profiles[pName] then
					if doBan(user, data) then
						countKick(user.sName, "ban")
					end
				end
				return 1

			elseif cmd == cmdtimeban then
				if cmdtimebanlevel > profiles[pName] then
					if doKickCount(user, data) then
						if doTimeBan(user, data) then
							countKick(user.sName, "timeban")
						end
					end
				end
				return 1

			elseif cmd == cmdunban then
				if cmdunbanlevel > profiles[pName] then
					if doUnban(user, data) then
						countKick(user.sName, "unban")
					end
				end
				return 1

			elseif cmd == cmdshowkicks then
				if cmdshowkickslevel > profiles[pName] then
					showKickInfo(user, data)
				end
				return 1
			end
		end
	end
end

Hopefully this gives ya some ideas ;)

Snooze

hehe - i've been studying your script .. a bit to advanced for me right now .. but it does give me some ideas for future adjustments ;)


Your right about it being becomming complex ... as i learn more, more will be added ...thus the complexity of the functions ...

When i get better at tables ill do a full rewrite of the script and make it public .. But for now this is just a learning project + the main script running in my hubs ...

Though i dont see that happening in the near future as ive only been scripting lua for 4 weeks Still have lots to lear ;)

btw - thanks for your answer - ill get working on that right away :)


**Snooze

Corayzon

nice man!...

i been scripting with lua on ptokax for about 5 weeks now...but i picked up really quickly...sinse when i found the server app and seen its scripts...i was writing my own fileshareing server...and went hey...this rocks...

i fukin love ptokax!

Snooze

I couldnt agree more - Ptokax rocks !!

I switched from NMDCh 5 weeks ago and havnt had any regrets :D ( and been scripting ever since )

Though hadnt it been for this forum i would have been lost in the lua part !! Guys like you make a world of dif in learning this !!

Thanks !


**Snooze

Corayzon

lols dude...

i just downlaoded scripts and learn lua from their...

i used mean machine mainly...tought me alot of lua it did!

=]

Snooze

Thanks for the advice :))


**Snooze
(you should max your DC)

SMF spam blocked by CleanTalk