Author Topic: how to add a cmd to a existing script  (Read 1526 times)

0 Members and 1 Guest are viewing this topic.

Offline kbeh273300

  • Double Ace
  • *
  • Posts: 106
  • Karma: +1/-0
    • The Ptokax LUA Language Board  Main Page
how to add a cmd to a existing script
« on: 16 February, 2004, 23:35:43 »
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
Code: [Select]
-- 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

PtokaX forum

how to add a cmd to a existing script
« on: 16 February, 2004, 23:35:43 »