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

Yusuf El-Shora

Herizona-Ots
Joined
Jul 19, 2015
Messages
170
Reaction score
6
Location
Lala-Land
Well I can't get this functions (Silence / Paralyze) to work .. (using tfs 0.4 / 8.6 client).
I gonna start with explanation for both (Silence / Paralyze) ..

(Silence) : It's an item (You see a fire bug.) player can you on another player for specified times, and it does silence the player for like 5 second, during the 5 second he can't use atk spells but can heal and use atk weapon, player can use it every 120 second or something.

(Paralyze) : It's an item (You see a tear of daraman.) the player can use on another player by dropping the item on him and he get paralyzed like the paralyze rune, player can use this item about 10 times.

Both Silence and Paralyze have effect saying (SILENCED-PARALYZED).

This was the explanation of the functions, now let me show you the errors :

1. when Movements is loading

PgUCnuP.png


2. when i use paralyze

WD9gbn3.png


3. when i use silence

3y9bR2F.png


And here is the Scripts for the above errors:

*grenade7.lua:
Lua:
-- Set up this line in movements.xml, with itemid matching grenade
-- <movevent type="AddItem" tileitem="0" itemid="5468" event="script" value="grenade.lua"/>
function check(cid, storage)
        if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
            return false
        end

        return getPlayerStorageValue(cid, storage) >= os.time()
    end

function set (cid, storage, time)
        setPlayerStorageValue(cid, storage, os.time() + time)
    end
local grenadeConfig = {
        exhaustionType = 0,        -- Type of exhaustion: 1 (same that for spells), 0 - exhaustion only for grenades
        exhaustionTime = 1,    -- Time in seconds
        exhaustionSV = 1237,    -- Storage value for exhaustion (if exhaustionType = 0 choosen)
        grenade = {                -- Grenade basic spell options
            combatArea = {{1}},
            attackType = COMBAT_PHYSICALDAMAGE,
            attackEffect = 6,
            charges = 15, -- how many times one granade can be used
        },
        disabledPositions = {     -- List of disabled positions
            {x = 100, y = 100, z = 7},
            {x = 2064, y = 835, z = 7},
            {x = 2065, y = 835, z = 7},
            {x = 2066, y = 835, z = 7},
            {x = 2067, y = 835, z = 7},
            {x = 2068, y = 835, z = 7},
            {x = 2069, y = 835, z = 7},
            {x = 2070, y = 835, z = 7}
        },
    }


local exhaustion = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaustion, CONDITION_PARAM_SUBID, EXHAUST_COMBAT)
setConditionParam(exhaustion, CONDITION_PARAM_TICKS, grenadeConfig.exhaustionTime * 750)
setCombatCondition(combat, exhaustion)

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
local condition = createConditionObject(CONDITION_PARALYZE)
setConditionParam(condition, CONDITION_PARAM_TICKS, 750)
setConditionFormula(condition, -1, 40, -1, 40)
setCombatCondition(combat, condition)
local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
local exhaustion = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaustion, CONDITION_PARAM_SUBID, 1)
setConditionParam(exhaustion, CONDITION_PARAM_TICKS, 750)
setCombatCondition(combat2, exhaustion)
local exhaustion = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaustion, CONDITION_PARAM_SUBID, 2)
setConditionParam(exhaustion, CONDITION_PARAM_TICKS, 750)
setCombatCondition(combat2, exhaustion)

function returnPlayerItem(cid, item)
    local useCount = getItemAttribute(item.uid, "grenade")
    doRemoveItem(item.uid)
    local newItem = doPlayerAddItem(cid, item.itemid)  
    doItemSetAttribute(newItem, "grenade", useCount)
    doItemSetAttribute(newItem, "description", "You have " .. (grenadeConfig.grenade.charges - useCount) .. " charges left.")
end

local function sendEffect(cid)
  if not isPlayer(cid) then return end
  doSendMagicEffect(getThingPos(cid), 34)
  doSendAnimatedText(getThingPos(cid), 'Protected', COLOR_GREY)
end

local function unregister(cid)
  if not isPlayer(cid) then return end
  unregisterCreatureEvent(cid, 'ImmunitySpell')
end

