PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Madman on 08 October, 2004, 18:42:58

Title: Help/Req - Read from file
Post by: Madman on 08 October, 2004, 18:42:58
Hello, i use this code
function NewUserConnected(user)
if stats[user.sName] then
local tmp = stats[user.sName]
if tonumber(tmp[1]) < postcount0 then text0(user)
elseif tonumber(tmp[1]) < postcount1 then text1(user)
elseif tonumber(tmp[1]) < postcount2 then text2(user)
elseif tonumber(tmp[1]) < postcount3 then text3(user)
elseif tonumber(tmp[1]) < postcount4 then text4(user)
elseif tonumber(tmp[1]) < postcount5 then text5(user)
elseif tonumber(tmp[1]) < postcount6 then text6(user)
elseif tonumber(tmp[1]) < postcount7 then text7(user)
elseif tonumber(tmp[1]) < postcount8 then text8(user)
elseif tonumber(tmp[1]) < postcount9 then text9(user)
end
end
end

postcount0 = 200 --//0-199 shows nothing (if empty)
function text0(user)
SendToAll("") --//Should be empty
end

postcount1 = 400 --//200-399 shows text1
function text1(user)
SendToAll(Bot, "The tiny "..user.sName.." is here")
end

postcount2 = 600 --//400-599 shows text2
function text2(user)
SendToAll(Bot, "The weak chatter "..user.sName.." is here")
end

postcount3 = 800
function text3(user)
SendToAll(Bot, "The little chatter "..user.sName.." is here")
end

postcount4 = 1000 --//shows 800-999
function text4(user)
SendToAll(Bot, "Does "..user.sName.." ever stoptalking?")
end

postcount5 = 1200
function text5(user)
SendToAll(Bot, "Non stop talking "..user.sName.." is in the building....")
end

postcount6 = 1400
function text6(user)
SendToAll(Bot, "Bigmouth "..user.sName.." crashed in to the hub")
end

postcount7 = 1600
function text7(user)
SendToAll(Bot, ""..user.sName.." sure knows how to chat...")
end

postcount8 = 1800
function text8(user)
SendToAll(Bot, "With license to chat - "..user.sName.." has dropped in to the hub")
end

postcount9 = 2000 --//shows 1800-1999
function text9(user)
SendToAll(Bot, "Oh no! The peace and quit is over! "..user.sName.." has kicked down the door")
end

It checks if user got Xnr of post send textX
What i want to do is to put textX part in to a file called greattings.dat
It is little har to explain
Something like this...

NewUserConnected
if tonumber(tmp[1]) < postcount1 then do greattings.dat
show msg..
end

postcount1 = 200

and the dat file... i guess wold look something like this..
["200"]= ""The weak chatter "..user.sName.." is here""

The entire Script can be found here http://destruction.myftp.org/filer/dc/chatsstatsv2.2.lua

Can anybody do this for me or give me some code sample of how it should be done....
Title:
Post by: Herodes on 08 October, 2004, 19:46:58
This is a nice thread to see ...  (http://board.univ-angers.fr/thread.php?threadid=2332&boardid=4&styleid=1)

Especially read the thread for functions to Read a file and use  the serialize function for loading a table ....

furthermore ...  get some script that uses table to define the scripts behaviour from a table . .. and then make yours act like it ... it will save u so much code ...
Title:
Post by: Madman on 08 October, 2004, 22:56:34
Woow... I dont even understand half of what that thread said....
I'm not so good at this....it took me atleast a day to figuer how to do the

postcount9 = 2000 --//shows 1800-1999
function text9(user)
SendToAll(Bot, "Oh no! The peace and quit is over! "..user.sName.." has kicked down the door")
end

thing.....
Title:
Post by: Herodes on 09 October, 2004, 14:24:18
Do you really think it took me less than a day to understand how to lua ?

no .. it took lots of time , days and months ..

anyhow .. the best way is to expiriment and keep hoping ...
all the functions that u need are in that thread ... test them ! see what u can do with them ... if you are not understanding smth then have a look in this (http://www.lua.org/manual/4.0/) which really is the key to understanding the lang...

and A-l-w-a-y-s expiriment ! :)