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

TFS 0.X Add a storage to another player by params

Zazeros

Member
Joined
Feb 13, 2012
Messages
67
Reaction score
17
0.4

Hi guys, I'm having a little trouble trying to do this.

This spell add a storage to a player, and after 15 seconds, the storage backs to -1. I'm trying to use spells params=1 in spells.xml, just like exura sio and such, but it does not seem to work.

Lua:
function onCastSpell(cid, var)
    local storage = 121345
    local storage2 = 300

    if getCreatureStorage(cid, storage) > 0 then
        doPlayerSendCancel(cid, "Already have the storage")
        return false
    end

    doCreatureSetStorage(cid, storage, storage2)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Storage add")

    addEvent(function()
        if isCreature(cid) then
            doCreatureSetStorage(cid, storage, nil)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Storage over")
        end
    end, 15000)

    return true
end
 
Make sure to reset this storage when the player logs in, otherwise if they die they'll keep the storage forever.

and you can't set a storage to nil.. actually set it to -1.

Lua:
local storage = 121345
local storageValue = 300

local function changeCreatureStorage(cid, storage, value)
    if not isCreature(cid) then
        return false
    end
    doCreatureSetStorage(cid, storage, value)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "creature storage reset.")
    return true
end

function onCastSpell(cid, var)
    if getCreatureStorage(cid, storage) > 0 then
        doPlayerSendCancel(cid, "Already have the storage")
        return false
    end

    doCreatureSetStorage(cid, storage, storageValue)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Storage add")

    addEvent(changeCreatureStorage, 15000, cid, storage, -1)
    return true
end
 
@Roddet Hey, it actually worked. Thank you, and thank @Xikini too
I'm sorry, but can you explain why it worked?
Sorry, I have limited knowledge of the spell system.

As far as I know, VARIANT_NUMBER is related to creatures.
So internally it probably works like.. Creature(creatureId) but like Creature(var.number) ?

I'm mostly guessing tho, I've only seen it used a handful of times.

Maybe Roddet can explain better.
 
Maybe Roddet can explain better.
Definely not xD I suck at explaining but I'll try

I'm sorry, but can you explain why it worked?

There are 4 types of variants
C++:
VARIANT_NUMBER // var.number
VARIANT_POSITION // var.pos
VARIANT_TARGETPOSITION // var.pos (scripted weapons)
VARIANT_STRING // var.text

the variant or var parameter consists on the following data structure:
Lua:
var = {
    type = VARIANT_TYPE,

    -- # returned key depends on VARIANT_TYPE
    pos = position,
    number = target,
    text = param
}

Variants are based on two things: XML Parameters and spell behaviour

For example, the exori vis spell which uses casterTargetOrDirection="1"
  • If target is found, it will return var.number (targetId)
  • If target is not found, it will return var.pos

Now lets take your spell as example, it uses needtarget="1" and params="1" (exura sio alike)
  • It will always return var.number (targetId) because it needs a target to work
  • However if your remove needtarget="1" it will return var.text instead (which contains the param)

Another example with runes thats requires a target needtarget="1"
  • If the rune is used on the floor (manually nor hotkey), it will return var.pos
  • If the rune is used on a target, it will return var.number (targetId)

Self target spells (selftarget="1") returns var.number (casterId)
Area spells returns var.number (casterId) aswell


There is more to cover but now you have a pretty good idea about how variants works
 
Back
Top