• Congratulations to the OTLand January Mapping Competition Winner! The grand prize of Otland Premium goes to Andréew.
  • Sign up for February Mapping Competition! The prize includes Otland Premium time.
  • 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!

NPC [MySQL] Account Manager

Joined
Apr 17, 2008
Messages
1,922
Best answers
0
Reaction score
181
Location
Venezuela
Hello, this is a request from narko, you can see it here -> http://otland.net/f132/request-npc-account-maker-acc-player-ideas-make-107556/

  • Updated At: Wednesday December 08th, 2010 at 21:36 P.M (GMT -4:30)
  • Last Tested At: Wednesday December 08th, 2010 at 21:34 P.M (GMT -4:30)
  • Tested On: The Forgotten Server 0.3.6pl1



Update Log:
Code:
[B]V0.1.1: [08 / 12 / 2010][/B]
- Now the plauer name cannot be too long.
[B]V0.1: [08 / 12 / 2010][/B]
- Release of the new script
Features:
Code:
* Player can create a new account.
* Player can change the/him account password. (If you say "change" before creating a new account, you'll change the created account's password)
* Player can create a new character on the/him account. (If you create a new character before creating a new account, you'll create a character on the new account)
* All npc messages almost the account manager.
* You can't type character/account/password with invalid characters.
* You can't create a character with the first letter on lower case.
* You can't create a new character if your account has reached the character's limit (15)
* You can't create a new character if the name contains "gm", "cm" or "god".
* You can't create account/password/character if the text is too short.
* You can't create an account name if is the same as the password.
-- Same restriction as account manager.
--- Coming features (Delete character, new recovery key)
Create a new npc file on data/npcs and paste this (Default):
XML:
<?xml version="1.0"?>
 
<npc name="Account Manager" script="data/npc/scripts/accmaker.lua" access="3" walkinterval="2000" lookdir="2">
	<mana now="800" max="800"/>
	<health now="200" max="200"/>
<look type="110" head="1" body="1" legs="1" feet="1" addons="0"/>
</npc>
Now create a file on data/npcs/scripts called accmaker.lua and paste this:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)                          npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)                       npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)                  npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                                      npcHandler:onThink() end

npcHandler:setMessage(MESSAGE_GREET, "Hello, type {account} to create a new account, {character} to add a new character or {manage} to see all available features.")

local config =
{
	newPlayerChooseVoc = getConfigValue("newPlayerChooseVoc"),
	newPlayerSpawnPosX = getConfigValue("newPlayerSpawnPosX"),
	newPlayerSpawnPosY = getConfigValue("newPlayerSpawnPosY"),
	newPlayerSpawnPosZ = getConfigValue("newPlayerSpawnPosZ"),
	newPlayerTownId = getConfigValue("newPlayerTownId"),
	newPlayerLevel = getConfigValue("newPlayerLevel"),
	newPlayerMagicLevel = getConfigValue("newPlayerMagicLevel"),
	generateAccountNumber = getConfigValue("generateAccountNumber")
}

local account = 
{
	name = {},
	pass = {}
}

