• 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!

Lua Ranks By Level [Rep++]

Alyhide

Banned User
Joined
Aug 21, 2010
Messages
1,945
Reaction score
55
Location
Switzerland
Hello, I am wondering if anybody can fix this script? I mean, it doesn't give ANY errors in console, it just simply, does not work.. What the script is supposed to do is once the player reaches level 100, it gives the rank 'Warlord of the Flame' to a character, along with a congratulations message and 100 crystal coins. It is also supposed to show in the player's description, after the guild, level,name,etc.​



Part 1:
LUA:
local t = {
	[100] = {id = 2160, count = 100, desc = "Warlord of the Flame"}
}
 
local storage = 7500
function onAdvance(cid, skill, oldLevel, newLevel)
	local i = t[newLevel]
	if skill == SKILL__LEVEL and newLevel == i and getCreatureStorage(cid, storage) < newLevel then
 
		local first = function()
			local reward = doCreateItemEx(i.id, i.count)
			if doPlayerAddItemEx(cid, reward, true) ~= RETURNVALUE_NOERROR then
				return false
			end
 
			doSendMagicEffect(getThingPos(cid), CONST_ME_FIREWORK_YELLOW)
			doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Congratulations, you have reached level " .. i .. "! You are now ranked " .. i.desc .. ".")
			return true
		end
 
		if first then
			doCreatureSetStorage(cid, storage, newLevel)
		end
	end
 
	return true
end

Part 2:
LUA:
local t = {
	[100] = {"Warlord of the Flame"}
}
 
local storage = 7500
function onLook(cid, thing, position, lookDistance)
	return isPlayer(thing.uid) and doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == 0 and ".\nShe" or ".\nHe") .. " is ranked " .. t[getCreatureStorage(thing.uid, storage)][1] .. ".") and true
end
 
You are missing an end in the 1st one.
Remade it tho
LUA:
local t = {
	[100] = {id = 2160, count = 100, desc = "Warlord of the Flame"}
}
 
local storage = 7500
function onAdvance(cid, skill, oldLevel, newLevel)
local i = t[newLevel]
if i then
   if skill == SKILL__LEVEL and getCreatureStorage(cid, storage) < newLevel then
      doPlayerAddItem(cid, t.id, t.count)
      doSendMagicEffect(getThingPos(cid), CONST_ME_FIREWORK_YELLOW)
      doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Congratulations, you have reached level " .. i .. "! You are now ranked " .. i.desc .. ".")
   end
end
return true
end
 
Santi, it seems to be going better than the last one, but whenever I look at myself.. it says:


The Second Code Is Ranks1.lua
Code:
[31/07/2011 17:10:24] [Error - CreatureScript Interface] 
[31/07/2011 17:10:24] data/creaturescripts/scripts/ranks1.lua:onLook
[31/07/2011 17:10:24] Description: 
[31/07/2011 17:10:24] data/creaturescripts/scripts/ranks1.lua:7: attempt to index field '?' (a nil value)
[31/07/2011 17:10:24] stack traceback:
[31/07/2011 17:10:24] 	data/creaturescripts/scripts/ranks1.lua:7: in function <data/creaturescripts/scripts/ranks1.lua:6>
 
Santi, it seems to be going better than the last one, but whenever I look at myself.. it says:


The Second Code Is Ranks1.lua
Code:
[31/07/2011 17:10:24] [Error - CreatureScript Interface] 
[31/07/2011 17:10:24] data/creaturescripts/scripts/ranks1.lua:onLook
[31/07/2011 17:10:24] Description: 
[31/07/2011 17:10:24] data/creaturescripts/scripts/ranks1.lua:7: attempt to index field '?' (a nil value)
[31/07/2011 17:10:24] stack traceback:
[31/07/2011 17:10:24] 	data/creaturescripts/scripts/ranks1.lua:7: in function <data/creaturescripts/scripts/ranks1.lua:6>

You should set storages in the first place, you want it that everytime you rank up, you get +1 storage right?

Part 1,
Below:
LUA:
doPlayerAddItem(cid, t.id, t.count)
Add:
LUA:
setPlayerStorageValue(cid,storage,getPlayerStorageValue(cid,storage) < 0 and 1 or getPlayerStorageValue(cid,storage)+1)

I can't find any errors in part 2 ;/
 
Those scripts in the first post are completely wrong. I told you I made the first one work properly but the second one is NOT possible without source additions.

