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

how to create NPC inside house

carlinhous1996

New Member
Joined
Apr 14, 2022
Messages
54
Reaction score
3
TFS 0.4 8.6
can someone please help me with an item that can only be used indoors

and when using this item creates an npc ?

I've tried in different ways and no

I always get this error the item disappears but the npc does not appear
[Erro - Interface de ação]
data/actions/scripts/npcnahouse.lua:eek:nUse
Descrição:
(luaDoCreateNpc) Não é possível criar npc: Alice
id local = 6507 -- ItemId da Estatua
local npc = "Alice" -- Nome do npc
função onUse(cid, item, fromPosition, itemEx, toPosition)
se getTileHouseInfo(fromPosition) == FALSE então
doPlayerSendCancel(cid,"Voce so pode criar o npc dentro da casa.")
elseif fromPosition.x == CONTAINER_POSITION then
doPlayerSendCancel(cid, "Coloque o item no primeiro chão.")
elseif id ~= nil then
doRemoveItem(item.uid, 1)
doCreateNpc(npc, toPosition)
doSendMagicEffect(fromPosition, CONST_ME_POFF)
senão
retorna falso
fim
retornar VERDADEIRO
fim
 
Last edited:
TFS0,4 8,6
alguém pode por favor me ajudar com um item que só pode ser usado dentro de casa
e ao usar este item cria um npc ?
ja tentei de varias formas e nem
sempre consigo dá esse erro o item desaparece mas o npc nao aparece
Você consegue usar o /n Alice pra criar o NPC sem o script? Outra coisa que recomendo é postar em Inglês em próximas vezes, assim você amplia a margem de ajuda nesse fórum.
 
Você consegue usar o /n Alice pra criar o NPC sem o script? Outra coisa que recomendo é postar em Inglês em próximas vezes, assim você amplia a margem de ajuda nesse fórum.
tinha postado em ingles, mas o tradutor mudou sorry.
o /n tambem nao funciona para criar nunhum dentro da house
o erro é com todos os npcs.
[Error - Action Interface]
data/actions/scripts/npcnahouse.lua:eek:nUse
Description:
(luaDoCreateNpc) Cannot create npc: Oiriz

e quando uso o item dentro da bag aparece este erro
[Error - Action Interface]
data/actions/scripts/npcnahouse.lua:eek:nUse
Description:
(luaGetHouseFromPos) Tile not found
 
Last edited:
If you can compile then you have to modify the doCreateNpc function
in this part: if(!g_game.placeCreature(npc, pos)) and add two more arguments you need to force the npc to place: if(!g_game.placeCreature(npc, pos, false, true))

then all the npc created with the doCreateNpc function will be forced to appear.
what is obvious is that these npc will not be there forever, when the server is closed, you will reopen it, that npc will no longer be there, unless you create a system to save npc in the houses. already having the modified function you can create your system.

the normal thing would be to add the functionality to the function to allow you to pass these arguments manually from lua, so you can force or not force the placement from lua.
 
If you can compile then you have to modify the doCreateNpc function
in this part: if(!g_game.placeCreature(npc, pos)) and add two more arguments you need to force the npc to place: if(!g_game.placeCreature(npc, pos, false, true))

then all the npc created with the doCreateNpc function will be forced to appear.
what is obvious is that these npc will not be there forever, when the server is closed, you will reopen it, that npc will no longer be there, unless you create a system to save npc in the houses. already having the modified function you can create your system.

the normal thing would be to add the functionality to the function to allow you to pass these arguments manually from lua, so you can force or not force the placement from lua.
is it only possible this way? I don't understand anything about compilation
 
is it only possible this way? I don't understand anything about compilation
idk your engine, but the TFS 0.4 I've seen on github seem to have no way to force npc placement from Lua
so I'm assuming your TFS 0.4 to be the same.

I think there is no other way, I'm not sure.
 
idk your engine, but the TFS 0.4 I've seen on github seem to have no way to force npc placement from Lua
so I'm assuming your TFS 0.4 to be the same.

I think there is no other way, I'm not sure.
do you know how to change this script to be able to use the item that becomes the npc inside bp
and add a storage in the player?
local id = 11391 -- ItemId da Estatua
local npc = "Cooking" -- Nome do monsto a ser sumonado

