PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: DorianGray on 20 January, 2004, 00:26:40

Title: Help me!!!! Commands userinfo and ipinfo
Post by: DorianGray on 20 January, 2004, 00:26:40
I'm in difficult. I'm a newbie to program in Lua. Now i work to create my first Bot. I have tried to do the command userinfo. But Ptokax give me an error.

function Arg1(data)
   s,e,cmd,arg = strfind(data, "%b<>%s(%S+)%s(%S+)")
   return arg
end

function UserInfo(user, data)
   who = Arg1(data)
   local usr = GetItemByName(who)
   user:SendPM(BotName, "Informazioni:" ..usr.."|")
   user:SendPM(BotName, "IP dell'utente:" ..usr.sIP.. "|")
   user:SendPM(BotName, "Versione del dc:" ..usr.iVersion.."|")
end

function DataArrival(user, data)
......
......
   if (cmd=="!ui) then
      UserInfo(user, data)
      return 1
   end
end

Ptokax tell me that "who" (is a nil value)... Why??????
Please reply me...
Title:
Post by: NightLitch on 20 January, 2004, 01:06:18
well one error would be this:

local usr = GetItemByName(who)
user:SendPM(BotName, "Informazioni:" ..usr.."|")

if getitembyname as above then you should
call the name as you call a user. bad explaining in this.
english sucks for the moment..

here try this:

local usr = GetItemByName(who)
user:SendPM(BotName, "Informazioni:" ..usr.sName.."|")
Title:
Post by: plop on 20 January, 2004, 02:50:26
doriangray try like this.
should give you some idea of whats going wrong.
who = Arg1(data)
if who then
   local usr = GetItemByName(who)
   if usr == nil then
      user:SendData(BotName, who.." isn't in the hub|")
   else
      -- do your userinfo stuff here
   end
else
   user:SendData(BotName, "something gone wrong here, couldn't proces the command. who wasn't found!|")
end
if something goes wrong then try inserting some debugging lines like i did on the above.

plop
Title:
Post by: DorianG on 20 January, 2004, 10:44:48
oh!! Yes  :D . Thank you. Now It's all right.  ;)