Author Topic: another script i m tryin my hands on  (Read 11616 times)

0 Members and 1 Guest are viewing this topic.

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: another script i m tryin my hands on
« Reply #25 on: 13 July, 2008, 13:23:18 »
an input box can be added with %[line:<title>]

So you're UserCommand will be
Quote
$UserCommand 1 3 RegUser Menu\\Add a request$<%[mynick]> +request %[line:Title]&#124;|

Before sending UserCommands to users, make sure their clients support that.
A Client sends $Supports UserCommands during login.
PtokaX stores if this has been send or not.
You can check this with
Code: [Select]
if Core.GetUserValue(User,12) == true then

PtokaX forum

Re: another script i m tryin my hands on
« Reply #25 on: 13 July, 2008, 13:23:18 »

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Re: another script i m tryin my hands on
« Reply #26 on: 14 July, 2008, 12:48:50 »
Hey CG thanks a lot for dat..
i will very soon try dat and will let ya know abt the out comes

thanks Satz

Eyes says everything,
Its on you how u read em...

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Re: another script i m tryin my hands on
« Reply #27 on: 17 July, 2008, 10:36:24 »
Code: [Select]

emp = {} -- creating a table to hold record of employee
-- no definition of keys/values needed in lua
-- Assuming Employer object with fields .Name and .Age

sFilename = "myfile.tbl" -- creating global var holding the file name


AddRecord = function(Employer) -- function to store employer name and age in table
emp[Employer.Name] = Employer.Age
end

GetRecord = function(Name) -- function to return age by name (or 0 if employer not found)
if emp[Name] then
return emp[Name]
else
return 0
end
end

DelRecord = function(Name) -- function to remove employer by name
if emp[Name] then
emp[Name] = nil
return true -- return true on success
else
return false -- return false, employer not found
end
end

LoadRecords = function() -- function to load file data into table
local hFile = io.open(sFilename)
if hFile then
hFile:close()
emp.items = dofile(sFilename)
end
end

SaveRecords = function() -- function to store table data into file
local hFile = io.open(sFilename, "w+")
if hFile then
hFile:write(Serialize(emp,"emp"))
hFile:flush()
hFile:close()
end
end

Serialize = function(tTable, sTableName, sTab)
--function to transform table data into readable file structure
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in pairs(tTable) do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end

Is this example of any help ?


this is how u xplained me table, with wich i have made a script wich keeps record of the userip at the time of registration.

Now a normal table say

Code: [Select]
user = {
   ["Peter"] = 10.40.181.225,
   ["John"] = 10.40.181.226,
   ["Albert"] = 10.40.181.227,
}

wud have the contents as shown above, now this time i want to store date and also time along with the user ip,

wich i wud use to show the user wen he logs in wen he was online in the hub last time. Wich is a common trend these days in the websites.

So i want to store Date and Time along with the IP

the content might be like this:
Code: [Select]
user = {
   ["Peter"] = {10.40.181.225,7/12/2008,15.36.53}
   ["John"] = 10.40.181.226,7/12/2008,15.36.53}
   ["Albert"] = 10.40.181.227,7/12/2008,15.36.53}
}
This is wat i think i wud look like, if i m wrong then pls help me out with dat.

but this is wat i want, u gave me function Serialize wich is used to store this in the file, so wat wud be the changes to be done to store such table in the same file, with the user table is ready with records in it.


thanks Satz

Eyes says everything,
Its on you how u read em...

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: another script i m tryin my hands on
« Reply #28 on: 17 July, 2008, 16:00:01 »
you are almost right, this is what it will look like

Quote
user = {
   ["Peter"] = {"10.40.181.225","7/12/2008","15.36.53",},
   ["John"] = {"10.40.181.226","7/12/2008","15.36.53",},
   ["Albert"] = {"10.40.181.227","7/12/2008","15.36.53",},
}

But when you add values to a table like that, LUA will automatically generate keys and you have a table within a table.

Code: [Select]
user = {
["Peter"] = {
[1] = "10.40.181.225",
[2] = "7/12/2008",
[3] = "15.36.53",
},
["John"] = {
[1] = "10.40.181.226",
[2] = "7/12/2008",
[3] = "15.36.53",
},
["Albert"] = {
[1] = "10.40.181.227",
[2] = "7/12/2008",
[3] = "15.36.53",
},
}

