• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action [TFS 1.0] House market (buy/sell)

Anyone can help me with gsub pattern?
Buy[stuffed dragon, 5000, 5; demon shield, 30000, 4; mace, 15;]
I need to find this, ignore price and replace this to (value - amount).
itemname(any amount of spaces),(any amount of spaces and numbers to be ignored),(any amount of spaces)number
 
Last edited:
I'll update first post today.
Creaturescript is prepared for metatables so it'll be simple to rewrite that.

Can't do that now. I'm posting via phone.
 
Anyone can help me with gsub pattern?

I need to find this, ignore price and replace this to (value - amount).
itemname(any amount of spaces),(any amount of spaces and numbers to be ignored),(any amount of spaces)number
What should the output be then?
 
Item name and amount
Replace amount with this amount - number of items player sold so when it reach 0 player can't sell this item anymore
 
Just explode(','), reduce amount and concatenate again
 
Just explode(','), reduce amount and concatenate again
walk of shame again...
It seems to be only way.

@Colors
enable new option in events and replace existing function to this:
Code:
function Player:onTradeRequest(target, item)
   if isHousetile(item:getPosition()) then   -- is this a house
     if self:getAccountType() == ACCOUNT_TYPE_GOD and self:getGroup():getAccess() then -- is server admin
       return true
     end
   
     if Tile(item:getPosition()):getHouse():getOwnerGuid() == self:getGuid() then -- is house owner
       return true
     end
   
     if isHousetile(self:getPosition()) then -- is inside a house
       return true
     end
     -- random player
     self:sendCancelMessage("This item doesn't belong to you.")
     return false
   end
return true
end

unregister and remove creaturescript

first post updated
 
@zbizu
Code:
function Player:onTradeRequest(player,target, item)
Just Wanted To Tell you Anyway Nice :)
 
There is no player parameter
 
There is no player parameter
Code:
bool Events::eventPlayerOnTradeRequest(Player* player, Player* target,Item* item)
Code:
LuaScriptInterface::pushUserdata<Player>(L, player);
    LuaScriptInterface::setMetatable(L, -1, "Player");
And Yes You Are Right you can use "self". I Haven't Really Scripted to tfs 1.0 so you can correct me if i said anything Wrong.
-- i found my mistake
Code:
function Player:onTradeRequest(target, item)
Player is Already declared in Player:onTradeRequest
 
Last edited:
Now I'm just having problems with the onMove... I can still move items on the edges :p

@EDIT: The problem is the capital letter on the player.lua part haha

function Player:OnMoveItem(item, count, fromPosition, toPosition)
 
@EDIT: The problem is the capital letter on the player.lua part haha
first post updated
Is there any way to disable emoticons / bb code for post? They ruin lua codes

@ down
it wasn't in code tag
preview feathure fucked up formatting and converted that to emoticon
 
Last edited:
First post updated(new wklej.to link)

changes:
- added amount support in buy, example:
when you want to buy only 3 maces, no more:
Buy[mace, 30, 3]

- replaced :explode to :split so you don't need to add compat anymore
 
hi zbizu
I followed all the really good explanations, start the server (I have tfs 1.0) and all goes well except this little error:


[Warning - Events::load] Can not load script: player.lua
data/events/scripts/player.lua:147: '<eof>' expected near 'end'

well I have the player.lua:

Code:
function Player:onBrowseField(position)[/COLOR][/COLOR]
[COLOR=#0000ff][COLOR=#000000]    return true
end

function Player:onLook(thing, position, distance)
    local description = 'You see ' .. thing:getDescription(distance)
    if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format('%s\nItemID: [%d]', description, thing:getId())

            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format('%s, ActionID: [%d]', description, actionId)
            end

            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format('%s, UniqueId: [%d]', description, uniqueId)
            end

            description = description .. '.'
            local itemType = thing:getType()

            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format('%s\nTransformTo: [%d] (onEquip).', description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format('%s\nTransformTo: [%d] (onDeEquip).', description, transformDeEquipId)
            end

            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format('%s\nDecayTo: [%d]', description, decayId)
            end
        elseif thing:isCreature() then
            local str = '%s\nHealth: [%d / %d]'
            if thing:getMaxMana() > 0 then
                str = string.format('%s, Mana: [%d / %d]', str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. '.'
        end

        local position = thing:getPosition()
        description = string.format(
            '%s\nPosition: [X: %d] [Y: %d] [Z: %d].',
            description, position.x, position.y, position.z
        )

        if thing:isCreature() and thing:isPlayer() then
            description = string.format('%s\nIP: [%s].', description, Game.convertIpToString(thing:getIp()))
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

function Player:onLookInBattleList(creature, distance)
    local description = 'You see ' .. creature:getDescription(distance)
    if self:getGroup():getAccess() then
        local str = '%s\nHealth: [%d / %d]'
        if creature:getMaxMana() > 0 then
            str = string.format('%s, Mana: [%d / %d]', str, creature:getMana(), creature:getMaxMana())
        end
        description = string.format(str, description, creature:getHealth(), creature:getMaxHealth()) .. '.'

        local position = creature:getPosition()
        description = string.format(
            '%s\nPosition: [X: %d] [Y: %d] [Z: %d].',
            description, position.x, position.y, position.z
        )

        if creature:isPlayer() then
            description = string.format('%s\nIP: [%s].', description, Game.convertIpToString(creature:getIp()))
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

function Player:onLookInTrade(partner, item, distance)
    self:sendTextMessage(MESSAGE_INFO_DESCR, 'You see ' .. item:getDescription(distance))
end

function Player:onLookInShop(itemType, count)
    return true
end

function Player:onMoveItem(item, count, fromPosition, toPosition)
  function isHousetile(position)
   local t = Tile(position)
   if t == nil then
   return false
   end
   return t:hasFlag(TILESTATE_HOUSE)
   end
   if isHousetile(item:getPosition()) then   -- yup, it's a housetile
     if self:getAccountType() == ACCOUNT_TYPE_GOD and self:getGroup():getAccess() then -- is server admin
       return true
     end
     if Tile(item:getPosition()):getHouse():getOwnerGuid() == self:getGuid() then -- is house owner
       return true
     end
     if isHousetile(self:getPosition()) then -- is inside a house
       return true
     end
     -- random player
     self:sendCancelMessage("Sorry, not possible.")
     return false
   end
return true
end

function Player:onTradeRequest(target, item)
   if isHousetile(item:getPosition()) then   -- is this a house
     if self:getAccountType() == ACCOUNT_TYPE_GOD and self:getGroup():getAccess() then -- is server admin
       return true
     end

     if Tile(item:getPosition()):getHouse():getOwnerGuid() == self:getGuid() then -- is house owner
       return true
     end

     if isHousetile(self:getPosition()) then -- is inside a house
       return true
     end
     -- random player
     self:sendCancelMessage("This item doesn't belong to you.")
     return false
   end
return true
end

    if isInArray({1738, 1740, 1747, 1748, 1749}, item:getId()) and item:getActionId() > 0 then
        self:sendCancelMessage('You cannot move this object.')
        return false
    elseif item:getId() == 7466 then
        self:sendCancelMessage('You cannot move this object.')
        return false
    end

    if fromPosition.x == 65535 and toPosition.x == 65535
            and item:getId() == 8710 and self:getItemCount(8710) == 2 and self:getStorageValue(Storage.RookgaardTutorialIsland.cockroachLegsMsgStorage) ~= 1 then
        self:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Well done, you have enough cockroach legs! You should head back to Santiago with them. Climb the ladder to the north to exit.')
        self:setStorageValue(Storage.RookgaardTutorialIsland.cockroachLegsMsgStorage, 1)
        self:setStorageValue(Storage.RookgaardTutorialIsland.SantiagoNpcGreetStorage, 6)
    end
    return true
end      <-------  this is line 147

function Player:onMoveCreature(creature, fromPosition, toPosition)
    return true
end

function Player:onTurn(direction)
    return true
end

function Player:onTradeRequest(target, item)
    if isInArray({1738, 1740, 1747, 1748, 1749, 8766}, item:getId()) and item:getActionId() > 0 then
        self:sendCancelMessage('Sorry, not possible.')
        return false
    end
    return true
end

function Player:onTradeAccept(target, item, targetItem)
    return true
end

function Player:onGainExperience(source, exp, rawExp)
    return exp
end

function Player:onLoseExperience(exp)
    return exp
end

if you could review and tell me how you fix greatly appreciate it.


Thanks to those who read it and greetings

[SOLVED]





 
Last edited:
Code:
    if fromPosition.x == 65535 and toPosition.x == 65535
            and item:getId() == 8710 and self:getItemCount(8710) == 2 and self:getStorageValue(Storage.RookgaardTutorialIsland.cockroachLegsMsgStorage) ~= 1 then
        self:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Well done, you have enough cockroach legs! You should head back to Santiago with them. Climb the ladder to the north to exit.')
        self:setStorageValue(Storage.RookgaardTutorialIsland.cockroachLegsMsgStorage, 1)
        self:setStorageValue(Storage.RookgaardTutorialIsland.SantiagoNpcGreetStorage, 6)
        return true
    end

that's how it should look I believe....
 
Back
Top