Finally working script, here.
 
Last edited:
Those scripts in the first post are completely wrong. I told you I made the first one work properly but the second one is NOT possible without source additions.

First: (tested & working)
LUA:
local t = {
	["Warlord of the Flame"] = {
		config = {
			level = 100,
			prize = {2160, 100}
		}
	}
}
 
local storage = 7500
function onAdvance(cid, skill, oldLevel, newLevel)
	for desc, i in pairs(t) do
		local v = i.config
		if skill == SKILL__LEVEL and newLevel == v.level and getCreatureStorage(cid, storage) < newLevel then
			local id = doCreateItemEx(v.prize[1], v.prize[2] or 1)
			if(doPlayerAddItemEx(cid, id, true) ~= RETURNVALUE_NOERROR) then
				return false
			end
				
			doCreatureSetStorage(cid, storage, newLevel)
			doSendMagicEffect(getThingPos(cid), CONST_ME_GIFT_WRAPS)
			doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Congratulations, you have reached level " .. v.level .. "! You are now ranked " .. desc .. ".")
			break
		end
	end
	
	return true
end

Second: The function was removed a while ago - it won't work.

LUA:
local t = {
	[100] = {"Warlord of the Flame"}
}

local storage = 7500
function onLook(cid, thing, position, lookDistance)
	if isPlayer(thing.uid) then
		doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == 0 and ".\nShe" or ".\nHe") .. " is ranked " .. t[getCreatureStorage(thing.uid, storage)][1] .. ".")
	end
	
	return true