If you'd use the Serialize function, that is how it will be written to disk.

Suppose Peter logs in and you want to show him his info, the code would be.
Code: [Select]
Core.SendToUser(User,"<Login info> Hello "..User.sNick..". This is your info\n\n\tYour IP:\t\t"..user[User.sNick][1].."\n\tDate you logged in:\t"..user[User.sNick][2].."\n\tTime you logged in:\t"..user[User.sNick][3].."|")
Resulting in
Quote
<Login info> Hello Peter. This is your info

   Your IP:      10.40.181.225
   Date you logged in:   7/12/2008
   Time you logged in:   15.36.53

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Re: another script i m tryin my hands on
« Reply #29 on: 17 July, 2008, 18:02:45 »
Hey CG thanks a lot for dat but still if u can xplain me in short like the way u did last time it will be more helpful for me.


Let me make it simpler for u..
from the last time lesson i know how to retrive the contents of the file into the table in the script, So lets say dat table user holds all the record

Code: [Select]
user
{
["ABC"]={"10.40.181.225","17/7/2008","15.03.56"}
["XYZ"]={"10.40.181.225","17/7/2008","15.03.56"}
}
Let the above be the user table contents wich are read from the file and are in the table in the script
so now help me with this

I want to show a Message to the user wen he connects to the hub with this msg

Code: [Select]
Welcome nick
You are logged in the hub with the IP: user.sIP, your ip at the registration time was (here i want to show the ip from the table user)
Last time u logged in the hub on (DATE FROM THE TABLE) at (TIME FROM THE TABLE)

So in short all i want to know is how to access ie display or compare all the members from the table, as of last time there was a single member in the table ie for each user there was his ip, but this time we have more than one value for each user nick.
I think i have made some sense :D

thanks Satz

Eyes says everything,
Its on you how u read em...

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: another script i m tryin my hands on
« Reply #30 on: 18 July, 2008, 12:54:08 »
Read my previous post again a bit more closely.  ;)
Although i send a different message then you , i do use the information in the table and send that to the user.
Check the [1], [2] and [3] indicators i use in the message.

I'm actually not quite sure how to make that example more clear.
If it doesn't help you, can you specify exactly on what point you get stuck ?

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Re: another script i m tryin my hands on
« Reply #31 on: 19 July, 2008, 09:28:41 »
Hey CG thanks a lot but i m really gettin no where with dat here is a small script wich i tried

Code: [Select]
usr = {}
OpConnected = function(user)
usr[user.sNick][1]=user.sIP
usr[user.sNick][2]=os.date("%A").." the "..os.date("%d").." of "..os.date("%B").." "os.date("%Y")
usr[user.sNick][3]=os.date("%T")
usr[user.sNick][4]=2014008




x="Welcome "..user.sNick.."\n"..
"Last time u where online on "..usr[user.sNick][2].." "..user[user.sNick][3].."\n\n"..
"Some of your important information: "..
"\tYour referal id: "..usr[user.sNick][4]..
"\tYour registered ip: "..usr[user.sNick][1]
Core.SendPmToUser(user, "INFO", x)
end