local character = 
{
	name = {},
	voc = {},
	sex = {}
}
local toBe = 0
local capMax = 400
local voc =
{
	["sorcerer"] = 1,
	["druid"] = 2,
	["paladin"] = 3,
	["knight"] = 4
}
function creatureSayCallback(cid, type, msg)

	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
	if msgcontains(msg, "account") then
		npcHandler:say("What would you like your password to be?", cid)
		talkState[talkUser] = 1
	elseif talkState[talkUser] == 1 then
		if msg ~= "" or msg ~= nil then
			toBe = string.gsub(msg, "[!'·#$%&/()=?¿¡.*\|;:,><{}]", "")
			npcHandler:say(toBe .. " is it {yes} or {no}?", cid)
			talkState[talkUser] = 2
		else
			npcHandler:say("What would you like your password to be?", cid)
		end
	elseif talkState[talkUser] == 2 and msgcontains(msg, "no") then
		npcHandler:say("What would you like your password to be?", cid)
		talkState[talkUser] = 1
	elseif talkState[talkUser] == 2 and msgcontains(msg, "yes") then
		account.pass[cid] = toBe
		if config.generateAccountNumber then
			toBe = string.format("%s%s%s%s%s%s%s", math.random(1, 9), math.random(1, 9), math.random(1, 9), math.random(1, 9), math.random(1, 9), math.random(1, 9), math.random(1, 9))
			local query = db.getResult("select id from accounts where name = " .. toBe .. ";")
			if query:getID() == -1 then
				account.name[cid] = toBe
				local query_ = db.executeQuery("insert into accounts (name, password) values (" .. db.escapeString(account.name[cid]) .. ", " .. db.escapeString(account.pass[cid]) .. ");")
				if query_ then
					npcHandler:say("Your account has been created, you may {manage} it now, but remember your account name: {" .. account.name[cid] .. "} and password: {" .. account.pass[cid] .. "}!", cid)
					talkState[talkUser] = 0
				else
					npcHandler:say("Your account cannot be created.", cid)
					talkState[talkUser] = 0
				end
			end
		else
			npcHandler:say("What would you like your account name to be?", cid)
			talkState[talkUser] = 3
		end
	elseif talkState[talkUser] == 3 then
		if msg ~= "" or msg ~= nil then
			toBe = string.gsub(msg, "[!·#$%&¬/()=?'¿¡.*\|;:,><{}]", "")
			if toBe == account.pass[cid] then
				npcHandler:say("Your account name cannot be the same as your password.", cid)
				talkState[talkUser] = 3
			else
				npcHandler:say(toBe .. " is it {yes} or {no}?", cid)
				talkState[talkUser] = 4
			end
		else
			npcHandler:say("What would you like your account name to be?", cid)
		end
	elseif talkState[talkUser] == 4 and msgcontains(msg, "no") then
		npcHandler:say("Od... then what would you like your account name to be?", cid)
		talkState[talkUser] = 3
	elseif talkState[talkUser] == 4 and msgcontains(msg, "yes") then
		local query = db.getResult("select id from accounts where name = " .. db.escapeString(toBe) .. ";")
		local deny = false
		if query:getID() ~= -1 then
			deny = true
			query:free()
		end
		if deny then
			npcHandler:say("An account with that name already exists, please try another account name.", cid)
			talkState[talkUser] = 3
		else
			account.name[cid] = toBe
			local query = db.executeQuery("insert into accounts (name, password) values (" .. db.escapeString(account.name[cid]) .. ", " .. db.escapeString(account.pass[cid]) .. ");")
			if query then
				npcHandler:say("Your account has been created, you may {manage} it now, but remember your account name: {" .. account.name[cid] .. "} and password: {" .. account.pass[cid] .. "}!", cid)
				talkState[talkUser] = 0
			else
				npcHandler:say("Your account cannot be created.", cid)
				talkState[talkUser] = 0
			end
		end
	elseif msgcontains(msg, "manage") then
		account.name[cid] = (account.name[cid] or getPlayerAccount(cid))
		local query = db.getResult("select password from accounts where name = " .. db.escapeString(account.name[cid]) .. ";")
		if query:getID() ~= -1 then
			account.pass[cid] = (account.pass[cid] or query:getDataString("password"))
			query:free()
		end
		npcHandler:say("You can {change} your pass or create a new {character}.", cid)
		talkState[talkUser] = 5
	elseif msgcontains(msg, "change") then
		npcHandler:say("Tell me your new password please.", cid)
		talkState[talkUser] = 6
	elseif talkState[talkUser] == 6 then
		if msg ~= "" or msg ~= nil then
			toBe = string.gsub(msg, "[!'·#$%&/()=?¿¡.*\|;:,><{}]", "")
			if string.len(toBe) < 6 then
				npcHandler:say("That password is too short, at least 6 digits are required. Please select a longer password.", cid)
			else
				npcHandler:say("Should {" .. toBe .. "} be your new password?", cid)
				talkState[talkUser] = 7
			end
		else
			npcHandler:say("What would you like your new password to be?", cid)
		end
	elseif talkState[talkUser] == 7 and msgcontains(msg, "no") then
		npcHandler:say("Then not.", cid)
		talkState[talkUser] = 0
	elseif talkState[talkUser] == 7 and msgcontains(msg, "yes") then
		local query = db.executeQuery("update accounts set password = " .. db.escapeString(toBe) .. " where name = " .. db.escapeString(getPlayerAccount(cid)).. ";")
		if query then
			npcHandler:say("Your password has been changed.", cid)
			talkState[talkUser] = 0
		else
			npcHandler:say("Your password cannot be changed.", cid)
			talkState[talkUser] = 0
		end
	elseif msgcontains(msg, "character") then
		local query = db.getResult("select count(id) as count from players where account_id = " .. getPlayerAccountId(cid) .. ";")
		if query:getID() ~= -1 then
			local t = query:getDataInt("count")
			if t >= 15 then
				npcHandler:say("Your account reach the limit of 15 players, you need delete a character if you want to create a new one.", cid)
				talkState[talkUser] = 0
			else
				npcHandler:say("What would you like as your character name?", cid)
				talkState[talkUser] = 8
			end
			query:free()
		end
	elseif talkState[talkUser] == 8 then
		if msg ~= "" or msg ~= nil then
			toBe = string.gsub(msg, "[!'·#$%&/()=?¿¡.*\|;:,><{}]", "")
			if string.len(toBe) < 4 then
				npcHandler:say("Your name you want is too short, please select a longer name.", cid)
			elseif string.len(toBe) > 20 then
				npcHandler:say("Your name you want is too long, please select a longer name.", cid)
			elseif string.sub(toBe, 0, 4) == "god " or isInArray({"gm ", "cm "}, string.sub(toBe, 0, 3)) then
				npcHandler:say("Your character is not a staff member, please tell me another name!", cid)
			elseif string.sub(toBe, 0, 1) == string.sub(toBe, 0, 1):lower() then
				npcHandler:say("Your name can not be the first letter in lower case.", cid)
			else
				local query = db.getResult("select id from players where name = " .. db.escapeString(toBe) .. ";")
				if query:getID() ~= - 1 then
					npcHandler:say("A player with that name already exists, please choose another name.", cid)
					query:free()
				else
					npcHandler:say(toBe .. " is it {yes} or {no}?", cid)
					talkState[talkUser] = 9
				end
			end
		else
			npcHandler:say("What would you like as your character name?", cid)
		end
	elseif talkState[talkUser] == 9 and msgcontains(msg, "no") then
		npcHandler:say("What else would you like to name your character?", cid)
		talkState[talkUser] = 8
	elseif talkState[talkUser] == 9 and msgcontains(msg, "yes") then
		character.name[cid] = toBe
		npcHandler:say("Should your character be a {male} or a {female}.", cid)
		talkState[talkUser] = 10
	elseif talkState[talkUser] == 10 and msgcontains(msg, "male") or msgcontains(msg, "female") then
		toBe = (msg == "male" and 1 or 0)
		npcHandler:say("A " .. msg .. ", are you sure?", cid)
		talkState[talkUser] = 11
	elseif talkState[talkUser] == 11 and msgcontains(msg, "no") then
		npcHandler:say("Tell me... would you like to be a {male} or a {female}?", cid)
		talkState[talkUser] = 10
	elseif talkState[talkUser] == 11 and msgcontains(msg, "yes") then
		character.sex[cid] = toBe
		if config.newPlayerChooseVoc then
			npcHandler:say("What do you want to be... {sorcerer}, {druid}, {paladin} or {knight}.", cid)
			talkState[talkUser] = 12
		else
			character.voc[cid] = 0
			local query = db.executeQuery("insert into players (id, name, world_id, group_id, account_id, level, vocation, health, healthmax, experience, lookbody, lookfeet, lookhead, looklegs, looktype, lookaddons, maglevel, mana, manamax, manaspent, soul, town_id, posx, posy, posz, conditions, cap, sex, lastlogin, lastip, skull, skulltime, save, rank_id, guildnick, lastlogout, blessings, online) VALUES (NULL, " .. db.escapeString(character.name[cid]) .. ", " .. getConfigValue("worldId") .. ", 1, " .. getAccountIdByAccount(account.name[cid]) .. ", " .. config.newPlayerLevel .. ", " .. character.voc[cid] .. ", " .. getVocationInfo(character.voc[cid]).healthGain * config.newPlayerLevel .. ", " .. getVocationInfo(character.voc[cid]).healthGain * config.newPlayerLevel .. ", " .. (config.newPlayerLevel < 2 and 0 or getExperienceForLevel(config.newPlayerLevel)) .. ", 68, 76, 78, 39, " .. (character.sex[cid] == 1 and 136 or 128) .. ", 0, " .. config.newPlayerMagicLevel .. ", 0, 0, 0, 100, " .. config.newPlayerTownId .. ", " .. config.newPlayerSpawnPosX .. ", " .. config.newPlayerSpawnPosY .. ", " .. config.newPlayerSpawnPosZ .. ", 0, " .. capMax + getVocationInfo(character.voc[cid]).capacity * config.newPlayerLevel .. ", " .. character.sex[cid] .. ", 0, 0, 0, 0, 1, 0, '', 0, 0, 0);")
			if query then
				npcHandler:say("Your character has been created.", cid)
				talkState[talkUser] = 0
			else
				npcHandler:say("Your character couldn't be created, please try again.", cid)
				talkState[talkUser] = 5
			end
		end
	elseif talkState[talkUser] == 12 then
		if voc[msg] then
			npcHandler:say("So you would like to be " .. msg .. "... are you sure?", cid)
			toBe = voc[msg]
			talkState[talkUser] = 13
		else
			npcHandler:say("I don't understand what vocation you would like to be... could you please repeat it?", cid)
		end
	elseif talkState[talkUser] == 13 and msgcontains(msg, "no") then
		npcHandler:say("No? Then what would you like to be?", cid)
		talkState[talkUser] = 12
	elseif talkState[talkUser] == 13 and msgcontains(msg, "yes") then
		character.voc[cid] = toBe
		local query = db.executeQuery("insert into players (id, name, world_id, group_id, account_id, level, vocation, health, healthmax, experience, lookbody, lookfeet, lookhead, looklegs, looktype, lookaddons, maglevel, mana, manamax, manaspent, soul, town_id, posx, posy, posz, conditions, cap, sex, lastlogin, lastip, skull, skulltime, save, rank_id, guildnick, lastlogout, blessings, online) VALUES (NULL, " .. db.escapeString(character.name[cid]) .. ", " .. getConfigValue("worldId") .. ", 1, " .. getAccountIdByAccount(account.name[cid]) .. ", " .. config.newPlayerLevel .. ", " .. character.voc[cid] .. ", " .. getVocationInfo(character.voc[cid]).healthGain * config.newPlayerLevel .. ", " .. getVocationInfo(character.voc[cid]).healthGain * config.newPlayerLevel .. ", " .. (config.newPlayerLevel < 2 and 0 or getExperienceForLevel(config.newPlayerLevel)) .. ", 68, 76, 78, 39, " .. (character.sex[cid] == 1 and 136 or 128) .. ", 0, " .. config.newPlayerMagicLevel .. ", 0, 0, 0, 100, " .. config.newPlayerTownId .. ", " .. config.newPlayerSpawnPosX .. ", " .. config.newPlayerSpawnPosY .. ", " .. config.newPlayerSpawnPosZ .. ", 0, " .. capMax + getVocationInfo(character.voc[cid]).capacity * config.newPlayerLevel .. ", " .. character.sex[cid] .. ", 0, 0, 0, 0, 1, 0, '', 0, 0, 0);")
		if query then
			npcHandler:say("Your character has been created.", cid)
			talkState[talkUser] = 0
		else
			npcHandler:say("Your character couldn't be created, please try again.", cid)
			talkState[talkUser] = 5
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:

