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
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
cheers m8ty , undestand it now its in englisah .. lol :D
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
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
yw.
plop
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()
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
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
^^ like nigth said, you just call it by the name, Not as in bv were you call a command with 'Call'
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... :-)
function DoStuff()
--// i.e. SendToAll("Hi")
end
function DoStuff(),
Surely dont need any parameters and it returns no value.
Just as HaArD asked for.
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