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

Lua [TFS 0.3.7] Exclusive use for first player

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
Hello everyone, everything good?

I created an outfit mechanic for my old server, where when using an item the player gets a specific looktype. The problem is, since the item cannot be removed, it can be loaned to anyone. Is there a way for the item to be exclusive to the first player who uses it? And make it possible to give use other times.

skin.lua

Lua:
function onUse(cid, item)
--------------------------------------------------    
local dolls = {
    [5220] = {outfit = 335, name = "Demon"},
    [5217] = {outfit = 334, name = "Golden"},
    [5269] = {outfit = 75, name = "GameMaster"},
    [5210] = {outfit = 332, name = "Pumpking"},
}
---------------------------------------------------
local go = dolls[item.itemid]
---------------------------------------------------
    if go then
        if getCreatureOutfit (cid).lookType ~= go.outfit then
            doCreatureChangeOutfit(cid, { lookType = go.outfit})
            doCreatureSay(cid, "Skin "..go.name..".", TALKTYPE_ORANGE_1)
            return true
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'The skin is already in use.')
            return true
        end
    end
end
 
Solution
Lua:
-- NPC
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

local items = {
  [5220] = {price = 100},
  [5217] = {price = 100},
  [5269] = {price = 100},
  [5210] = {price = 100}
}

function creatureSayCallback(cid, type, msg)
  if(not npcHandler:isFocused(cid)) then return false end
  local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  local...
Give the doll a special description, stating the player's name, and compare that name to the person using the doll.

or make a global + regular storage value assigned to the doll.
If global storage is -1, doll has never been used, and give that player the storage value to use the doll.
If global storage is 1, doll has been used.

Could maybe play around with the global storage value and player guid, but I don't understand it enough. xP
 
Give the doll a special description, stating the player's name, and compare that name to the person using the doll.

or make a global + regular storage value assigned to the doll.
If global storage is -1, doll has never been used, and give that player the storage value to use the doll.
If global storage is 1, doll has been used.

Could maybe play around with the global storage value and player guid, but I don't understand it enough. xP
This item is selled by npc
 
Yep, so go with the first solution I posted.
Can u tech me how do it? I failed x.x
Post automatically merged:

Can u tech me how do it? I failed x.x
There is no way to put when a specific player use a item, only this player can use other times? In action script.
 
Last edited:
Lua:
-- NPC
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

local items = {
  [5220] = {price = 100},
  [5217] = {price = 100},
  [5269] = {price = 100},
  [5210] = {price = 100}
}

function creatureSayCallback(cid, type, msg)
  if(not npcHandler:isFocused(cid)) then return false end
  local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  local shopWindow = {}

  local buy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
    local value = items[item]
    if value then
      if amount <= 0 then return false end
      if not doPlayerRemoveMoney(cid, value.price * amount) then
        return doPlayerSendCancel(cid, ('You need %d gold coins.'):format(price))
      end
      for i = 1, amount do
        local itemEx = doCreateItemEx(item)
        doItemSetAttribute(itemEx, "owner", getCreatureName(cid))
        doItemSetAttribute(itemEx, "description", ('Owner: %s.'):format(getCreatureName(cid)))
        doPlayerAddItemEx(cid, itemEx, true)
      end
    end
  end

  if (msgcontains(msg, 'trade')) then
    for var, ret in pairs(items) do
      table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, buy, onSell)
  end
  return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Lua:
-- Action

function onUse(cid, item)
--------------------------------------------------   
local dolls = {
    [5220] = {outfit = 335, name = "Demon"},
    [5217] = {outfit = 334, name = "Golden"},
    [5269] = {outfit = 75, name = "GameMaster"},
    [5210] = {outfit = 332, name = "Pumpking"},
}
---------------------------------------------------
local go = dolls[item.itemid]
---------------------------------------------------
    if not getItemAttribute(item.uid, "owner") then
      doItemSetAttribute(item.uid, "owner", getCreatureName(cid))
      doItemSetAttribute(item.uid, "description", ('Owner: %s.'):format(getCreatureName(cid)))
    elseif getItemAttribute(item.uid, "owner") ~= getCreatureName(cid) then
      return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'This item does not belong to you..')
    elseif getCreatureOutfit(cid).lookType == go.outfit then
      return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'The skin is already in use.')
    end

    doCreatureChangeOutfit(cid, { lookType = go.outfit })
    doCreatureSay(cid, "Skin " .. go.name .. ".", TALKTYPE_ORANGE_1)
    return true
end
 
Solution
Lua:
-- NPC
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

local items = {
  [5220] = {price = 100},
  [5217] = {price = 100},
  [5269] = {price = 100},
  [5210] = {price = 100}
}

function creatureSayCallback(cid, type, msg)
  if(not npcHandler:isFocused(cid)) then return false end
  local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  local shopWindow = {}

  local buy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
    local value = items[item]
    if value then
      if amount <= 0 then return false end
      if not doPlayerRemoveMoney(cid, value.price * amount) then
        return doPlayerSendCancel(cid, ('You need %d gold coins.'):format(price))
      end
      for i = 1, amount do
        local itemEx = doCreateItemEx(item)
        doItemSetAttribute(itemEx, "owner", getCreatureName(cid))
        doItemSetAttribute(itemEx, "description", ('Owner: %s.'):format(getCreatureName(cid)))
        doPlayerAddItemEx(cid, itemEx, true)
      end
    end
  end

  if (msgcontains(msg, 'trade')) then
    for var, ret in pairs(items) do
      table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, buy, onSell)
  end
  return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Lua:
-- Action

function onUse(cid, item)
--------------------------------------------------  
local dolls = {
    [5220] = {outfit = 335, name = "Demon"},
    [5217] = {outfit = 334, name = "Golden"},
    [5269] = {outfit = 75, name = "GameMaster"},
    [5210] = {outfit = 332, name = "Pumpking"},
}
---------------------------------------------------
local go = dolls[item.itemid]
---------------------------------------------------
    if not getItemAttribute(item.uid, "owner") then
      doItemSetAttribute(item.uid, "owner", getCreatureName(cid))
      doItemSetAttribute(item.uid, "description", ('Owner: %s.'):format(getCreatureName(cid)))
    elseif getItemAttribute(item.uid, "owner") ~= getCreatureName(cid) then
      return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'This item does not belong to you..')
    elseif getCreatureOutfit(cid).lookType == go.outfit then
      return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'The skin is already in use.')
    end

    doCreatureChangeOutfit(cid, { lookType = go.outfit })
    doCreatureSay(cid, "Skin " .. go.name .. ".", TALKTYPE_ORANGE_1)
    return true
end
Worked, thank you @Alberto Cabrera
 
Back
Top