See the above code i have tried once but its not helping me in any ways :(
i don understand where i m worng, wud u please tell me a small code just like u did last time.

thanks Satz

Eyes says everything,
Its on you how u read em...

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: another script i m tryin my hands on
« Reply #32 on: 19 July, 2008, 13:08:35 »
Well, there's nothing really wrong with your code, but there's a few things you could have a look at.
Not all, but some of these in the list can cause that you do not get a message (i assume that is what the problem is ?)


  • 'x' should be declared as local
Code: [Select]
local x =
  • The date and time you overwrite when the user logs in, so it will always be current time
  • OpConnected is only triggered when a user with bIsOP property = true enters. Use UserConnected and RegConnected to cover the other profiles.
Code: [Select]
UserConnected = OpConnected
  • "INFO" as sender of the PM needs to be registered as bot. DC++ clients by default ignore pm's from offline users (which include unregistered bots)
  • As you work with a new user, you need to add a table entry for the user first before you can add sub values. 
Set
Code: [Select]
usr[user.sNick] = {} before you use
Code: [Select]
usr[user.sNick][1]=user.sIP

I'm not fully awake yet, so I may have missed something but i'm pretty sure that created a new table for the current user and registering the sender of pm (or change it to SetMan.GetString(21)  the default bot) will do the trick.
Other then that, I see no reason why it shouldn't work, you have the principles right :)

« Last Edit: 19 July, 2008, 13:11:21 by CrazyGuy »

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Re: another script i m tryin my hands on
« Reply #33 on: 20 July, 2008, 13:54:33 »
Hey CG thanks a lot its workin fine

heres one more:

from the user nick i want to find wats inside the []

for ex:
Code: [Select]
[123]Alen
so i have written the following code for dat
Code: [Select]
local id=user.sNick:find("(%b)[]")
and its says dat its a nil value

nething missing with my codin????

thanks Satz

Eyes says everything,
Its on you how u read em...

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Re: another script i m tryin my hands on
« Reply #34 on: 20 July, 2008, 19:07:33 »
well mutor i have done dat as many times as u wud have imagined but its of no use, there is no example wat so ever in dat manual and also there are no simple and xact xplanation as ne1 need.

once again mutor this is something between me and CG, if he says dat i m bugin him its fine i will stop, but i never asked u in this thread any single time it was CG who came forward n helped me as i wantd, and i thank him every single time. And if readin Manuals wud had done a great deal then we shud have these help or how-to forums

thanks Satz

Eyes says everything,
Its on you how u read em...

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: another script i m tryin my hands on
« Reply #35 on: 21 July, 2008, 13:56:39 »
Hey CG thanks a lot its workin fine

heres one more:

from the user nick i want to find wats inside the []

for ex:
Code: [Select]
[123]Alen
so i have written the following code for dat
Code: [Select]
local id=user.sNick:find("(%b)[]")
and its says dat its a nil value

nething missing with my codin????

thanks Satz

Quote from: Mutor
%bxy Matches the balanced string from character x to character y (e.g. nested parenthesis).


You want to find what is within the square brackets [ and ].
So that'll be %b[]    ( although i'm not 100% sure if the brackets are counted as special chars and need to be escapded with \ )

Also, I'm pretty sure i've explained before that the first 2 return values of find are the index and length of the pattern you are looking for. As you want to know what is between the brackets and not where in the string the pattern is, your variable 'id' should be the third variable after keyword 'local'
Code: [Select]
local _,_,id=user.sNick:find("(%b[])")
Give that a try, I'm not sure it works though.



Quote from: Mutor
Something between you and he? This is a public forum.
It is, he is right. And I'd welcome other scripters to join this post with questions and answers.
I'm not all knowing :P


Quote from: satya
well mutor i have done dat as many times as u wud have imagined but its of no use, there is no example wat so ever in dat manual and also there are no simple and xact xplanation as ne1 need.
Actually everything can be found in the manual, but I can understand why it can be hard to see it all the first few times.
Especially string patterns have given me a headache for the longest time when learning lua.
Often I simply tried things in code and once I got it working and figured out why it worked, I read back in the manual and was like "aha, so that's how they meant that".


Either way, I wanna use this topic to help explain principles, not to code for someone. There's 1000 topics for that in the Request sections ;)
Personally I find it easier to explain using examples and I get the impression satya finds it easier to learn by watching examples.
I do think there's progress though, certainly if you consider we started with C  ;D

I was gonna write something else, but I forgot. Will add when I remember :P

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Re: another script i m tryin my hands on
« Reply #36 on: 24 July, 2008, 19:04:33 »
Hey CG thanks a lot for dat.

Quote from: CrazyGuy
Also, I'm pretty sure i've explained before that the first 2 return values of find are the index and length of the pattern you are looking for.
Hey i had forgotten dat :D well now i rem but using dat manual i found my way out my self, instead of string.find i used string.sub

Code: [Select]
id=user.sNick
id=id:sub(1,8)

Now the above code will return string from position 1 to 8, wich is wat i wanted cos the id is 7 digit long :D