function onUse(cid, item, fromPosition, itemEx, toPosition)
doRemoveItem(item.uid, 1)
doCreateNpc(npc, fromPosition)

return true
end
and in this script you can put para da use on npc and turn it into the item only if you have storage X
function onTarget(cid, target)
if (isPlayer(cid) and isNpc(target) and getCreatureName(target) == "Cooking") then
doSendMagicEffect(getThingPos(target), CONST_ME_MAGIC_BLUE)
doRemoveCreature(target)
doPlayerAddItem(cid, 11391, 1)
end
return true
end
 
do you know how to change this script to be able to use the item that becomes the npc inside bp
and add a storage in the player?

and in this script you can put para da use on npc and turn it into the item only if you have storage X
maybe:
data/creturescripts/scripts/cooking_npc.lua
Lua:
function onTarget(cid, target)
    if isPlayer(cid) and isNpc(target) and getCreatureName(target) == "Cooking" then
        if getCreatureStorage(cid, 10000) ~= 1 then
            doPlayerSendCancel(cid, "Sorry, not possible.")
            return true
        end

        doSendMagicEffect(getThingPos(target), CONST_ME_MAGIC_BLUE)
        doRemoveCreature(target)
        doPlayerAddItem(cid, 11391, 1)
        doCreatureSetStorage(cid, 10000, -1)
    end
    return true
end

data/creaturescripts/creaturescripts.xml
XML:
<event type="target" name="CookingNpc" event="script" value="cooking_npc.lua"/>

data/actions/scripts/cooking_npc.lua
Lua:
local npcName = "Alice" -- Nome do npc

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if fromPosition.x == CONTAINER_POSITION then
        doPlayerSendCancel(cid, "Coloque o item no primeiro chão.")
    elseif not getHouseFromPos(fromPosition) then
        doPlayerSendCancel(cid, "Voce so pode criar o npc dentro da casa.")
    else
        doRemoveItem(item.uid, 1)
        doCreateNpc(npcName, fromPosition, false, true)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
        doCreatureSetStorage(cid, 10000, 1)
    end
    return true
end

data/actions/actions.xml
XML:
<action itemid="6507" event="script" value="cooking_npc.lua"/>

But remember this may not work to spawn the npc inside the house, I just added the storage.
For the npc you must add the changes in the sources.
 
maybe:
data/creturescripts/scripts/cooking_npc.lua
Lua:
function onTarget(cid, target)
    if isPlayer(cid) and isNpc(target) and getCreatureName(target) == "Cooking" then
        if getCreatureStorage(cid, 10000) ~= 1 then
            doPlayerSendCancel(cid, "Sorry, not possible.")
            return true
        end

        doSendMagicEffect(getThingPos(target), CONST_ME_MAGIC_BLUE)
        doRemoveCreature(target)
        doPlayerAddItem(cid, 11391, 1)
        doCreatureSetStorage(cid, 10000, -1)
    end
    return true
end

data/creaturescripts/creaturescripts.xml
XML:
<event type="target" name="CookingNpc" event="script" value="cooking_npc.lua"/>

data/actions/scripts/cooking_npc.lua
Lua:
local npcName = "Alice" -- Nome do npc

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if fromPosition.x == CONTAINER_POSITION then
        doPlayerSendCancel(cid, "Coloque o item no primeiro chão.")
    elseif not getHouseFromPos(fromPosition) then
        doPlayerSendCancel(cid, "Voce so pode criar o npc dentro da casa.")
    else
        doRemoveItem(item.uid, 1)
        doCreateNpc(npcName, fromPosition, false, true)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
        doCreatureSetStorage(cid, 10000, 1)
    end
    return true
end

data/actions/actions.xml
XML:
<action itemid="6507" event="script" value="cooking_npc.lua"/>

But remember this may not work to spawn the npc inside the house, I just added the storage.
For the npc you must add the changes in the sources.
thank you so much you helped a lot!!!!
will it be if I put 1 spawn in all the houses the npc dps of the SS will continue in place?
 
Back
Top