Exedion

Active Member
Joined
Jun 11, 2007
Messages
628
Best answers
0
Reaction score
28
Wow! this will reduce the work for TFS 0.4 (in TO-DO file say: REMOVE HARDCODED FEATURES LIKE ACC MANAGER A RE-DO IN LUA) xD
 

Santi

Theres no way im stopping
Joined
Aug 29, 2010
Messages
1,975
Best answers
0
Reaction score
149
Location
00
Awesome work.
 

narko

vertrauenswürdig ~
Joined
Oct 19, 2008
Messages
1,317
Best answers
2
Reaction score
115
Location
Unknown
:DDD thankkksksksskskskksksssskksksksksksk you are r0x
 

narko

vertrauenswürdig ~
Joined
Oct 19, 2008
Messages
1,317
Best answers
2
Reaction score
115
Location
Unknown
how to give rep to you dark?
 

HeberPcL

[PowerOT.com.br]
Joined
Aug 21, 2007
Messages
1,280
Best answers
0
Reaction score
38
Location
Brazil
darkhaos, the script works but it has to convert the password in sha1 and limite for can't change 1/1.

Thanks.
 

tigerx2

New Member
Joined
Apr 5, 2010
Messages
104
Best answers
0
Reaction score
2
darkhaos, the script works but it has to convert the password in sha1 and limite for can't change 1/1.