Here take a look at the code wich i made by myself
I run a hub at my place these days it been rockin so now i have got an idea of doin the referral registration system wich we see these days on many site, so this is a script wich checks the ref id and if its valid then lets the user to enter the hub else it disconnects it

Code: [Select]
usref = {}
local refFile=Core.GetPtokaXPath().."scripts/table/usref.txt"

UserConnected = function(user)
LoadRecords()
local flag=0
local id=user.sNick
local nik
id=id:sub(2,8)


for k in pairs(usref) do
if usref[k] == id then
flag=1
nik=k
end
end

if flag == 1 then
x="\n\t\t\t\tWelcome "..user.sNick.."\n"..
"\t\t YOU HAVE PROVIDED A VALID USER ID:"..id.."\n"..
"\t\t NOW YOU CAN ENTER THE HUB BUT U WONT B ABLE TO DOWNLOAD ANYTHING FROM THE HUB\n"..
"\t\t VERY SOON U WILL B CONTACTED BY ONE OF THE OPERATORS FOR U REGISTRATION PROCESS\n"..
"\t\t PLEASE BE ACTIVE"
Core.SendPmToUser(user,"Stifler",x)
x="\n\n\t\t\t\t\tATTENTION OPERATOR\n"..
"\tA USER HAS LOGGED IN THE HUB WITH THE ID: "..id.." which from our records is valid for the user: "..nik
Core.SendPmToOps("REFERAL",x)
else
x="\n\tRegistration for the hub has been closed\n"..
"\tRegistration for the hub has been closed\n"..
"\tRegistration for the hub has been closed\n"..
"\tRegistration for the hub has been closed\n"..
"\tRegistration for the hub has been closed\n"..
"\tRegistration for the hub has been closed\n"..
"\tRegistration for the hub has been closed\n"..
"\tNOW REGISTRATION ONLY ON REFERRAL BASIS U CAN ENTER THE HUB WITH A REFERRAL ID OF A REGISTERED USER,\n"..
"\tEVERY USER HAS A REFERAL ID, YOU CAN ASK FOR ONE\n\n"..
"\tAFTER U GET THE ID U CAN PREFIX THE ID IN UR NICK AS FOLLOWS\n"..
"\t\t\tIF ALEN IS THE NICK AND THE REF ID IS 1025555 THIS IS HOW U HAVE TO ENTER IT: [1025555]Alen\t\t\t\t\n"
Core.SendToUser(user, "<Stifler>"..x)
Core.Disconnect(user)
end

end


LoadRecords = function() -- function to load file data into table THE SAME ONE WICH U HELPED ME FOR THE TABLE CODE
local hFile = io.open(refFile)
if hFile then
hFile:close()
usref.items = dofile(refFile)
end
return
end


Well CG thanks a lot for been kind and helping me with those explanation and most importantly those examples wich helped me a lot.

Quote from: CrazyGuy
I get the impression satya finds it easier to learn by watching examples.

U are absolutely right buddy and this is the reason why i always asked u for an example never the full coding except for dat table thing which was entirely new thing for me. And about the manual ya it helpful in many ways but the string and the os functions needed to have some examples for users like me.

Well CG i want to show u some scripts wich i made after u explained me stuffs.

1st i made rather i shud say i changed ur example code wich u showed to me for dat emp :D

but i learnt a lot from it and i have made a script with 4 tables
one for ip another for date of last login another for time of last login and last one holds the REF ID wich i was talkin abt a while ago

2nd rem once i asked abt those command and all

Quote from: Satya
Hey CG some help againn Cheesy


wat we need to do if we want to get all the text after a keyword say for example

Code:

+request The Hancock movie


how can i get thing after +request into a var in the above example "The Hancock movie"

thanks Satz

rem this ???
to which u gave such an awesome reply dude, this kind of explanation shud be in the manual simple with examples. ;)

ok so using dat i have made few commands for my hub operators and hub registered members, take a look

Code: [Select]
request = function(user,data,cmd)
local _,_,uReq = data:find("%b<> %p"..cmd.."%s(.*)|")

local msg="\r\n\r\n\t\t\tATTENTION OPERATOR\r\n"..
"\t\t"..user.sNick.." has submitted a request:\r\n"..
"\t\t\t"..uReq

