• 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 Rename NPC

Summ

(\/)(;,,;)(\/) Y not?
Staff member
Global Moderator
Joined
Oct 15, 2008
Messages
4,152
Solutions
12
Reaction score
1,107
Location
Germany :O
Golden_Newspaper.gif
Rename NPC Players can buy new names

Description:
The NPC will ask the player for a new name, the player then has to pay a certain amount of money and his name is changed.

Request:
NPC rename npc

Scripts:
Npc/Renamer.xml:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Renamer" script="renamer.lua" walkinterval="0" floorchange="0">
	<health now="150" max="150"/>
	<look type="129" head="114" body="119" legs="114" feet="114" corpse="2212"/>
    <parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|. Do you want a new {name}."/>
    </parameters>
</npc>

Npc/scripts/renamer.lua:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talk = {}
local name = {}

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
function onPlayerEndTrade(cid)				npcHandler:onPlayerEndTrade(cid)			end
function onPlayerCloseChannel(cid)			npcHandler:onPlayerCloseChannel(cid)		end

function creatureGreetCallback(cid)
	talk[cid] = 0
	name[cid] = ''
	return true
end

local chars = {' ', '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', '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'}

RET_VALID = 1
RET_EXISTS = 2
RET_INVALID = 3

local function validName(name)
	if getPlayerGUIDByName(name) ~= nil then
		return RET_EXISTS
	end
 
	local notAllowed = {"god", "gm", "cm"}
	for _, naw in pairs(notAllowed) do
		if (name:lower():find(naw .. " ") or name:lower() == naw or name:lower():find("admin")) then
			return RET_INVALID
		end
	end
 
	for i = 1, name:len() do
		if not(isInArray(chars, name:sub(i,i))) then
			return RET_INVALID
		end
	end
	return RET_VALID
end

local function getValid(name, opt)
	local function tchelper(first, rest)
	  return first:upper()..rest:lower()
	end

	return opt and name:gsub("(%a)([%w_']*)", tchelper) or name:gsub("^%l", string.upper)
end

local config = {
	type = 'money',  -- or 'item'
	money = 10000,  -- = 1cc
	item = {2159, 20},  -- itemid, itemcount
	everyFirstLetterCapital = true
}

function messageDefaultCallback(cid, type, msg)
	if not(npcHandler:isFocused(cid)) then
		return false
	end
	
	if msgcontains(msg, "name") and talk[cid] == 0 then
		selfSay("What should be your new name?", cid)
		talk[cid] = 1
	elseif talk[cid] == 1 then
		local v = getValid(msg:lower(), config.everyFirstLetterCapital)
		local ret = validName(v)
		if ret == RET_VALID then
			selfSay("So you want '" .. v .. "' to be your new name for " .. (config.type == "money" and (config.money .. " gold") or (config.item[2] .. ' ' .. (config.item[2] > 1 and getItemPluralNameById(config.item[1]) or getItemNameById(config.item[1])))) .. "?", cid)
			talk[cid], name[cid] = 2, v
		else
			if ret == RET_INVALID then
				selfSay(msg .. " is not a valid name. What should be your new name?", cid)
			elseif ret == RET_EXISTS then
				selfSay(msg .. " already exists. What should be your new name?", cid)
			end
		end
	elseif talk[cid] == 2 then
		if msgcontains(msg, "yes") then
			if (config.type == 'money' and doPlayerRemoveMoney(cid, config.money)) or (config.type ~= 'money' and doPlayerRemoveItem(cid, config.item[1], config.item[2])) then
				local curName = getPlayerName(cid)
				doRemoveCreature(cid)
				db.query("UPDATE players SET name = '"..name[cid].."' WHERE name = '"..curName.."';")
			else
				selfSay("You don't have " .. (config.type == "money" and (config.money .. " gold") or (config.item[2] .. ' ' .. (config.item[2] > 1 and getItemPluralNameById(config.item[1]) or getItemNameById(config.item[1])))) .. "!", cid)
				talk[cid] = 0
			end
		else
			selfSay("Maybe later.", cid)
			talk[cid] = 0
		end
	end
	
	
	return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, "Bye.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "How rude!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, messageDefaultCallback)  
npcHandler:setCallback(CALLBACK_FAREWELL, creatureFarewell)
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureFarewell)
npcHandler:setCallback(CALLBACK_GREET, creatureGreetCallback)
npcHandler:addModule(FocusModule:new())

Config:
> type = 'money' or 'item'
> Whether the player has to pay with cash or a certain amout of items

> price = 10000,
> The money the player has to pay. (if type = 'money')

> item = {itemid, count},
> The item the player need to rename himself + count. (if type = 'item')

> everyFirstLetterCapital = true
Example name: "summ summ"
> If set to "true" the name will be "Summ Summ", if set too false the name will be "Summ summ" (Difference in capital letters)

> local chars = {' ', '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', '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'}
> Which letters are allowed for new names.

Change Log:
-Fixed bug when name already exists.
-Added method to pay the npc with items.
-Fixed players being able to use Staff identification
 
Last edited:
[08/03/2012 23:52:56] [Error - Npc interface]
[08/03/2012 23:52:57] data/npc/scripts/renamer.lua:eek:nCreatureSay
[08/03/2012 23:52:57] Description:
[08/03/2012 23:52:57] data/npc/scripts/renamer.lua:66: attempt to call field 'query' (a nil value)
[08/03/2012 23:52:57] stack traceback:
[08/03/2012 23:52:57] data/npc/scripts/renamer.lua:66: in function 'callback'
[08/03/2012 23:52:57] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[08/03/2012 23:52:57] data/npc/scripts/renamer.lua:9: in function <data/npc/scripts/renamer.lua:9>



no rename and got this problem help plz
 
Try replacing db.query with db.executeQuery
 
ty alot working now

but got this problem

[09/03/2012 15:27:49] sqlite3_step(): SQLITE ERROR: columns name, deleted are not unique

when i try chance name to name already exist


and how i can chance price from 10000 crystal coins to 20 scarab coins ItemID: [2159].
 
Last edited:
I updated the rename.lua.
Duplicate name bug is fixed and to use scarab coins use this config:

Lua:
local config = {
	type = 'item',
	money = 10000, 
	item = {2159, 20},
	everyFirstLetterCapital = true
}

Rep+ :D
 
This looks wonderful (easy to exploit most Gesior name changers)!
A few questions:

- Does it work for 0.4?
- Is it possible to make a small blacklist of letter combinations that aren't allowed? (GM, CM, God, etc.)
- Will it support premium_points as a payment in the future?

Red
 
This looks wonderful (easy to exploit most Gesior name changers)!
A few questions:

- Does it work for 0.4?
- Is it possible to make a small blacklist of letter combinations that aren't allowed? (GM, CM, God, etc.)
- Will it support premium_points as a payment in the future?

Red

Same questions.. also this brings rpg feeling to the server.. great scripts!
I'll rep when you add the points that red asked for :D
 
:p I think it would be great for any server. Just need to learn how to make it so they can't get Staff char names :p

-bump
 
Back
Top