setMaster(player) , does not work TFS 1.2

Discussion in 'Support' started by lazarocp, Mar 20, 2017.

Tags:
  1. lazarocp

    lazarocp Kryx

    Joined:
    May 3, 2014
    Messages:
    9
    Likes Received:
    0
    Best Answers:
    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
     
  2. Best Answer:
    Post #6 by Itutorial, Mar 20, 2017
  3. Mkalo

    Mkalo ボーカロイド Support Team

    Joined:
    Jun 1, 2011
    Messages:
    1,087
    Likes Received:
    821
    Best Answers:
    46
    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.
     
  4. lazarocp

    lazarocp Kryx

    Joined:
    May 3, 2014
    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    In the case of creatures with <flag convinceable = "1" />?

    The demon is with <flag convinceable = "1" />
     
  5. Mkalo

    Mkalo ボーカロイド Support Team

    Joined:
    Jun 1, 2011
    Messages:
    1,087
    Likes Received:
    821
    Best Answers:
    46
    Code (Lua):
    1.  criatura:setMaster(player)
    There is no "player" in your code it should be:

    Code (Text):
    1.  criatura:setMaster(cid)
     
  6. lazarocp

    lazarocp Kryx

    Joined:
    May 3, 2014
    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    As it would in tfs 1.3? Is there any way to make summon obey the player in 1.2?
     
  7. Itutorial

    Itutorial Active Member

    Joined:
    Dec 23, 2014
    Messages:
    865
    Likes Received:
    134
    Best Answers:
    6
    Best Answer
    Code (Lua):
    1.  
    2. function onUse(player, item, fromPosition, target, toPosition)
    3.     if player:getStorageValue(41111) == 1 then
    4.         player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    5.     else
    6.         local monster = Game.createMonster("Demon", player:getPosition())
    7.         monster:setMaster(player)
    8.         monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    9.  
    10.         player:sendTextMessage(MESSAGE_INFO_DESCR, "Demon!")
    11.         player:setStorageValue(41111, 1)
    12.     end
    13. return true
    14. end
    15.  
     
    Last edited: Mar 20, 2017
    lazarocp likes this.
  8. WibbenZ

    WibbenZ Support Team Support Team Premium User

    Joined:
    Oct 16, 2008
    Messages:
    4,590
    Likes Received:
    675
    Best Answers:
    39
    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.

    Code (Lua):
    1. function onUse(player, item, fromPosition, target, toPosition)
    2.     if player:getStorageValue(41111) == 1 then
    3.         player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    4.     else
    5.         local monster = Game.createMonster("Demon", player:getPosition())
    6.         monster:setMaster(player)
    7.         monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    8.  
    9.         player:sendTextMessage(MESSAGE_INFO_DESCR, "Demon!")
    10.         player:setStorageValue(41111, 1)
    11.     end
    12.     return true
    13. end
     
    lazarocp likes this.
  9. Itutorial

    Itutorial Active Member

    Joined:
    Dec 23, 2014
    Messages:
    865
    Likes Received:
    134
    Best Answers:
    6
    I win
     
  10. Makalo

    Makalo Banned User

    Joined:
    Mar 20, 2017
    Messages:
    20
    Likes Received:
    6
    Best Answers:
    0
    Code (Lua):
    1. function onUse(player, item, fromPosition, target, toPosition)
    2.     if player:getStorageValue(41111) == 1 then
    3.         player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    4.     else
    5.         local monster = Game.createMonster("Demon", player:getPosition())
    6.         if monster then -- check if monster was created
    7.             monster:setMaster(player)
    8.             monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    9.             player:sendTextMessage(MESSAGE_INFO_DESCR, "Demon!")
    10.             player:setStorageValue(41111, 1)
    11.         end
    12.     end
    13.     return true
    14. end
     
  11. Itutorial

    Itutorial Active Member

    Joined:
    Dec 23, 2014
    Messages:
    865
    Likes Received:
    134
    Best Answers:
    6
    pfft get out of here makalo.....

    How are you doing the lua code? mine just does code(text)?
     
  12. Makalo

    Makalo Banned User

    Joined:
    Mar 20, 2017
    Messages:
    20
    Likes Received:
    6
    Best Answers:
    0
    code=Lua /code
    Use the brackets
     
  13. Itutorial

    Itutorial Active Member

    Joined:
    Dec 23, 2014
    Messages:
    865
    Likes Received:
    134
    Best Answers:
    6
    Code (Lua):
    1.  
    2. function test
    3. return works
    4.  
     
    Makalo likes this.
  14. lazarocp

    lazarocp Kryx

    Joined:
    May 3, 2014
    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Thank you @Itutorial and others for help ! I'm still learning, could I when the item was used again did it remove the summon?
     
    Last edited: Mar 20, 2017
  15. Makalo

    Makalo Banned User

    Joined:
    Mar 20, 2017
    Messages:
    20
    Likes Received:
    6
    Best Answers:
    0
    Code (Lua):
    1. local storage = 41111
    2. local monsterName = "Demon"
    3.  
    4. function onUse(player, item, fromPosition, target, toPosition)
    5.     if player:getStorageValue(storage) == 1 then
    6.         player:sendTextMessage(MESSAGE_INFO_DESCR, "Noo.")
    7.         if player:removeSummon(monsterName) then
    8.             player:sendTextMessage(MESSAGE_INFO_DESCR, "You have removed "..monsterName..".")
    9.             player:setStorageValue(storage, 0)
    10.         end
    11.     else
    12.         local monster = Game.createMonster(monsterName, player:getPosition())
    13.         if monster then
    14.             monster:setMaster(player)
    15.             monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    16.             player:sendTextMessage(MESSAGE_INFO_DESCR, monsterName.."!")
    17.             player:setStorageValue(storage, 1)
    18.         end
    19.     end
    20.     return true
    21. end
     
  16. lazarocp

    lazarocp Kryx

    Joined:
    May 3, 2014
    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    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>
     
  17. Makalo

    Makalo Banned User

    Joined:
    Mar 20, 2017
    Messages:
    20
    Likes Received:
    6
    Best Answers:
    0
    The removeSummon function is from 1.3
    forgottenserver/creature.lua at 5ba1ef3926695237a8da3d969bd99e779a0ae7f1 · otland/forgottenserver · GitHub
    Possibly updating your creature.lua will alleviate the issue?
     
  18. WibbenZ

    WibbenZ Support Team Support Team Premium User

    Joined:
    Oct 16, 2008
    Messages:
    4,590
    Likes Received:
    675
    Best Answers:
    39
  19. lazarocp

    lazarocp Kryx

    Joined:
    May 3, 2014
    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    I was able to solve the problems, thanks for the help!
     
    Last edited: Mar 22, 2017 at 2:14 AM

Share This Page

Loading...