how to add a cmd to a existing script
 

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

how to add a cmd to a existing script

Started by kbeh273300, 16 February, 2004, 23:35:43

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kbeh273300

i have a script i made with the old script maker when i first started useing ptokax and i am useing it know to try and learn some lua.i was hopeing i could get a little help here what i want to do is add a cmd to the script can anyone help me out?here is the script that has the cmd i want to add to my script.if someone could show me how you would add a cmd to a already made script that would be very helpfull to help me learn this stuff lol
-- Date: 13-02-2004 
-- code from klownietklowniet 
-- some small shit by Freed 
-- optimized some by pur 
-- Added regbot, by zinden
-- fixed security bug introdused by me :-( 
-- gg3k added save function (that was ripped from triviabot :))

botname="-=WARNING=-" 
warningfile="warned.dat"

function Main() 
LoadWarn()
frmHub:RegBot(botname) 
end 

max = 3 -- number of warnings before kick 
warnings={} 
c={[1]="1st", [2]="2nd"} 


function NewUserConnected(curUser) 
warnings[curUser.sName]=0 
end 


function DataArrival(user, data) 

	data=strsub(data,1,strlen(data)-1) 
	s,e,cmd = strfind(data,"%b<>%s+(%S+)") 
	s,e,arg = strfind(data,"%b<>%s+%S+%s+(%S+)") 
	s,e,arg2 = strfind(data,"%b<>%s+%S+%s+%S+%s(.+)") 

	if (cmd=="!warn" and user.bOperator) then 
		-- its here i need the help -- 
		if arg~=nil then 
			victim=GetItemByName(arg) 
			if victim~=nil then 
				if warnings[arg]==nil then 
					warnings[arg]=0 
				end 
			if warnings[arg]==(max - 1) then 
				SendPmToNick(botname, "This was your last warning. You are now banned!")
				SendToAll(botname, arg.." got his last warning and was now banned!") 
				victim:Ban() 
				victim:Disconnect() 
				SaveWarn()
				return 1 
			else 
				if victim.bOperator then 
					warnings[arg]=0 
					return 1 
				end 
				warnings[arg]=warnings[arg]+1 
				if arg2~=nil then 
					victim:SendPM(botname,"Warning: "..arg2) 
					SendToAll(botname, arg.." got his "..c[warnings[arg]].." warning. Reason: "..arg2) 
				end 
				SendPmToNick(botname, "This is your "..c[warnings[arg]].." warning! Get 3 and you are banned!") 
				SaveWarn()
				return 1 
			end 
		else 
			user:SendPM(botname, "No such user in the userlist: "..arg) 
			return 1 
		end 
		else 
			user:SendPM(botname, "Syntax: ?warn  ") 
			return 1 
		end 
	elseif (cmd=="!reset" and user.bOperator) then 
		if arg~=nil then 
			warnings[arg]=nil 
			user:SendPM(botname, arg.."'s warning were reset.") 
			SaveWarn()
			return 1 
		else 
			user:SendPM(botname, "Syntax: ?reset ") 
			return 1 
		end 
	end 
end 

function SaveWarn()
  local handle = openfile(warningfile, "w")
  for index, value in warnings do
    write(handle,index.."|"..value.."\r\n")
  end
  closefile(handle)
end

function LoadWarn()
  local handle = openfile(warningfile, "r")
  if (handle) then
    local line = read(handle)
    while line do
      local arrTmp = tokenize(line, "|")
      if ((arrTmp[1] ~= nil) and (arrTmp[2] ~= nil)) then
        warnings[arrTmp[1]] = tonumber(arrTmp[2])
      end
      line = read(handle)
    end
  closefile(handle)
  end
end

function tokenize (inString,token)
  _WORDS = {}
  local matcher = "([^"..token.."]+)"
  gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
  return _WORDS
end

i like this warn script and i would like to add it to mine i hope the scripter doesnt mind if i use his code.i know i could just add it in combining it with my script but i would like to learn just how to create such a thing into a script.
-=United Kings network=-
Network Webpage?
Hub address: houseofkings.no-ip.org:420
hub webpage
hub forum

SMF spam blocked by CleanTalk