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

Action Advanced Exp Scroll

Masiar

Ja być macho.
Joined
Apr 15, 2008
Messages
73
Reaction score
0
Location
Poland, Lodz
My third script:
PHP:
-- OTcentrum.pl - Polskie Centrum OpenTibii 
local config = {
funnyEffect = "YES", -- effects firework's & Animated Text  (YES/NO) 
minimumLevel = 20,
maximumLevel = 160, -- for infinite type math.huge
}
local addExp = {
[{config.minimumLevel, 40}] = 100,
[{40, 60}] = 500,
[{60, 80}] = 1000,
[{80, 100}] = 2000,
[{100, 120}] = 3000,
[{120, 140}] = 4000,
[{140, config.maximumLevel}] = 5000
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local level = getPlayerLevel(cid)
	local effect = math.random(CONST_ME_FIREWORK_YELLOW,CONST_ME_FIREWORK_BLUE) 

	if level < config.minimumLevel then
		doPlayerSendCancel(cid, "You need to be at least "..config.minimumLevel.." to use a scroll.")
		return FALSE 
	end
	
	if level >= config.maximumLevel then
		doPlayerSendCancel(cid, "Your level is too high for using a scroll.")
		return FALSE 
	end

	for k, v in pairs(addExp) do 
		if level >= k[1] and level < k[2] then 
			doPlayerAddExp(cid, v)
			doRemoveItem(item.uid, 1)
			break 
		end 
	end  

        if config.funnyEffect == "YES" then
		local pos = getPlayerPosition(cid)
		local positions = {
        		{x=pos.x+1,y=pos.y-1,z=pos.z},
        		{x=pos.x-1,y=pos.y-1,z=pos.z},
        		{x=pos.x+1,y=pos.y+1,z=pos.z},
        		{x=pos.x-1,y=pos.y+1,z=pos.z},
        		{x=pos.x+1,y=pos.y,z=pos.z},
        		{x=pos.x-1,y=pos.y,z=pos.z},
        		{x=pos.x,y=pos.y+1,z=pos.z},
        		{x=pos.x,y=pos.y-1,z=pos.z}
		}

		for i = 1, table.getn(positions) do
			doSendAnimatedText(getThingPos(cid), "Yeah! Exp!", TEXTCOLOR_RED) 
			doSendMagicEffect(positions[i],effect)
		end
	end
	return TRUE 
end
Simple Exp table, for edit

It thanks for my teacher, Keraxel
 
Last edited:
He wants me to slit my veins :D If you see any bug or it won't work leave message in this thread (because he's lma0).
 
Last edited:
Hio.

bug
Code:
if level < minimumLevel then