function onAddItem(moveItem, tileItem, position, cid)

    local voc = getPlayerVocation(cid)
    if voc == 3 or voc == 7 or voc == 9 then
            returnPlayerItem(cid, moveItem)
        return false
    end
 
    if getTilePzInfo(position) == true or getTilePzInfo(getThingPosition(cid)) then
        returnPlayerItem(cid, moveItem)
        return false
    end
 
    local useCount = getItemAttribute(moveItem.uid, "grenade")
    if useCount == nil or useCount < 0 then
        useCount = 0
    end
  
    if grenadeConfig.exhaustionType == 0 then
        local exhaust = getPlayerStorageValue(cid, grenadeConfig.exhaustionSV)
        if  exhaust >= os.time() then
            returnPlayerItem(cid, moveItem)
            return false
        end
    elseif grenadeConfig.exhaustionType == 1 then
        if getCreatureCondition(cid, CONDITION_EXHAUST, EXHAUST_COMBAT) == true then
            returnPlayerItem(cid, moveItem)
            return false
        end
    else
        returnPlayerItem(cid, moveItem)
        return false
    end
 
    if #grenadeConfig.disabledPositions > 0 then
        for _, disabled in pairs(grenadeConfig.disabledPositions) do
            if disabled.x == position.x and disabled.y == position.y and disabled.z == position.z then
                returnPlayerItem(cid, moveItem)
                return false
            end
        end
    end
 
    local var = {pos = position, type = 2}
    local pos = variantToPosition(var)
    local pid = getTopCreature(pos).uid
    local speed = getCreatureSpeed(pid)
    if isPlayer(pid) then
        if not isPaladin(pid) then
            doCombat(cid, combat2, pos)
        end
        doSendAnimatedText(pos, "PARALYZED", TEXTCOLOR_PURPLE)
        doChangeSpeed(pid, -speed + 150)
        doSendMagicEffect(pos, CONST_ME_MAGIC_RED)
        addEvent(function()
            if isPlayer(pid) then
                doChangeSpeed(pid, speed)
            end
        end, isKnight(pid) and 750 or 1000)
    end
 
    if not isPlayer(pid) then
        doPlayerSetStorageValue(cid,7925,getPlayerStorageValue(cid,7925) + 1)
        doPlayerSetStorageValue(cid,7927,0)
    else
        if check(cid, 9024) then
            for i = 7923,7924 do
                doPlayerSetStorageValue(cid,i,getPlayerStorageValue(cid,i) + 1)
            end
            doPlayerSetStorageValue(cid,7927,getPlayerStorageValue(cid,7927) + 1)
        else
            set(cid, 9024,7*24*60*60)
            for i = 7923,7925 do
                doPlayerSetStorageValue(cid,i,0)
            end
        end
    end
 
    if getPlayerStorageValue(cid ,7924) > getPlayerStorageValue(cid,7926) then
        doPlayerSetStorageValue(cid,7926,getPlayerStorageValue(cid,7924))
    else
        doPlayerSetStorageValue(cid,7926,getPlayerStorageValue(cid,7926))
    end
 
          

 
    if (useCount + 1) >= grenadeConfig.grenade.charges then
        doRemoveItem(moveItem.uid)
    else
        doItemSetAttribute(moveItem.uid, "grenade", (useCount + 1))
        doItemSetAttribute(moveItem.uid, "description", "You have " .. (grenadeConfig.grenade.charges - useCount - 1) .. " charges left.")
        returnPlayerItem(cid, moveItem)
    end
 
    if grenadeConfig.exhaustionType == 0 then
        setPlayerStorageValue(cid, grenadeConfig.exhaustionSV, (os.time() + grenadeConfig.exhaustionTime))
    else
        doAddCondition(cid, exhaustion)
    end

    return true
end
*silence.lua:
Lua:
local config = {
    cooldown = { storage = 3994, duration = 40 },
    duration = 6,
    ignoreCooldownGroup = 3,
    uses = 10
}

local function sendEffect(cid)
  if not isPlayer(cid) then return end
  doSendMagicEffect(getThingPos(cid), 66)
  doSendAnimatedText(getThingPos(cid), 'Silenced', COLOR_RED)
end

local function unregister(cid)
  if not isPlayer(cid) then return end
  doPlayerSetSilenced(cid, false)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local target = itemEx.uid
    if not isPlayer(target) or target == cid then
      doPlayerSendCancel(cid, "You can only use this ability on other players.")
      return true
    end

    local uses = getItemAttribute(item.uid, 'uses')
    if not uses then
      doItemSetAttribute(item.uid, 'uses', config.uses)
      uses = config.uses
    end
 
    uses = uses - 1

    if getCreatureStorage(cid, config.cooldown.storage) > os.time() and getPlayerGroupId(cid) < config.ignoreCooldownGroup then
      doPlayerTextMessage(cid,27, string.format('You can only use this ability each %d seconds.', config.cooldown.duration))
      doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
      return true
    end
  
    doCreatureSetStorage(cid, config.cooldown.storage, os.time() + config.cooldown.duration)
    doPlayerSetSilenced(target, true)
    for i = 0, config.duration - 1 do
      addEvent(sendEffect, i * 1000, target)
    end
    addEvent(unregister, config.duration * 1000, target)
 
    doItemSetAttribute(item.uid, 'uses', uses)
 
    if uses <= 0 then
      doRemoveItem(item.uid)
      doPlayerSendTextMessage(cid,27, 'You used the last charge, your item is gone.')
    else
      doPlayerSendTextMessage(cid,27, string.format('You used a charge, you have %d charges left.', uses))
    end
    return true