Core.SendPmToOps("UserReq", msg)
Core.SendPmToUser(user, "UserReq" , "Your request has been submitted to the operators")
end

suggest = function(user,data,cmd)
local _,_,cs,uSug = data:find("%b<> %p"..cmd.."%s(%S+)%s(.*)|")
cs=cs:lower()
if cs =="cs" then
local msg="\r\n\r\n\t\t\tATTENTION OPERATOR\r\n"..
"\t\t"..user.sNick.." has submitted a suggestion for the Counter Strike Game:\r\n"..
"\t\t\t"..uSug
Core.SendPmToOps("UserReq", msg)
Core.SendPmToUser(user, "UserReq" , "Your suggestion has been submitted to the operators")
else
local _,_,uSug = data:find("%b<> %p"..cmd.."%s(.*)|")
local msg="\r\n\r\n\t\t\tATTENTION OPERATOR\r\n"..
"\t\t"..user.sNick.." has submitted a suggestion:\r\n"..
"\t\t\t"..uSug
Core.SendPmToOps("UserReq", msg)
Core.SendPmToUser(user, "UserReq" , "Your suggestion has been submitted to the operators")
end
end
There are lot more :D

And dats all buddy now i can think abt a script and make it myself all credit goes to u for helping me always and wenever i was in need it.

Hey one more thing buddy with the new version of the ptokax they provide those HTML files with functions and useful scripting information, using dat i have developed a HUB auto shutdown script check it out and do suggest any improvements u think of.

Code: [Select]
OnStartup=function()
Timer = TmrMan.AddTimer(60000)
OnTimer(Timer)

end

OnTimer = function()
time=os.date("%T")
tx=time:sub(1,2)
if tx == "5" then
Core.Shutdown()
end
end

OpConnected = function(user)
local x="\n\n\t\t\tWELCOME "..user.sNick.."\n"..
"\t This is the night session of the hub where there will be not operator in the hub\n"..
"\t The will remain active throught the night till morning at 5.00 AM\n"..
"\t And in the morning the hub will AUTO SHUTDOWN\n"
Core.SendPmToUser(user, "Stifler", x)
end

RegConnected=OpConnected

Thanks Satz

Eyes says everything,
Its on you how u read em...

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: another script i m tryin my hands on
« Reply #37 on: 24 July, 2008, 21:07:21 »
Hey Satya,

Good to hear you're enjoying scripting that much  8)
The more experienced you'll get, the easier it will be and more fun it will be.
Then complicated ideas will arise and scripts get of such size that they'll be hard to follow.
But, if you succeed even with that, and place scripts here, peope will start bugging you for scripts.
And then the fun is over.......  :P  just kidding  ;D

Had 2 small things in your code I'd like to point out.
In the first code
Code: [Select]
local nik
That doesn't do anything in LUA. ( i think that's a C thingy ?)
if you want to reserve a variable 'nik' for later usage, you'll have to equal it to something.
Depending on what it will hold, you could use this.
  • local nik = ""
  • local nik = 0
  • local nik = {}
  • local nik = false

You can't see it in your code, but when you actually use 'nik' later on in your code, it will become a global variable,instead of a local var. Assigning it a base value assures the local keyword is honoured.


The second thing i saw was in your last code, regarding the OnTimer function.
Wether you are working with 1 or mutliple timers, it's a good idea to check if the timer triggering the event actually is the timer you are looking for. What i mean is, check the timer ID.

Code: [Select]
Timer = TmrMan.AddTimer(60000)
What you did there is you stored the timerID returned by the function AddTimer into variable Timer.
So you have this info, why not use it ?
The OnTimer function has a parameter nTimerID.
When the function is called, you can check if that parameter matches yours.
If so, execute the code. Else, do nothing.

Code: [Select]
OnTimer = function(nTimerID)
if nTimerID == Timer then
-- code
end
end

If you'd keep that as a habit, you'll have it easier later on when you use multiple timers in one script.


Keep up the good work  :D

PtokaX forum

Re: another script i m tryin my hands on
« Reply #37 on: 24 July, 2008, 21:07:21 »