• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Nazwa NPC + getCreatureName(cid)

Verdis

Ciekawy świata.
Joined
May 28, 2012
Messages
394
Reaction score
9
Location
Poland
Witam,
dałoby radę stworzyć komendą !merchant create: npc w którego nazwę wchodzi Merchant + getCreatureName(cid) np. Merachant Administrator..
Wie ktoś jak tego dokonać? :D Jak tak proszę o jakąś podpowiedź :D
 
Bo mam merchant system, lecz zawsze tworzy się npc "Merchant" a chciałem także uwzględnić w nim nazwę gracze który go postawił.
 
Code:
<talkaction words="!merchant" event="script"><![CDATA[
    domodlib('merchantSystem_conf')
    function onSay(cid, words, param, channel)
    if param:lower() == 'create' then
       
        if getPlayerItemCount(cid, requiedItemToPutMerchant[1]) < requiedItemToPutMerchant[2] then
              return doPlayerSendCancel(cid, 'You don\'t have enough '..getItemNameById(requiedItemToPutMerchant[1])..'s.')
        end
        if getPlayerItemCount(cid, writeableItem) < 1 then
              return doPlayerSendCancel(cid, 'You need '..getItemNameById(writeableItem)..' to put merchant.')
        end
        local merchPlayer = getCreatureStorage(cid, merchantStorage)
        if merchPlayer ~= -1 or isCreature(merchPlayer) then
              doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
              return doPlayerSendCancel(cid, 'Only one merchant at once!')
        end
        local greetMessage, itemOffert = doSearchWriteItem(cid, writeableItem)
        if greetMessage and itemOffert then
              local itemsExplode = itemOffert:explode('\n')
              if #itemsExplode < 1 then
                  return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
              end
              local p = getThingPos(cid)
        if getThingFromPos({x=p.x,y=p.y,z=p.z}, true).actionid ~= 123 then
          return doPlayerSendCancel(cid, 'You can\'t create merchant here!')
        end
       
              local itemList, merchant = {}, doCreateNpc('merchant', getThingPos(cid), false)
   
           
              for _, v in pairs(itemsExplode) do
                  local itemExplode = v:explode(',')
                  if #itemExplode < 2 then
                        doRemoveThing(merchant)
                        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                        return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
                  end
                    if #itemExplode > 3 then
                        doRemoveThing(merchant)
                        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                        return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
                  end
                  local itemId, itemCount = itemExplode[1], itemExplode[3] or 1
                    if type(tonumber(itemCount)) ~= 'number' or tonumber(itemCount) <= 0 then
                            doRemoveThing(merchant)
                            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                            return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'The amount must be a number greater than zero.')
                    end
                              if type(tonumber(itemExplode[2])) ~= 'number' or tonumber(itemExplode[2]) <= 0 then
                            doRemoveThing(merchant)
                            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                            return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Price must be a number greater than zero.')
                            end
                  if type(itemId) == 'string' then
                        itemId = getItemIdByName(itemExplode[1], false)
                        if not itemId then
                            doRemoveThing(merchant)
                            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                            return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Wrong item name!')
                        end
                          if getPlayerItemCount(cid, itemId) < tonumber(itemCount) then
                            doRemoveThing(merchant)
                            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                            return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You don\'t have these items.')
                        end
                  end
                  if getPlayerItemCount(cid, itemId) >= tonumber(itemCount) then
                        itemList[#itemList + 1] = {}
                        itemList[#itemList + 1] = {itemId = itemId, itemPrice = itemExplode[2], itemCount = itemCount}
                  end
              end
              for _, v in pairs(itemList) do
                  if v.itemId then
                        doPlayerRemoveItem(cid, v.itemId, v.itemCount)
                  end
              end
              addNewNpcItemList(cid, merchant, itemList)
              doPlayerRemoveItem(cid, requiedItemToPutMerchant[1], requiedItemToPutMerchant[2])
              doCreatureSetStorage(cid, merchantStorage, merchant)
              doCreatureSetStorage(merchant, merchantStorage-2, '_'..cid)
              doCreatureSetStorage(merchant, merchantStorage-1, '_' .. getCreatureName(cid) .. '_' .. getPlayerTown(cid))
              doCreatureChangeOutfit(merchant, getCreatureOutfit(cid))
              sayGreet(greetMessage, merchant)
              return doCreatureSetStorage(merchant, cashStorage, 0)
        end
   
    end
    return true
    end
    ]]></talkaction>
 
Sprawdź:

Code:
<talkaction words="!merchant" event="script"><![CDATA[
    domodlib('merchantSystem_conf')
    function onSay(cid, words, param, channel)
    if param:lower() == 'create' then
     
        if getPlayerItemCount(cid, requiedItemToPutMerchant[1]) < requiedItemToPutMerchant[2] then
              return doPlayerSendCancel(cid, 'You don\'t have enough '..getItemNameById(requiedItemToPutMerchant[1])..'s.')
        end
        if getPlayerItemCount(cid, writeableItem) < 1 then
              return doPlayerSendCancel(cid, 'You need '..getItemNameById(writeableItem)..' to put merchant.')
        end
        local merchPlayer = getCreatureStorage(cid, merchantStorage)
        if merchPlayer ~= -1 or isCreature(merchPlayer) then
              doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
              return doPlayerSendCancel(cid, 'Only one merchant at once!')
        end
        local greetMessage, itemOffert = doSearchWriteItem(cid, writeableItem)
        if greetMessage and itemOffert then
              local itemsExplode = itemOffert:explode('\n')
              if #itemsExplode < 1 then
                  return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
              end
              local p = getThingPos(cid)
        if getThingFromPos({x=p.x,y=p.y,z=p.z}, true).actionid ~= 123 then
          return doPlayerSendCancel(cid, 'You can\'t create merchant here!')
        end
     
              local itemList, merchant = {}, doCreateNpc('Merchant ('..getCreatureName(cid)..')', getThingPos(cid), false)
 
         
              for _, v in pairs(itemsExplode) do
                  local itemExplode = v:explode(',')
                  if #itemExplode < 2 then
                        doRemoveThing(merchant)
                        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                        return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
                  end
                    if #itemExplode > 3 then
                        doRemoveThing(merchant)
                        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                        return doPlayerSendCancel(cid, 'Invalid text in writeable item.')
                  end
                  local itemId, itemCount = itemExplode[1], itemExplode[3] or 1
                    if type(tonumber(itemCount)) ~= 'number' or tonumber(itemCount) <= 0 then
                            doRemoveThing(merchant)
                            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                            return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'The amount must be a number greater than zero.')
                    end
                              if type(tonumber(itemExplode[2])) ~= 'number' or tonumber(itemExplode[2]) <= 0 then
                            doRemoveThing(merchant)
                            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                            return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Price must be a number greater than zero.')
                            end
                  if type(itemId) == 'string' then
                        itemId = getItemIdByName(itemExplode[1], false)
                        if not itemId then
                            doRemoveThing(merchant)
                            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                            return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Wrong item name!')
                        end
                          if getPlayerItemCount(cid, itemId) < tonumber(itemCount) then
                            doRemoveThing(merchant)
                            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                            return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You don\'t have these items.')
                        end
                  end
                  if getPlayerItemCount(cid, itemId) >= tonumber(itemCount) then
                        itemList[#itemList + 1] = {}
                        itemList[#itemList + 1] = {itemId = itemId, itemPrice = itemExplode[2], itemCount = itemCount}
                  end
              end
              for _, v in pairs(itemList) do
                  if v.itemId then
                        doPlayerRemoveItem(cid, v.itemId, v.itemCount)
                  end
              end
              addNewNpcItemList(cid, merchant, itemList)
              doPlayerRemoveItem(cid, requiedItemToPutMerchant[1], requiedItemToPutMerchant[2])
 
Code:
doCreateNpc('Merchant ('..getCreatureName(cid)..')', getThingPos(cid), false)
To nie może zadziałać bo nie mam npc o takiej nazwie: Merchant nick_garcza.Ale Dzięki za chęci :D
 
Code:
doCreateNpc('Merchant ('..getCreatureName(cid)..')', getThingPos(cid), false)
To nie może zadziałać bo nie mam npc o takiej nazwie: Merchant nick_garcza.Ale Dzięki za chęci :D
A nie ma takiej funkcji co zmienia nazwe gracza / npc w locie? wydaje mi sie ze byla.
 
Wystarczy ze wygenerujesz nowego NPC przed wywolaniem go w skrypcie albo zmienisz jego nazwę zaraz po wywolaniu :)

Zmianę nazwy NPC bez edycji kodu źródłowego się nie obędzie, ale zawsze możesz zastosować utworzenie nowego NPC w osobnym folderze, co będzie dla początkujących (a raczej ludzi którzy nie ogarniają C++) łatwiejsze.

Code:
local file = io.open("data/npc/merchants/Merchant "..getCreatureName(cid)..".xml", "w")
file:write('<?xml version="1.0" encoding="UTF-8"?><npc name="Merchant '..getCreatureName(cid)..'" script="merchant.lua" walkinterval="2000" floorchange="0"><health now="100" max="100"/><look type="133" head="57" body="113" legs="95" feet="113" addons="0"/><parameters></parameters></npc>')
file:close()

Pisałem z tableta, nie wiem czy gdzies nie ma błędu, ale to tylko przykład, zawsze możesz sprawdzać modyfikacje (pliku żeby nadpisał owy z nowym looktype itp.), look type itp pobrać od gracza żeby tak samo wyglądał, ogólnie lua ma dużo zastosowań, ale myślę że z podstawami C++ poradzisz sobie dodać funkcję zmieniania nicku postaci.

Znalazłem coś co Ci się przyda, do lekkiej edycji w zależności od source :)

http://otland.net/threads/change-existing-monster-name-in-game.131643/
 
Last edited:
Mój handlarz jest w folderze merchant (wiem lepiej żeby oddzielić od npc) lecz nie mogę stworzyć tego npc jak znajduje się w tym folderze. Tzn jak wrzuce merchanta od razu do npc to działa i się załaduje all :D THX za pomoc :)
 
Back
Top