end

I have a Protection item (immunity.lua) also which protect the player for 10sec against atk spells, you may notice it in the grenade7.lua but it's working fine.

Also for further information I have this in action.xml which may be related to the problem:
XML:
    <!-- Trinkets silence is the one you will fix throw on ground for no need to fix because you will fix it like paralyze immunity need fix -->
    <action itemid="5468" event="script" value="silence.lua"/>
    <action itemid="5809" event="script" value="immunity.lua"/>
As you notice in actions instructions saying I need to fix para and silence, but I really have no idea how to fix any of them.

Someone told me it's a source error, some other told me it's a script error.
I really don't know what is the problem, and hoping someone can help me if it was a source error or a script error.

& Thanks in advance.
 
Last edited:
i don't know how to do it but gonna search now

You can give this a try;
Lua:
local mute = createConditionObject(CONDITION_MUTED)
setConditionParam(mute, CONDITION_PARAM_TICKS, -1)

function doPlayerSetSilenced(cid, bool)
    if not isPlayer(cid) then
        return false
    end

    if bool then
        doAddCondition(cid, mute)
    else
        doRemoveCondition(cid, CONDITION_MUTED)
    end

    return true
end
 
You can give this a try;
Lua:
local mute = createConditionObject(CONDITION_MUTED)
setConditionParam(mute, CONDITION_PARAM_TICKS, -1)

function doPlayerSetSilenced(cid, bool)
    if not isPlayer(cid) then
        return false
    end

    if bool then
        doAddCondition(cid, mute)
    else
        doRemoveCondition(cid, CONDITION_MUTED)
    end

    return true
end

Now there is no .exe error saying doPlayerSetSilenced, and player get the effect saying Silenced...
but sill can do a ue
 
in luascripts.cpp add this
C++:
int32_t LuaInterface::luaDoPlayerSetSilenced(lua_State* L)
{
    //doPlayerSetSilenced(cid, state)
    bool state = popNumber(L);

    ScriptEnviroment* env = getEnv();
    if(Player* player = env->getPlayerByUID(popNumber(L)))
    {
        if(player->isSilenced() != state)
            player->setSilenced(state);

        lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}

and this
C++:
    //doPlayerSetSilenced(cid, state)
    lua_register(m_luaState, "doPlayerSetSilenced", LuaInterface::luaDoPlayerSetSilenced);

in luascript.h add this
C++:
        static int32_t luaDoPlayerSetSilenced(lua_State* L);

in player.cpp above lastAttackBlockType = BLOCK_NONE; add this
C++:
silenced = false;

in player.h add

C++:
        bool isSilenced() { return silenced; }
        void setSilenced(bool state) { silenced = state; }

in player.h too above bool talkState[13]; add this
C++:
bool silenced;


spells.cpp in fuction onPlayerSay after this line return RET_NOTPOSSIBLE; add this
C++:
    if(player->isSilenced() && instantSpell->getIsAggressive())
    {
        player->sendCancel("You are silenced.");
        g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
        return RET_NOERROR;
    }

goodluck :D
 
Last edited by a moderator:
in luascripts.cpp add this
Code:
int32_t LuaInterface::luaDoPlayerSetSilenced(lua_State* L)
{
    //doPlayerSetSilenced(cid, state)
    bool state = popNumber(L);

    ScriptEnviroment* env = getEnv();
    if(Player* player = env->getPlayerByUID(popNumber(L)))
    {
        if(player->isSilenced() != state)
            player->setSilenced(state);

        lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}

and this
Code:
    //doPlayerSetSilenced(cid, state)
    lua_register(m_luaState, "doPlayerSetSilenced", LuaInterface::luaDoPlayerSetSilenced);

in luascript.h add this
Code:
        static int32_t luaDoPlayerSetSilenced(lua_State* L);

in player.cpp above lastAttackBlockType = BLOCK_NONE; add this
Code:
silenced = false;

in player.h add

Code:
        bool isSilenced() { return silenced; }
        void setSilenced(bool state) { silenced = state; }

in player.h too above bool talkState[13]; add this
Code:
bool silenced;


spells.cpp in fuction onPlayerSay after this line return RET_NOTPOSSIBLE; add this
Code:
    if(player->isSilenced() && instantSpell->getIsAggressive())
    {
        player->sendCancel("You are silenced.");
        g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
        return RET_NOERROR;
    }

goodluck :D
Thanks very much!
how you knew all that :O
 
I change all sources , i will se if wokrs silence ok?

Use the vps here are the files in the source you can edit if you want
 
Last edited by a moderator:
Back
Top