PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: ??????Hawk?????? on 03 November, 2003, 01:21:24

Title: Functions
Post by: ??????Hawk?????? on 03 November, 2003, 01:21:24
Heya peeps  im quite new to Lua and was wandering if there is a list/collection of functions.

If not  then maby ppl could start sharing their functions in this thread...

Title:
Post by: BlazeXxX on 03 November, 2003, 01:25:12
hmm i think it can be found in LUA guide... it was somewhere in forum... chek  the Useful links section..
Title:
Post by: ??????Hawk?????? on 03 November, 2003, 01:47:24
cant seem to find anything    :(

maby im missing it..

if anyone comes across any links to or lists of functions could you please post it in here and ill check back tommorow.


Many Thanks
Title:
Post by: nErBoS on 03 November, 2003, 02:06:29
Great to see you here .)

This is a great manual for LUA-coding

http://www.lua.org/manual/4.0/manual.html#pm

To scritp see the section How To Do.

Best regards, nErBoS
Title:
Post by: ??????Hawk?????? on 03 November, 2003, 14:38:32
Thanks for that link m8

Im hoping in time i will be able to put some constructive input in to this forum but for now im a noob ( to lua anyway ) striving to take in as much as i can.

I guess im going to be living here for a good while now.   :)

so the search goes on............

c'mon all you Great script writers share your knowlage and zip your functions up and post them here  and give us noobs a kick start in understanding Lua in ptokax.

 :)       :)        :)         :)        :)
Title:
Post by: ??????Hawk?????? on 06 November, 2003, 19:20:25
:(    :(           :(             :(         :(

well i guess ive gotta learn the hard way as i did with VB

thx to the 2 that did respond   :)
Title:
Post by: Skrollster on 06 November, 2003, 19:35:44
What sort of functions are you looking for?

i have a whole archive with functions...and a head full with knowleage about lua

i'm not too active right now though since i'm waiting for my new mother board to come so I can start using my own computer again..

but if you are looking for something please ask here!!

cheers mate
Title:
Post by: Skrollster on 06 November, 2003, 19:59:54
here comes some good functions and a good structure:

function DataArrival(tUser, sData)
if (strsub(sData, 1, 1) == "<" ) then
-- create a table
local tArgs = {}
-- Save sData in an array
tArgs = tHelpFunctions:GetArgs(sData)
-- Check if the user has used any of the hubprefixes
tArgs = tHelpFunctions:CheckIfHasPrefix(tArgs)
-- add sData as a variable to tArgs
tArgs.sData = sData
if tArgs.sPrefix then
tUser.SendMessage = tUser.SendData
local returnvalue = call(UserCommands[tArgs.sCmd],{UserCommands,tUser,tArgs}, "x", nil)
if returnvalue then
return returnvalue
else
return 0
end
else -- messages that isn't commands ends up here
end
end
end
tSettings = {
tCmdPrefixes = {"!","+","gs:","?","#","?"},
}

tHelpFunctions = {
CheckIfHasPrefix = function(self,tArgs)
sToCheck = tArgs.sCmd
local i
local err
for i = 1, getn(tSettings.tCmdPrefixes) do
if strsub(sToCheck, 1, strlen(tSettings.tCmdPrefixes[i])) == tSettings.tCmdPrefixes[i] then
tArgs.sCmd = strsub(sToCheck, strlen(tSettings.tCmdPrefixes[i])+1, strlen(sToCheck))
tArgs.sPrefix = tSettings.tCmdPrefixes[i]
break
end
end
return tArgs
end,
GetArgs = function(self,sData)
local tArgs = {}
_,_,sData = strfind(sData, "%b<>%s+(.+)|")
tArgs.sMessage = sData
sData = strlower(sData)
gsub(sData, "(%S+)", function (w) tinsert(%tArgs,w) end)
tArgs.sCmd = tArgs[1]
tremove(tArgs, 1)
return tArgs
end,
}

UserCommands = {
help = function(self, tUser, tArgs)-- for all users
-- Do your own help function here :)
return 1
end,
}
Title:
Post by: ??????Hawk?????? on 10 November, 2003, 00:04:05
Thx for the reply m8...

im just looking for a whole collection of  functions  to get me  started  in understanding   how   LUA  works  in relation to VB   then  maby  ill get to grips with it.  :-)
Title:
Post by: pHaTTy on 10 November, 2003, 00:15:17
start here (http://board.univ-angers.fr/thread.php?threadid=44&boardid=4&styleid=1&sid=4b7748f53b03fd8283dde54bdf3f909e)

then move to lesson 2 then 3 etc etc
Title:
Post by: ??????Hawk?????? on 11 November, 2003, 00:33:57
thx m8   i read them  when i joined  but they dont tell me what im really wanting to know


EG:-

data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)") -- this converts it into cmd (the incoming data)

how does it do it.  what does

s=
e=

if i wanted to brake data sent to the hub bot down  what functions do i use to split this:-

$To: HubBot From: User $ +command theText

bot=HubBot
user=User
CmdPrf=+
command=command
text=theText



And the same for main chat...... ????



is there and  texts that will help  understand Lua In ptokaks hub software ??
Title:
Post by: tezlo on 11 November, 2003, 11:12:36
yes.. the manual (http://www.lua.org/manual/4.0/manual.html)

strfind (s, pattern [, init [, plain]])
Looks for the first match of pattern in s. If it finds one, then strfind returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. If the pattern specifies captures (see gsub below), the captured strings are returned as extra results. A third, optional numerical argument init specifies where to start the search; its default value is 1, and may be negative. A value of 1 as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain ``find substring'' operation, with no characters in pattern being considered ``magic''. Note that if plain is given, then init must be given too.


so.. theres no need to remove the end pipe as you can put it in the regexp too
"this converts it into cmd" nothing gets converted. it just tries to extract the first word

you either want to use a bunch of strsubs and plain strfinds like in VB
or one strfind and a proper regexp.. ie

$To: HubBot From: User $ +command theText
local s, e, to, cmd, args = strfind(data, "^$To: (%S+) From: %S+ $%b<> %+(%a+)%s*(.*)%|$")