Thanks.
+1

And would be nice if you make guild management via npc :)
 

Dion078

New Member
Joined
Aug 27, 2010
Messages
32
Best answers
0
Reaction score
0
Alright so I added both scripts, but how to login with it cuz 1/1 doesn't work =]
 

Justin123456

New Member
Joined
Mar 24, 2011
Messages
177
Best answers
0
Reaction score
3
When I try to make another character on an account created, it gives me a long error... Like way too long for me to type and I can't copy it... : (
I'll try to type some of it ....
mysql_real_query(): instert into players (id, name, world_id, group_id, account_id, level, vocation, health, healthmax, experience, lookbody, lookfeet, lookhead, looklegs, looktype, lookaddons, maglevel, mana, manamax, manaspent, soul, town_id, posx, posy, posz, conditions, cap, sex, lastlogin, lastip, skull, skulltime, save, rank_id, guildnick, lastlogout, blessings, online) VALUES (NULL, 'Master Skilla', 0,1,0,12,1,60,60,17600,68,76,78,39,136,0,1,0,0,0,100,1,834,995,7,0,520,1,0,0,0,0,1,0'',0,0,0); - MYSQL ERROR: Cannot add or update a child row: a fpreign key contraint fails ('nubwarz'.'players', CONTRAINT 'players_ibfk_1' FOREIGN KEY ('account_id') REFERENCES 'accounts' ('id') ON DELETE CASCADE ) (1452)
Never I typed it all haha :p But something might be spelled wrong :(

I also get this after the NPC asks if i'm sure my characters wants to be a voc...
20:31 Account Manager: Your character couldn't be created, please try again.
 

GOD Fito

Member
Joined
Oct 3, 2008
Messages
97
Best answers
1
Reaction score
8
Darkhaos you can edit the script with storage? For Having to re-log to re-create an account.

I would greatly appreciate it
 
Top