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

setMaster(player) , does not work TFS 1.2

lazarocp

Kryx
Joined
May 3, 2014
Messages
20
Solutions
1
Reaction score
0
function onUse(cid, item, fromPosition, target, toPosition)
local storageplayer = getPlayerStorageValue(cid, 41111)
local criatura = "Demon"

if storageplayer == 1 then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Noo.")

else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Demon!")
Game.createMonster(criatura, getCreaturePosition(cid))
criatura:setMaster(player)
position:sendMagicEffect(CONST_ME_MAGIC_RED)
return true

end
end
 
Solution
Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if player:getStorageValue(41111) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    else
        local monster = Game.createMonster("Demon", player:getPosition())
        monster:setMaster(player)
        monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)

        player:sendTextMessage(MESSAGE_INFO_DESCR, "Demon!")
        player:setStorageValue(41111, 1)
    end
return true
end
function onUse(cid, item, fromPosition, target, toPosition)
local storageplayer = getPlayerStorageValue(cid, 41111)
local criatura = "Demon"

if storageplayer == 1 then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Noo.")

else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Demon!")
Game.createMonster(criatura, getCreaturePosition(cid))
criatura:setMaster(player)
position:sendMagicEffect(CONST_ME_MAGIC_RED)
return true

end
end
setMaster only works on convinceable creatures in TFS 1.2 (this was changed in TFS 1.3), you would have to edit the sources to get it working.
 
Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if player:getStorageValue(41111) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    else
        local monster = Game.createMonster("Demon", player:getPosition())
        monster:setMaster(player)
        monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)

        player:sendTextMessage(MESSAGE_INFO_DESCR, "Demon!")
        player:setStorageValue(41111, 1)
    end
return true
end
 
Last edited:
Solution
Code:
function onUse(player, item, fromPosition, target, toPosition)
local criatura = "Demon"

    if player:getStorageValue(41111) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Demon!")
        local monster = Game.createMonster(criatura, player:getPosition())
        monster:setMaster(player)
        monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        player:setStorageValue(41111, 1)
    end
  
return true
end

Correct, the problem was that you can't use a string when calling a Creature function, you need a creature userdata value.
But please try to tab the scripts abit better, also since it's just one monster there is no need to really keep the "criatura" variable.

Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if player:getStorageValue(41111) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    else
        local monster = Game.createMonster("Demon", player:getPosition())
        monster:setMaster(player)
        monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)

        player:sendTextMessage(MESSAGE_INFO_DESCR, "Demon!")
        player:setStorageValue(41111, 1)
    end
    return true
end
 
Correct, the problem was that you can't use a string when calling a Creature function, you need a creature userdata value.
But please try to tab the scripts abit better, also since it's just one monster there is no need to really keep the "criatura" variable.

Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if player:getStorageValue(41111) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    else
        local monster = Game.createMonster("Demon", player:getPosition())
        monster:setMaster(player)
        monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)

        player:sendTextMessage(MESSAGE_INFO_DESCR, "Demon!")
        player:setStorageValue(41111, 1)
    end
    return true
end

I win
 
Correct, the problem was that you can't use a string when calling a Creature function, you need a creature userdata value.
But please try to tab the scripts abit better, also since it's just one monster there is no need to really keep the "criatura" variable.

Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if player:getStorageValue(41111) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    else
        local monster = Game.createMonster("Demon", player:getPosition())
        monster:setMaster(player)
        monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)

        player:sendTextMessage(MESSAGE_INFO_DESCR, "Demon!")
        player:setStorageValue(41111, 1)
    end
    return true
end
Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if player:getStorageValue(41111) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    else
        local monster = Game.createMonster("Demon", player:getPosition())
        if monster then -- check if monster was created
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Demon!")
            player:setStorageValue(41111, 1)
        end
    end
    return true
end
 
Thank you @Itutorial and others for help ! I'm still learning, could I when the item was used again did it remove the summon?
Lua:
local storage = 41111
local monsterName = "Demon"

function onUse(player, item, fromPosition, target, toPosition)
    if player:getStorageValue(storage) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
        if player:removeSummon(monsterName) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have removed "..monsterName..".")
            player:setStorageValue(storage, 0)
        end
    else
        local monster = Game.createMonster(monsterName, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
            player:sendTextMessage(MESSAGE_INFO_DESCR, monsterName.."!")
            player:setStorageValue(storage, 1)
        end
    end
    return true
end
 
This error , Storage is not required


Lua Script Error: [Action Interface]
data/actions/scripts/tools/rgoback.lua:eek:nUse
data/actions/scripts/tools/rgoback.lua:7: attempt to call method 'removeSummon' (a nil value)
stack traceback:
[C]: in function 'removeSummon'
data/actions/scripts/tools/rgoback.lua:7: in function <data/actions/scripts/tools/rgoback.lua:3>
 
This error , Storage is not required


Lua Script Error: [Action Interface]
data/actions/scripts/tools/rgoback.lua:eek:nUse
data/actions/scripts/tools/rgoback.lua:7: attempt to call method 'removeSummon' (a nil value)
stack traceback:
[C]: in function 'removeSummon'
data/actions/scripts/tools/rgoback.lua:7: in function <data/actions/scripts/tools/rgoback.lua:3>
The removeSummon function is from 1.3
forgottenserver/creature.lua at 5ba1ef3926695237a8da3d969bd99e779a0ae7f1 · otland/forgottenserver · GitHub
Possibly updating your creature.lua will alleviate the issue?
 
Back
Top