• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Script health

Himii

Premium User
Premium User
Joined
Jan 19, 2011
Messages
1,268
Solutions
5
Reaction score
188
Location
Sweden
Can anyone help me with a script that adds you the mana/hp of 10 lvls when you use a lever?

Repp+!!
 
I could, I'm just scared that by the time I'm done, three other scripts are already posted. LOL

but ill do it.

- - - Updated - - -

Do you want it to add BOTH the hp and the mana, or just one of them?

And also do you mean that you add an amount of hp that you'd gain if you advanced 10 levels?
 
If you are using distro 0.2.15~ you will not be able to use this script since it uses the two functions marked with red.

Code:
local function giveHPAndMP(cid, hp, mp)
	[COLOR="#B22222"]setCreatureMaxHealth(cid, hp) -- give max health[/COLOR]
	doCreatureAddHealth(cid, hp)
	
	[COLOR="#B22222"]setCreatureMaxMana(cid, mp) -- give max mana[/COLOR]
	doPlayerAddMana(cid, mp)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1945 then
		local voc = getPlayerVocation(cid) 
		local hp = 0
		local mp = 0

		if voc == 1 or voc == 5 then -- sorc
			hp = 5
			mp = 30
		elseif voc == 2 or voc == 6 then -- druid
			hp = 5
			mp = 30
		elseif voc == 3 or voc == 7 then -- paladin
			hp = 10
			mp = 15
		elseif voc == 4 or voc == 8 then -- knight
			hp = 15
			mp = 5
		end

		giveHPAndMP(cid, hp*10, mp*10)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have gained " .. hp .. " maximum health and " .. mp .. " maximum mana!")

		doTransformItem(item.uid, 1946)
	elseif item.itemid == 1946 then
		doTransformItem(item.uid, 1945)
	end
	return TRUE
end
 
If you are using distro 0.2.15~ you will not be able to use this script since it uses the two functions marked with red.

Code:
local function giveHPAndMP(cid, hp, mp)
    [COLOR=#B22222]setCreatureMaxHealth(cid, hp) -- give max health[/COLOR]
    doCreatureAddHealth(cid, hp)
    
    [COLOR=#B22222]setCreatureMaxMana(cid, mp) -- give max mana[/COLOR]
    doPlayerAddMana(cid, mp)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1945 then
        local voc = getPlayerVocation(cid) 
        local hp = 0
        local mp = 0

        if voc == 1 or voc == 5 then -- sorc
            hp = 5
            mp = 30
        elseif voc == 2 or voc == 6 then -- druid
            hp = 5
            mp = 30
        elseif voc == 3 or voc == 7 then -- paladin
            hp = 10
            mp = 15
        elseif voc == 4 or voc == 8 then -- knight
            hp = 15
            mp = 5
        end

        giveHPAndMP(cid, hp*10, mp*10)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have gained " .. hp .. " maximum health and " .. mp .. " maximum mana!")

        doTransformItem(item.uid, 1946)
    elseif item.itemid == 1946 then
        doTransformItem(item.uid, 1945)
    end
    return TRUE
end

Thx!!

EDIT:

Srry but when i edited it didnt work anymore, can anyone say what i did wrong?
Code:
local function giveHPAndMP(cid, hp, mp)
    setCreatureMaxHealth(cid, hp) -- give max health
    
    setCreatureMaxMana(cid, mp) -- give max mana
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
        if getPlayerMoney(cid) > 1000 then
    if item.itemid == 1355 then
        local voc = getPlayerVocation(cid) 
        local hp = 0
        local mp = 0

        if voc == 1 then -- Guard
            hp = 35
            mp = 10
        elseif voc == 2 then -- Archer
            hp = 15
            mp = 15
        elseif voc == 3 then -- Necromancer
            hp = 10
            mp = 20
        elseif voc == 4 then -- Priest
            hp = 10
            mp = 25
        end

        giveHPAndMP(cid, hp*10, mp*10)
        doPlayerRemoveMoney(cid, 1000)
        doPlayerSendTextMessage(cid,21,"You have bought 10 lvls of hp/mana!")
    else
        doPlayerSendTextMessage(cid,21,"Sorry you dont have enough money!")
        end
    end
        return TRUE
end
 
Last edited:
It's better to add the new if-condition inside one if instead of having two if-statements, like this:

Code:
local function giveHPAndMP(cid, hp, mp)
	setCreatureMaxHealth(cid, hp) -- give max health

	setCreatureMaxMana(cid, mp) -- give max mana

	doPlayerRemoveMoney(cid, 1000)
	doPlayerSendTextMessage(cid, 21, "You have bought 10 lvls of hp/mana!")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerMoney(cid) > 1000 and item.itemid == 1355 then
		local voc = getPlayerVocation(cid) 

		if voc == 1 then -- Guard
			giveHPAndMP(cid, 35*10, 10*10)
		elseif voc == 2 then -- Archer
			giveHPAndMP(cid, 15*10, 15*10)
		elseif voc == 3 then -- Necromancer
			giveHPAndMP(cid, 10*10, 20*10)
		elseif voc == 4 then -- Priest
			giveHPAndMP(cid, 10*10, 25*10)
		end
	else
		doPlayerSendTextMessage(cid, 21, "Sorry you don't have enough money!")
	end
	return TRUE
end

Also I edited the script so that it fits you better. If it does not work you should post the error you're getting so that we can figure out what's wrong.
 
Im not getting any errors but i dont earn hp/mana eather
Shuldnt i take something else instead of
setCreatureMaxHealth/Mana?

Becouse that doesnt add it to you?

Like doCreatureAddMana?
 
Last edited:
I think that maybe the character that you're trying the script with (pulling the lever) is neither a Guard, Necromancer, Archer or Priest. If it is not (could be non-voc/promoted archer then it won't do nothing).
 
If this does not work I don't know what's wrong with the script. If I were you I would make prints to progressively see where the script is failing.

Code:
local function giveHPAndMP(cid, hp, mp)
	setCreatureMaxHealth(cid, getCreatureMaxHealth(cid) + hp) -- give max health

	setCreatureMaxMana(cid, getCreatureMaxMana(cid) + mp) -- give max mana

	doPlayerRemoveMoney(cid, 1000)
	doPlayerSendTextMessage(cid, 21, "You have bought 10 lvls of hp/mana!")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerMoney(cid) > 1000 and item.itemid == 1355 then
		local voc = getPlayerVocation(cid) 

		if voc == 1 then -- Guard
			giveHPAndMP(cid, 35*10, 10*10)
		elseif voc == 2 then -- Archer
			giveHPAndMP(cid, 15*10, 15*10)
		elseif voc == 3 then -- Necromancer
			giveHPAndMP(cid, 10*10, 20*10)
		elseif voc == 4 then -- Priest
			giveHPAndMP(cid, 10*10, 25*10)
		else
			doPlayerSendTextMessage(cid, 21, "Sorry, your vocation is not allowed to buy hp/mana!")
		end
	else
		doPlayerSendTextMessage(cid, 21, "Sorry you don't have enough money!")
	end
	return TRUE
end
 
Works perfect thanks!!, cant rep u yet thow but ill make shure to do it later
Code:
You must spread some Reputation around before giving it to trollebror again.
 
Back
Top