Shawak
Intermediate OT User
Here a npc to create an account while talking with him! (goot for war server)
data/npc/acc maker.xml
data/npc/scripts/account.lua
I hope you'll rep me if you like it :thumbup:.
Regards,
Shawak
data/npc/acc maker.xml
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Account Maker" nameDescription="an account maker" script="account.lua" walkinterval="2000" floorchange="0" skull="green">
<health now="100" max="100"/>
<look type="130" head="39" body="122" legs="125" feet="57" addons="0"/>
</npc>
data/npc/scripts/account.lua
Lua:
local config = {
teleport_after_creating = {x=1000, y=1000, z=7},
teleport_after_creating_used = false,
number = {
lenght = 10,
allowed_letters = {
-- ABC
"A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z",
-- abc
"a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z",
-- numbers
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
}
},
password = {
lenght = 12,
allowed_letters = {
-- ABC
"A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z",
-- abc
"a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z",
-- numbers
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
}
}
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local numberS = {}
local passwordS = {}
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)
state.set(talkUser, 0)
npcHandler:onCreatureDisappear(cid)
end
function onThink()
end
local state = {
set = function(talkUser, state)
talkState[talkUser] = state
end,
get = function(talkUser)
return talkState[talkUser]
end
}
local account = {
number = {
set = function(talkUser, number)
numberS[talkUser] = number
end,
get = function(talkUser)
return numberS[talkUser]
end,
exist = function(number)
local query_number = db.getResult("SELECT `name` FROM `accounts` ORDER BY `id` ASC;")
repeat
if query_number:getDataString("name") == number then
return true
end
until not query_number:next()
return false
end
},
password = {
set = function(talkUser, password)
passwordS[talkUser] = password
end,
get = function(talkUser)
return passwordS[talkUser]
end
},
create = function(number, password)
db.executeQuery("INSERT INTO `accounts` (`name`, `password`, `premdays`, `lastday`, `email`, `key`, `blocked`, `warnings`, `group_id`) VALUES ('"..number.."', '"..password.."', 0, 0, '', '0', 0, 0, 1);")
end
}
function answer(msg, text)
return msgcontains(msg, text) and true or false
end
function string.toTable(str)
local str_table = {}
for s = 1, string.len(str) do
table.insert(str_table, string.sub(str, s, s))
end
return str_table
end
function creatureSayCallback(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if answer(msg, "account") then
selfSay("What do you want as account number?", cid)
state.set(talkUser, 1)
elseif state.get(talkUser) == 1 then
local letters = string.toTable(msg)
for i = 1, #letters do
if isInArray(config.number.allowed_letters, letters[i]) == false then
return selfSay("This account number contains an invalid letter ("..i..").", cid)
end
end
if string.len(msg) > config.number.lenght then
return selfSay("This account number is too long.", cid)
end
local account_number = ""
for m = 1, #letters do
account_number = ""..account_number..""..letters[m]..""
end
if account.number.exist(account_number) == true then
return selfSay("\""..account_number.."\" already exist.", cid)
end
account.number.set(talkUser, account_number)
selfSay("Good your new account number will be \""..account_number.."\".\nWhat do you want as new password?", cid)
state.set(talkUser, 2)
elseif state.get(talkUser) == 2 then
local letters_pw = string.toTable(msg)
for i2 = 1, #letters_pw do
if isInArray(config.password.allowed_letters, letters_pw[i2]) == false then
return selfSay("This account password contains an invalid letter ("..i2..").", cid)
end
end
if string.len(msg) > config.password.lenght then
return selfSay("This account password is too long.", cid)
end
local account_password = ""
for m2 = 1, #letters_pw do
account_password = ""..account_password..""..letters_pw[m2]..""
end
account.password.set(talkUser, account_password)
account.create(account.number.get(talkUser), account.password.get(talkUser))
selfSay("Good your new account password is \""..account_password.."\".\nNow you can login with \""..account.number.get(talkUser).."\" / \""..account.password.get(talkUser).."\".", cid)
state.set(talkUser, 0)
if config.teleport_after_creating_used == true then
doTeleportThing(cid, config.teleport_after_creating, TRUE)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|, I can make a {account} for you.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Bye |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_FAREWELL, "See you later |PLAYERNAME|!")
npcHandler:addModule(FocusModule:new())
I hope you'll rep me if you like it :thumbup:.
Regards,
Shawak