PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: DarkElf on 18 October, 2003, 00:06:14

Title: Help whith kick and DawgBot
Post by: DarkElf on 18 October, 2003, 00:06:14
Hi, i have a bot (dawgbot 0.8b) and he give to ptokax this error:
Syntax Error: attempt to index local `kickUser' (a string value)

Can you help me?I post the kick string

--// kick
function dokick(curUser,kickUser,reason)
   if curUser.bOperator then
   if GetItemByName(kickUser) then kickUser = GetItemByName(kickUser) end
   kicklevel = GetProfileName(kickUser.iProfile)
   if kicklevel == nil then kicklevel = "Unreg" end
   if reason == nil then reason = "No Reason Given" end
   if userLevels[GetProfileName(curUser.iProfile)] < userLevels[kicklevel] then
   kickUser:SendPM(secbot,"You Have Been Kicked Because: "..reason)
   SendToAll("<<"..secbot..">> The User "..kickUser.sName.." Has Been Kicked Because: "..reason)
   writelog(date().."  <"..curUser.sName.."> Kicked <"..kickUser.sName.."> Because:"..reason)
   kickUser:Disconnect()
   else
   SendPmToNick(curUser.sName,secbot,"The User "..kickUser.sName.." Is Of Equal Or Higher Level Than You, You Lack The Authority")
   end
   end
end
Title:
Post by: plop on 18 October, 2003, 03:22:24
give this 1 a try, placed comments on the added/changed part.

--// kick
function dokick(curUser,kickUser,reason)
   if curUser.bOperator then
      if GetItemByName(kickUser) then   -- here checking if the kicked user is in the hub
         kickUser = GetItemByName(kickUser)  
      else -- if not were sending the kicking OP a pm informing that fact
         SendPmToNick(curUser.sName,secbot,"The User "..kickUser.." Is not in the hub")
         return 1 -- no need to continue processing so were canceling
      end
      kicklevel = GetProfileName(kickUser.iProfile)
      if kicklevel == nil then
         kicklevel = "Unreg"
      end
      if reason == nil then
         reason = "No Reason Given"
      end
      if userLevels[GetProfileName(curUser.iProfile)] < userLevels[kicklevel] then
         kickUser:SendPM(secbot,"You Have Been Kicked Because: "..reason)
         SendToAll("<<"..secbot..">> The User "..kickUser.sName.." Has Been Kicked Because: "..reason)
         writelog(date().." <"..curUser.sName.."> Kicked <"..kickUser.sName.."> Because:"..reason)
         kickUser:Disconnect()
      else
         SendPmToNick(curUser.sName,secbot,"The User "..kickUser.sName.." Is Of Equal Or Higher Level Than You, You Lack The Authority")
      end
   end
end

plop
Title:
Post by: DarkElf on 18 October, 2003, 18:52:57
don't run... :(
Title:
Post by: plop on 18 October, 2003, 20:45:20
yea was a tiny error in it, i edited the above post and made the next more safe version.
pick the 1 you like. (if the above now would work, lol).
it's hard 2 test it without the rest of the script.


--// kick

function dokick(curUser,kickUser,reason)
   if curUser.bOperator then
      kickMe = GetItemByName(kickUser)  -- changing the string kickUser 2 the table with name kickMe, we could be needing the string later
      if kickMe ~= nil then  -- if not nil we can continue doing the kick
         kicklevel = GetProfileName(kickMe.iProfile)
         if kicklevel == nil then
            kicklevel = "Unreg"
         end
         if reason == nil then
            reason = "No Reason Given"
         end
         if userLevels[GetProfileName(curUser.iProfile)] < userLevels[kicklevel] then
            kickMe:SendPM(secbot,"You Have Been Kicked Because: "..reason)
            SendToAll("<<"..secbot..">> The User "..kickMe.sName.." Has Been Kicked Because: "..reason)
            writelog(date().." <"..curUser.sName.."> Kicked <"..kickMe.sName.."> Because:"..reason)
            kickMe:Disconnect()
         else
            SendPmToNick(curUser.sName,secbot,"The User "..kickMe.sName.." Is Of Equal Or Higher Level Than You, You Lack The Authority")
         end
      else    --if kickMe == nil were sending the kicking OP a pm informing that the user is not in the hub
         SendPmToNick(curUser.sName,secbot,"The User "..kickUser.." Is not in the hub") -- using the string here
      end
   end
end

plop
Title:
Post by: DarkElf on 23 October, 2003, 01:40:28
Thanks, now it run :))))
1 milion of thanks :P
Title:
Post by: plop on 23 October, 2003, 01:42:28
QuoteOriginally posted by DarkElf
Thanks, now it run :))))
1 milion of thanks :P
1 is more then enough.  lol