otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.55k stars 1.04k forks source link

[Bug]: Can't create multiple different NPC with the same display name #4759

Open ArturKnopik opened 2 weeks ago

ArturKnopik commented 2 weeks ago

By submitting this bug issue, you agree to the following.

Does this bug crash tfs?

no

Server Version

1.7 (Master)

Operation System

all (listed below)

OS Description

No response

Bug description

Can't create multiple different NPC with the same display name

Possible Pull Requests which are to blame

Steps to reproduce

  1. Copy Riona.xml -> Riona_Two.xml
  2. Add Riona Two to spawns (/s not working if NPC isn't on the map)
  3. Start server
  4. /goto Riona_Two

Additiona: /s Riona_Two not workin

Zrzut ekranu 2024-06-23 211139

Actual Behavior

/goto Riona_Two works, NPC have invalid name(name is taken from filename) /s Riona_Two not working

Expected Behavior

/goto Riona_Two should not works, npc Riona_Two.xml NPC should have Riona name(taken from xml file from name field) /s Riona_Two should create npc from Riona_Two.xml file named Riona

Backtrace

No response

ArturKnopik commented 2 weeks ago

for /s fix looks easy to be done

changes required in file place_npc.lua

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local position = player:getPosition()
    local npc = NpcType(param)  --  <<< change to Game.createNpc(param, position)
    if npc then
        Game.createNpc(param, position) -- <<< to remove
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
    else
        player:sendCancelMessage("There is not enough room.")
        position:sendMagicEffect(CONST_ME_POFF)
    end
    return false
end
EvilHero90 commented 2 weeks ago

I don't really get the sense behind this, as you can spawn the same npc just fine with /s or adding them several times in the mapeditor why would you want to make another xml file for the same npc? I'll include the changes proposed to /s in revnpcsys version 1.4

ArturKnopik commented 2 weeks ago

Example from issue is to fast setup env when issue occure

example: i want to have 2 npc with displayed name Traveler Traveler1.xml (travel1.lua) that teleport player to Island Traveler2.xml (travel2.lua) that teleport player to main land What was possible before changes is both npc has the same display name. For now file name is used and described behavior is impossible On map i will have Traveler1 and Traveler2 instead 2x Traveler (with different behaviors)


About /s - npc must not be loaded during startup(not present in spawn.xml)