• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Acc Maker!

Shawak

Intermediate OT User
Joined
Sep 11, 2008
Messages
1,984
Solutions
2
Reaction score
120
Location
Germany
GitHub
Shawak
Here a npc to create an account while talking with him! (goot for war server)

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
 
First:
Just question:
Do you know what mean "TRUE" in doTeleportThing?

Second:
Code:
account_password = ""..account_password..""..letters_pw[m2]..""

Same here:
Code:
account_number = ""..account_number..""..letters[m]..""

Why not just:
Code:
account_password = account_password..letters_pw[m2]

Third:
Why the fuck are you writing this:
Code:
state.set(talkUser, 1)

While you can use normal table to set:
Code:
talkState[talkUser] = 1

And to get:
Code:
talkState[talkUser]

Fourth:
Just little question:
Code:
return selfSay("This account number contains an invalid letter ("..i..").", cid)

Do you know what is return statement of selfSay(words[, target[, type]])?

Fifth:
What is it?
Reapeating while we have thousands accounts in database? Sux man...
Code:
                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

PLX PLX:
Code:
exist = function(name)
	local query = db.getResult("SELECT FROM `accounts` WHERE `name` = '".. name .."';")
	if (query:getRows() > 0)
		return true
	else
		return false
	end
	return false
end

Hmm, maybe in future your programming skill will be better.
Keep writing :)
 
Last edited:
First:
Just question:
Do you know what mean "TRUE" in doTeleportThing?

true mean pushmove.

Second:
Code:
account_password = ""..account_password..""..letters_pw[m2]..""

Same here:
Code:
account_number = ""..account_number..""..letters[m]..""

Why not just:
Code:
account_password = account_password..letters_pw[m2]

I didn't knew I can wirte <variable>..<variable.. :).
Thanks for showing.

Third:
Why the fuck are you writing this:
Code:
state.set(talkUser, 1)

While you can use normal table to set:
Code:
talkState[talkUser] = 1

And to get:
Code:
talkState[talkUser]
First I startet to make the acc manager for fun and tried out some functions :thumbup:. (I wasn't going to release it)

Fourth:
Just little question:
Code:
return selfSay("This account number contains an invalid letter ("..i..").", cid)

Do you know what is return statement of selfSay(words[, target[, type]])?
Forgot to delete return xd.

Fifth:
What is it?
Reapeating while we have thousands accounts in database? Sux man...
Code:
                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

PLX PLX:
Code:
exist = function(name)
	local query = db.getResult("SELECT FROM `accounts` WHERE `name` = '".. name .."';")
	if (query:getRows() > 0)
		return true
	else
		return false
	end
	return false
end
Fail from me there :).

Hmm, maybe in future your programming skill will be better.
Keep writing :)
Yes they will become better.

PS:
Code:
exist = function(name)
	local query = db.getResult("SELECT FROM `accounts` WHERE `name` = '".. name .."';")
	if (query:getRows() > 0)
		return true
	else
		return false
	end
	return false
end
Better:
Code:
exist = function(name)
	local query = db.getResult("SELECT FROM `accounts` WHERE `name` = '".. name .."';")
	if (query:getRows() > 0) then
		return true
	end
	return false
end
 
Ehm.

Shawak said:
true mean pushmove.
Yapzor.



Shawak said:
I didn't knew I can wirte <variable>..<variable.. :).
Thanks for showing.
NP :)



Shawak said:
First I startet to make the acc manager for fun and tried out some functions :thumbup:. (I wasn't going to release it)
So don't use your useless functions in public scripts? :p



Shawak said:
Forgot to delete return xd.
Return is required to stop executing rest of code, because we don't need check the rest if our acc is not allowed. But my question was "Do you know what is return statement of selfSay(words[, target[, type]])?"



Shawak said:
Better:
Code:
exist = function(name)
	local query = db.getResult("SELECT FROM `accounts` WHERE `name` = '".. name .."';")
	if (query:getRows() > 0) then
		return true
	end
	return false
end

Not really, look:
Code:
	if (query:getRows() > 0) then
		rows > 0
	else
		rows <= 0
	end
	ops, something wrong o_O!
 
Last edited:
Good job boys, maybe in the future you've learned something ;D
 
Back
Top