end
this should work:
LUA:
]local t = {
	[100] = {"Warlord of the Flame"}
}
function onLook(cid, thing)
	return	isPlayer(thing.uid) and doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You see ' .. getCreatureName(thing.uid) .. ' (Level: ' .. getCreatureLevel(thing.uid) .. '. ' .. (getPlayerSex(thing.uid) == 0 and 'She' or 'He') .. ' is a ' .. getPlayerVocationInfo(thing.uid).name .. '.' .. (getPlayerSex(thing.uid) == 0 and '\nShe' or '\nHe') .. ' is ranked ' .. t[getCreatureStorage(thing.uid, storage)][1] .. '.') and false or true
end
 
That's why you have not registered your script in a. xml or something where you have to go
make sure you have everything well and you do not miss a line ..
read:
PHP:
[31/07/2011 17:10:24] Description: 
[31/07/2011 17:10:24] data/creaturescripts/scripts/ranks1.lua:7: attempt to index field '?' (a nil value)
Can not find where this file.
 
I have an error for the script he gave.
I am using an Elite Knight.


Code:
[01/08/2011 14:13:26] [Error - CreatureScript Interface] 
[01/08/2011 14:13:26] data/creaturescripts/scripts/ranks1.lua:onLook
[01/08/2011 14:13:26] Description: 
[01/08/2011 14:13:26] (internalGetPlayerInfo) Player not found when requesting player info #6
 
Last edited:
LUA:
local t = {
	[100] = {"Warlord of the Flame"}
}
 
local storage = 7500
function onLook(cid, thing, position, lookDistance)
	if not isPlayer(thing.uid) then
		return true
	end

	local voc = getPlayerVocation(thing.uid)
	if t[getCreatureStorage(thing.uid, storage)] then
		if cid == thing.uid then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You see yourself. " .. (voc == 0 and "You have no vocation" or "You are " .. getVocationInfo(voc).description) .. ".\nYou are also ranked as a " .. t[getCreatureStorage(thing.uid, storage)][1] .. ".")
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You see " .. getCreatureName(thing.uid) .. " (Level: " .. getPlayerLevel(thing.uid) .. "). " .. (getPlayerSex(thing.uid) == 0 and "She" or "He") .. " " .. (voc == 0 and 'has no vocation' or 'is ' .. getVocationInfo(voc).description) .. ". " .. (getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " is also a " .. t[getCreatureStorage(thing.uid, storage)][1] .. ".")
		end
 
		return false
	end
 
	return true
end
 
LUA:
local t = {
	[100] = {"Warlord of the Flame"}
}
 
local storage = 7500
function onLook(cid, thing, position, lookDistance)
	local voc = getPlayerVocation(thing.uid)
	return isPlayer(thing.uid) and t[getCreatureStorage(thing.uid, storage)] and (cid == thing.uid and doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You see yourself. " .. (voc == 0 and "You have no vocation" or "You are " .. getVocationInfo(voc).description) .. ".\nYou are also ranked as a " .. t[getCreatureStorage(thing.uid, storage)][1] .. ".") or doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You see " .. getCreatureName(thing.uid) .. " (Level: " .. getPlayerLevel(thing.uid) .. "). " .. (getPlayerSex(thing.uid) == 0 and "She" or "He") .. " " .. (voc == 0 and 'has no vocation' or 'is ' .. getVocationInfo(voc).description) .. ". " .. (getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " is also a " .. t[getCreatureStorage(thing.uid, storage)][1] .. ".")) and false or true	
end
I'm such a one lining whore! :P
 
Lua Code:

SCRIPT HERE << lol

I'm such a one lining whore! :P

Still getting the error :(

Code:
[01/08/2011 14:27:51] [Error - CreatureScript Interface] 
[01/08/2011 14:27:51] data/creaturescripts/scripts/ranks1.lua:onLook
[01/08/2011 14:27:51] Description: 
[01/08/2011 14:27:51] (internalGetPlayerInfo) Player not found when requesting player info #6

Code:
14:32 You see yourself. You are a biochemist.
 
Tested and working on the latest subversion.

2jd5hg2.jpg


vh54l0.png


setRank.lua

LUA:
local config = {
	storage = 7500,
	mailbox = {
		{x = 95, y = 112, z = 7} -- mailbox location on map
	}
}

local ranks = {
	["Warlord of the Flame"] = {
		c = {
			level = 100,
			prize = {2160, 10}
		}
	},
}

local function doPlayerAddDepotItems(cid, pos, town, items, notify) -- credits to Chojy for idea.
	local parcel = doCreateItemEx(2595)
	local label = doAddContainerItem(parcel, 2599)
	doSetItemText(label, getCreatureName(cid) .."\n".. town)
	doAddContainerItemEx(parcel, items)
	doTeleportThing(parcel, pos)
	if(notify == true) then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your reward has been sent to your depot because you were unable to carry it.")
	end
	
	return true
end

function onAdvance(cid, skill, oldLevel, newLevel)
	for desc, i in pairs(ranks) do
		if skill == SKILL__LEVEL then
			if newLevel >= i.c.level then
				if getCreatureStorage(cid, config.storage) < newLevel then
				
					local id = doCreateItemEx(i.c.prize[1], i.c.prize[2] or 1)
					if(doPlayerAddItemEx(cid, id, false) ~= RETURNVALUE_NOERROR) then
						doPlayerAddDepotItems(cid, config.mailbox[1], getTownName(getPlayerTown(cid)), id, true)
					end
				
					doCreatureSetStorage(cid, config.storage, newLevel)
					doSendMagicEffect(getThingPos(cid), CONST_ME_GIFT_WRAPS)
					doCreatureSay(cid, "Congratulations! You are now a " .. desc .. ".", TALKTYPE_MONSTER)
					break
				end
			end
		end
	end
	
	return true
end

lookRank.lua
LUA:
local t = {
	[100] = {"Warlord of the Flame"}
}

local storage = 7500
function onLook(cid, thing, position, lookDistance)
	if isPlayer(thing.uid) then
		local voc = getPlayerVocation(thing.uid)
		if t[getCreatureStorage(thing.uid, storage)] then
			if cid == thing.uid then
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You see yourself. " .. (voc == 0 and "You have no vocation" or "You are " .. getVocationInfo(voc).description) .. ".\nYou are also ranked as " .. t[getCreatureStorage(thing.uid, storage)][1] .. ".")
			else
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You see " .. getCreatureName(thing.uid) .. " (Level: " .. getPlayerLevel(thing.uid) .. "). " .. (getPlayerSex(thing.uid) == 0 and "She" or "He") .. " " .. (voc == 0 and 'has no vocation' or 'is ' .. getVocationInfo(voc).description) .. ". " .. (getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " is also " .. t[getCreatureStorage(thing.uid, storage)][1] .. ".")
			end
		
			return false
		end
	end
	
	return true
end
 
Last edited:
Done :thumbup:

@Shin,
It's not such a good idea to make long scripts into one line, it doesn't do much of anything except allow you to make mistakes more easily. You could argue that it reacts faster but not really. :p
 
Last edited:
Back
Top