what is minimumLevel???? is nil :(:(:(

===== config.minimumLevel

Hello.

bug[2]
Code:
doSendAnimatedText(getThingPos(cid), Yeah! Exp!, TEXTCOLOR_RED)
String have to be in quotes ""

====== "Yeah! Exp!"

Oi.

bug[3]
Code:
{x=pos.x+1,y=pos.y-1,z=pos.z},
pos is nil.

======== ppos?

Cant find any usage of addExp = doPlayerAddExp.
Can be removed oki :mad:
 
Last edited:
What about adding Maximum level as well? Etc if you are higher level than 160 you cant use the scroll any longer, so users cant use it for topping the high scores.
 
#up: You don't need to set maximum level because you can set it in array (config.addExp): [(MaximumLevel)] = 4000. Now it's math.huge - infinite.

I've made it with infinite (math.huge), but it fail loop. Check this:
PHP:
-- OTcentrum.pl - Polskie Centrum OpenTibii 
local config = {
funnyEffect = "YES", -- effects firework's & Animated Text  (YES/NO) 
minimumLevel = 1,
addExp = {[60] = 1000, [80] = 2000, [100] = 3000, [120] = 4000, [math.huge] = 5000}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local expTable = config.addExp
	local effect = math.random(CONST_ME_FIREWORK_YELLOW,CONST_ME_FIREWORK_BLUE) 

	if getPlayerLevel(cid) < config.minimumLevel then
		doPlayerSendCancel(cid, "You need to be at least "..config.minimumLevel.." to use a scroll.")
		return FALSE 
	end 

	for k, v in pairs(expTable) do 
		if getPlayerLevel(cid) <= k then 
			doPlayerAddExp(cid, v)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "k: "..k.." // v: "..v.."")
			doRemoveItem(item.uid, 1) 
			break
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "k: "..k.." // v: "..v.."")
		end 
	end  

        if config.funnyEffect == "YES" then
		local pos = getPlayerPosition(cid)
		local positions = {
        		{x=pos.x+1,y=pos.y-1,z=pos.z},
        		{x=pos.x-1,y=pos.y-1,z=pos.z},
        		{x=pos.x+1,y=pos.y+1,z=pos.z},
        		{x=pos.x-1,y=pos.y+1,z=pos.z},
        		{x=pos.x+1,y=pos.y,z=pos.z},
        		{x=pos.x-1,y=pos.y,z=pos.z},
        		{x=pos.x,y=pos.y+1,z=pos.z},
        		{x=pos.x,y=pos.y-1,z=pos.z}
		}

		for i = 1, table.getn(positions) do
			doSendAnimatedText(getThingPos(cid), "Yeah! Exp!", TEXTCOLOR_RED) 
			doSendMagicEffect(positions[i],effect)
		end
	end
	return TRUE 
end

Now when I use scroll
Code:
15:31 You advanced from Level 17 to Level 18.
15:31 k: 120 // v: 4000
I don't know why infinite crash a loop :/

@edit: Also You can set experience for level which will never be reached (ex. 10000).
 
Last edited:
how to add max lvl to this code? like Znote said?

PHP:
local experience = {min=500000, max=750000} -- the experience that is given to the player will be between the values
local levelreq = 30 -- level to use the script
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerLevel(cid) > levelreq then
		local playerexp = math.random(experience.min, experience.max)
		doPlayerAddExp(cid, playerexp)
		doPlayerSendTextMessage(cid, 22, "Exp scroll gave you " .. playerexp .." experience!")
		doRemoveItem(item.uid, 1) -- Remove this if you want the scroll to not run out
		doSendMagicEffect(getPlayerPosition(cid), 40)
	else
		doPlayerSendCancel(cid, "Level Requirement is 30.")
	end
	return 1
end
 
#up: o_O
Code:
if getPlayerLevel(cid) > maximumLevel then 
        doPlayerSendCancel(cid, "Your level is too high for using a scroll.") 
        return FALSE  
    end
 
#up: o_O
Code:
if getPlayerLevel(cid) > maximumLevel then 
        doPlayerSendCancel(cid, "Your level is too high for using a scroll.") 
        return FALSE  
    end

t hx man ++ rep but i didnt understand it clearly
 
Code:
local config = {
	experience = { min = 500000, max = 750000 },
	minLevel = 30,
	maxLevel = 60
}
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerLevel(cid) < config.minLevel or getPlayerLevel(cid) > config.maxLevel then
		doPlayerSendCancel(cid, "Players of your level may not use this item.")
		return FALSE
	end
	
	local playerExp = math.random(config.experience.min, config.experience.max)
	doPlayerAddExp(cid, playerExp)
	doPlayerSendTextMessage(cid, 22, "Exp scroll gave you " .. playerExp .." experience!")
	doRemoveItem(item.uid, 1) -- Remove this if you want the scroll to not run out
	doSendMagicEffect(getPlayerPosition(cid), 40)
        return TRUE
end
 
Ok, I revised a code. Now it should works perfectly.

data/actions/scripts
PHP:
-- OTcentrum.pl - Polskie Centrum OpenTibii 
local config = {
funnyEffect = "YES", -- effects firework's & Animated Text  (YES/NO) 
minimumLevel = 20,
maximumLevel = 160, -- for infinite type math.huge
}
local addExp = {
[{config.minimumLevel, 40}] = 100,
[{40, 60}] = 500,
[{60, 80}] = 1000,
[{80, 100}] = 2000,
[{100, 120}] = 3000,
[{120, 140}] = 4000,
[{140, config.maximumLevel}] = 5000
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local level = getPlayerLevel(cid)
	local effect = math.random(CONST_ME_FIREWORK_YELLOW,CONST_ME_FIREWORK_BLUE) 

	if level < config.minimumLevel then
		doPlayerSendCancel(cid, "You need to be at least "..config.minimumLevel.." to use a scroll.")
		return FALSE 
	end
	
	if level >= config.maximumLevel then
		doPlayerSendCancel(cid, "Your level is too high for using a scroll.")
		return FALSE 
	end

	for k, v in pairs(addExp) do 
		if level >= k[1] and level < k[2] then 
			doPlayerAddExp(cid, v)
			doRemoveItem(item.uid, 1)
			break 
		end 
	end  

        if config.funnyEffect == "YES" then
		local pos = getPlayerPosition(cid)
		local positions = {
        		{x=pos.x+1,y=pos.y-1,z=pos.z},
        		{x=pos.x-1,y=pos.y-1,z=pos.z},
        		{x=pos.x+1,y=pos.y+1,z=pos.z},
        		{x=pos.x-1,y=pos.y+1,z=pos.z},
        		{x=pos.x+1,y=pos.y,z=pos.z},
        		{x=pos.x-1,y=pos.y,z=pos.z},
        		{x=pos.x,y=pos.y+1,z=pos.z},
        		{x=pos.x,y=pos.y-1,z=pos.z}
		}

		for i = 1, table.getn(positions) do
			doSendAnimatedText(getThingPos(cid), "Yeah! Exp!", TEXTCOLOR_RED) 
			doSendMagicEffect(positions[i],effect)
		end
	end
	return TRUE 
end

data/actions/actions.xml
Code:
<action itemid="6119" script="mine/expScroll.lua"/>

Now how to use it ;)
Code:
[{[color=red]80[/color], [color=orange]100[/color]}] = [color=green]2000[/color],
red - min level for this exp
orange - max level [...]
green - exerience
 
Ok, I revised a code. Now it should works perfectly.

data/actions/scripts
PHP:
-- OTcentrum.pl - Polskie Centrum OpenTibii 
local config = {
funnyEffect = "YES", -- effects firework's & Animated Text  (YES/NO) 
minimumLevel = 20,
maximumLevel = 160, -- for infinite type math.huge
}
local addExp = {
[{config.minimumLevel, 40}] = 100,
[{40, 60}] = 500,
[{60, 80}] = 1000,
[{80, 100}] = 2000,
[{100, 120}] = 3000,
[{120, 140}] = 4000,
[{140, config.maximumLevel}] = 5000
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local level = getPlayerLevel(cid)
	local effect = math.random(CONST_ME_FIREWORK_YELLOW,CONST_ME_FIREWORK_BLUE) 

	if level < config.minimumLevel then
		doPlayerSendCancel(cid, "You need to be at least "..config.minimumLevel.." to use a scroll.")
		return FALSE 
	end
	
	if level >= config.maximumLevel then
		doPlayerSendCancel(cid, "Your level is too high for using a scroll.")
		return FALSE 
	end

	for k, v in pairs(addExp) do 
		if level >= k[1] and level < k[2] then 
			doPlayerAddExp(cid, v)
			doRemoveItem(item.uid, 1)
			break 
		end 
	end  

        if config.funnyEffect == "YES" then
		local pos = getPlayerPosition(cid)
		local positions = {
        		{x=pos.x+1,y=pos.y-1,z=pos.z},
        		{x=pos.x-1,y=pos.y-1,z=pos.z},
        		{x=pos.x+1,y=pos.y+1,z=pos.z},
        		{x=pos.x-1,y=pos.y+1,z=pos.z},
        		{x=pos.x+1,y=pos.y,z=pos.z},
        		{x=pos.x-1,y=pos.y,z=pos.z},
        		{x=pos.x,y=pos.y+1,z=pos.z},
        		{x=pos.x,y=pos.y-1,z=pos.z}
		}

		for i = 1, table.getn(positions) do
			doSendAnimatedText(getThingPos(cid), "Yeah! Exp!", TEXTCOLOR_RED) 
			doSendMagicEffect(positions[i],effect)
		end
	end
	return TRUE 
end

data/actions/actions.xml
Code:
<action itemid="6119" script="mine/expScroll.lua"/>

Now how to use it ;)
Code:
[{[color=red]80[/color], [color=orange]100[/color]}] = [color=green]2000[/color],
red - min level for this exp
orange - max level [...]
green - exerience

Not working for me :( I can't even use it. I am using poem scroll with id 6119 Can someone help me ? Im not a scripter, but how can this script work if there is nothign said about item with id 6119?
 
Back
Top