PtokaX forum

Development Section => Your Developing Problems => Topic started by: ((UKSN))shad_dow on 11 January, 2004, 11:06:54

Title: Basic way to call a function command
Post by: ((UKSN))shad_dow on 11 January, 2004, 11:06:54
Dear All


can any body tell me please a basic way to all a function
command in the scripts .

example

function HelloNewUser(User)
                 
SendToAll(Bot,"Welcome  "..user.sName.." To Our Hub :)")

   
end

right thats a example fuction (syntex i think is ok.. LOL)

how do i call that fuction from the main part of the script

basicly all i wont it to undestand the basic command to call any fuction from in side  the  main body [function DataArrival(User)]

any help would be most helpfull :)

yours Shad  :D



Title:
Post by: kepp on 11 January, 2004, 11:40:37
Just an example..
function WelcomeVIP(user)
end

function NewUserConnected(user)
  if user.iProfile == 2 then
     WelcomeVIP(user)
  elseif user.iProfile == 3 then
      WelcomeReg()
   end
end
Title:
Post by: ((UKSN))shad_dow on 11 January, 2004, 11:49:35
cheers m8ty , undestand it now its in englisah .. lol  :D
Title: Along the same Lines....
Post by: WooshMan on 03 February, 2004, 15:00:25
Hi, I have a question which I have asked NightLitch and think I have done his head in.

Please can someone help to save me killing his head all together.

OK.. I want all my commands in a seperate lua file and called from the main lua.

Here is my functionDA

function DataArrival(user, data)

   if( strsub(data, 1, 1) == "<" ) then
   return MainCommands(user, data)
   end
end


Here is my function MainCommands

function MainCommands(user, data)

   data=strsub(data,1,strlen(data)-1)
   local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
   if not cmd then cmd = "0" end
   cmd = strlower(cmd)

   local SendCommand = (GetCommands(user,data,cmd))

   if not SendCommand then
   return 1
   else
   return SendCommand -- here again returning the commands
   end

end

And here is my GetCommands

function GetCommands(user,data,cmd)

if user.iProfile == 0 or user.iProfile == 1 then
   if cmd == "mc" then
   mc(user,data,cmd,msg)
   return 1
   end   
end

function mc(user,data,cmd,msg)
   s,e,cmd,msg=strfind(data, "%b<>%s+(%S+)%s+(.*)")   
   whofrom = user.sName
   SendPmToAll(botname, msg .." ")
   return 1

      end

end


I have tried to follow existing scripts and have tried with NL's help, but I still can't get it.

Now I think it is my function something(user,data,x,x,x)
I am not sure what to put in.

the !mc command I am trying will send a mass PM to all users.

I get no script errors but I don't get PM's sent either.

Please help and explain in PLAIN English where I am going wrong... or even correct my code and maybe comment it so i can understand from there.

Thanks in advance and thanks for a great forum.

WooshMan
Title:
Post by: WooshMan on 03 February, 2004, 15:59:11
Hi again....

I have spoken to Plop and he has explained where I was going wrong.

Here are my new files

function DataArrival(user, data)

   if( strsub(data, 1, 1) == "<" ) then
   MainCommands(user, data)
   end
end


function MainCommands(user, data)

   data=strsub(data,1,strlen(data)-1)
   local s,e,cmd = strfind(data, "%b<>%s+(%S+)")
   if not cmd then cmd = "0" end
   cmd = strlower(cmd)

   GetCommands(user,data,cmd)
end

I had made the above to complicated for me to understand...lol



function GetCommands(user,data,cmd)

   if user.iProfile == 0 or user.iProfile == 1 then
      if cmd == "!mc" then
         mc(user,data,cmd,msg)
         return 1
      end
   end
end


function mc(user,data,cmd,msg)
   s,e,cmd,msg=strfind(data, "%b<>%s+(%S+)%s+(.*)")
   whofrom = user.sName
   SendPmToAll(botname, msg .." ")
   return 1
end

The line which reads if com =="!mc" then

is now correct... i had cmd=="mc" so it never saw the it.

Thanks Plop.

Thank you to NL for his help in getting me as far as he did.

WooshMan
Title:
Post by: plop on 04 February, 2004, 04:15:50
yw.

plop
Title:
Post by: HaArD on 07 February, 2004, 15:05:21
Rally n00b question but what if I want to have a routine that requires no parms and returns no value?

Similar to calling a Sub in vbscript, how do I do that?
Define the Function as:
function DoStuff()
..
..
..
end function

and then call it with:
DoStuff()
Title:
Post by: NightLitch on 07 February, 2004, 16:13:33
ThX Woosh!

HaArD:

You will need to go by this ex:
function some(user,data)
if something then
DoStuff()
else
--dosimething else or nothing
end
end

hope this clear some for you
Title:
Post by: VidFamne on 07 February, 2004, 19:23:26
Are you thinking of this function, without any params or values?function DoStuff()
--// i.e. SendToAll("Hi")
end

--// for example in Main

function Main()
DoStuff()
end
Title:
Post by: kepp on 07 February, 2004, 19:24:54
^^ like nigth said, you just call it by the name, Not as in bv were you call a command with 'Call'
Title:
Post by: NightLitch on 07 February, 2004, 19:49:22
QuoteBy VidFamne
Are you thinking of this function, without any params or values?

Of course it must be a value or param this was just a
basic explaination from me.

But he asked only how to call the function not the hole cake... :-)
Title:
Post by: VidFamne on 07 February, 2004, 21:54:30
function DoStuff()
--// i.e. SendToAll("Hi")
end
function DoStuff(),
Surely dont need any parameters and it returns no value.
Just as HaArD asked for.
Title:
Post by: HaArD on 08 February, 2004, 15:06:28
I'd searched and searched and could not find a single script that did this so I was just a little unsure.

Thanks for all the replies and it works exactly as suspected and everyone replied. :D