• 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 Need help with manarune script

haxborn

server dominando, cry is free
Joined
Dec 1, 2011
Messages
126
Reaction score
7
Location
Sweden
Hi there, I'm putting up a server and got a small problem, since I'm not a good scripter I just want a small help.

I'm using a mana rune since my server is 8.50 and using tfs 0.2.2

It works perfectly, though the mana rune disapears when used, I want it to stay.

Could you help me out?

Here's the script:

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)

function onCastSpell(cid, var)

local level = getPlayerLevel(cid)
local mlevel = getPlayerMagLevel(cid)
local pos = getPlayerPosition(cid)

-- Mana Formula Settings --
-- You can use "level" and "mlevel" --
local mana_minimum = (level * 3) + (mlevel * 3) - 50
local mana_maximum = (level * 4) + (mlevel * 3)
-- Mana Formula Settings END --
local mana_add = math.random(mana_minimum, mana_maximum)
doSendMagicEffect(pos,28)
doPlayerAddMana(cid, mana_add)
doSendAnimatedText(pos, mana_add, TEXTCOLOR_LIGHTBLUE)
doCreatureSay(cid, "_+_MaNa PoWeR_+_", TALKTYPE_ORANGE_1)
return doCombat(cid, combat, var)
end

btw looking for scripter if someone is intrested, will make a deal then.
 
Last edited:
Yea I know but I find it hard to update to a newer distro and get it working fine, always finds bugs in map, scripts etc and nothing works, I'm not that good anymore. I was hosting when 0.2 was the good part and my rl friends like it oldschool so we would like to continue using old clients etc, but if someone can help me update it would be great!
 
PHP:
[05/12/2011 16:45:13] data/actions/scripts/other/manarune.lua:18: attempt to index global 'exhaustion' (a nil value)
[05/12/2011 16:45:13] stack traceback:
[05/12/2011 16:45:13] 	data/actions/scripts/other/manarune.lua:18: in function <data/actions/scripts/other/manarune.lua:1>

I guess its my server that doesn't work. well thanks anyways!
 
Here's the new script,

Lua:
----------------------------------- 
--Created to make the script easy to manipulate 
--If used without using server potion exhaust (EX: potExhaust = false), it will work regardless of server 
--Remember, true = yes, false = no, in the config 

function onUse(cid, item, frompos, item2, topos) 
    --Config 
local level = getPlayerLevel(cid)
local mlevel = getPlayerMagLevel(cid)
local pos = getPlayerPosition(cid)
    local reqml = 3         --Magic Level required to use it 
    local reqlvl = 15       --Character Level required to use it 
    local potExhaust = false    -- causes exhaust like potions (false creates seperate exhaust for mana rune) 
    local mana_minimum = (level * 1) + (mlevel * 2) - 50
    local mana_maximum = (level * 1) + (mlevel * 2)
    local mana_add = math.random(mana_minimum, mana_maximum)
    local ani = 1           --Animation to be sent to player when used (these can be found in your global.lua; search for CONST_ME_) 
    --If you're not using potion exhaust (potExhaust = false) edit the following the way you'd like 
    local storeValue = 50       --The storage value that will be used for exhaust if you have potexhaust to false 
    local exhaustTime = 1       --Exhaust in seconds 
    local infinite = true      --Will it cause rune to lose charges 
    local canUseInPz = true    --If true, mana rune may be used in PZ, otherwise, it will not work. 

    local player_say = "Ahhh..."                            --What player says after successfully using the mana rune 
    local error_ml = "You don't have the required magic level to use that rune."    --What the cancel says when ml is too low 
    local error_lvl = "You don't have the required magic level to use that rune."   --What the cancel says when level is too low 
    local error_notPlayer = "You can only use this rune on players."        --What the cancel says when you try to use it on something not a player 
    local error_exhaust = "You are exhausted."                  --What the cancel says when you are exhausted 
    local error_pz = "You may not use this in Protected Zones." --What the cancel says when you are in PZ and canUseInPz is false 
    ------------------------------------------- DO NOT EDIT BELOW THIS LINE!! ------------------------------------------- 

    ---------------------------START Check for Errors-------------------------------- 
    --If doesn't allow use in PZ, send poof and cancel message 
    if canUseInPz == false  and getTilePzInfo(getPlayerPosition(cid)) == 1 then 
        doSendMagicEffect(frompos, CONST_ME_POFF) 
        doPlayerSendCancel(cid, error_pz) 
        return 0 
    end 
    --If not high enough level, send poof and cancel message 
    if getPlayerLevel(cid) < reqlvl then 
        doSendMagicEffect(frompos, CONST_ME_POFF) 
        doPlayerSendCancel(cid, error_lvl) 
        return 0 
    end 

    --If ml is too low, send poof and cancel message 
    if getPlayerMagLevel(cid) < reqml then 
        doSendMagicEffect(frompos, CONST_ME_POFF) 
        doPlayerSendCancel(cid, error_ml) 
        return 0 
    end 

    --If it's not a player, send poof and cancel message 
    if item2.uid < 1 then 
        doSendMagicEffect(frompos, CONST_ME_POFF) 
        doPlayerSendCancel(cid, error_notPlayer) 
        return 0 
    end 

    --Check if exhausted 
    if potExhaust == false then --If not using Potion Exhaust 
        if exhaust(cid, storeValue, exhaustTime) == 0 then 
            doSendMagicEffect(frompos, CONST_ME_POFF) 
            doPlayerSendCancel(cid, error_exhaust) 
            return 0 
        end 
    else --If you are using potion exhaust 
        if hasCondition(cid, CONDITION_EXHAUSTED) == 1 then 
            doPlayerSendCancel(cid, error_exhaust) 
            return 0 
        end 
    end 

    ---------------------------END Check for Errors-------------------------------- 

    doSendMagicEffect(topos, ani) 
    doPlayerAddMana(item2.uid, mana_add) 
    if infinite == false then 
        if item.type > 1 then 
            doChangeTypeItem(item.uid,item.type-1) 
        else 
            doRemoveItem(item.uid,1) 
        end 
    end 
end 

--Exhaust System created by Alreth 
--Edited by OsoSangre 
function exhaust(cid, storeValue, exhaustTime) 
    local newExhaust = os.time() 
    local oldExhaust = getPlayerStorageValue(cid, storeValue) 
    if (oldExhaust == nil or oldExhaust < 0) then 
        oldExhaust = 0 
    end 
    if (exhaustTime == nil or exhaustTime < 0) then 
        exhaustTime = 1 
    end 
    diffTime = os.difftime(newExhaust, oldExhaust) 
    if (diffTime >= exhaustTime) then 
        setPlayerStorageValue(cid, storeValue, newExhaust) 
        return 1 
    else 
        return 0 
    end 
end

It works with exhaust etc, but it doesn't give mana, it says:

[05/12/2011 17:09:03] luaDoPlayerAddMana(). Player not found

So can someone fix the:
doPlayerAddMana(item2.uid, mana_add)

so it finds the player? I've tried cid, var, combat etc all thoose. I don't know how it works at all.. :(
 
I'm most certain that doPlayerAddMana is used like:
Code:
[COLOR=#000000][B]doPlayerAddMana[/B][/COLOR][COLOR=#808080]([/COLOR][COLOR=#0000FF]id[/COLOR][COLOR=#808080], [/COLOR][COLOR=#0000FF]amount[/COLOR][COLOR=#808080])[/COLOR]

In your case it should be doPlayerAddMana(cid, mana_add) or doCreatureAddMana(cid, mana_add).
 
Back
Top