#cw trading

1 messages · Page 1 of 1 (latest)

timber island
#

I was wondering. is it possible to do a random item received out of a select list
for example

local SandwichToBeer = {
    tradeName = 'SandwichToBeer',
    fromItems = {
        { name = 'blueprint_', amount = 10, itemcontains = 'blueprint' }
    },
    hasChance = {
        { name = 'beer', amount = 2, }
        { name = 'beer', amount = 4, }
        { name = 'beer', amount = 6, }
        { name = 'beer', amount = 8, }
    },
}``` it would act as like a blueprint rerolling system?
glass phoenix
#

Not with the current script no, but you can always add it. Look at how for example toMoney is handled. Mainly in the server file of trade

proper sorrel
#

SandwichToBeer.hasChance[math.random(1,#SandwichToBeer.hasChance)]

#

selects randomly from the hasChance table

timber island
proper sorrel
#

I don't actually use the script but i could look into making it random

timber island
timber island
#

@proper sorrel any luck?

timber island
#

i've figured it out

CONFIG.lua (cw-trade)

local SandwichToBeer = {
    tradeName = 'SandwichToBeer',
    fromItems = {
        { name = 'sandwich', amount = 2 },
    },
    toItems = {
        { name = 'steel' },
        { name = 'plastic' },
        { name = 'rubber' },
        { name = 'glass' }


    },
}```

### SERVER.lua (cw-trade)
```lua
        if trade.toItems then
            for i, item in pairs(trade.toItems) do
                local total = item.amount
                if modifier then
                    total = item.amount*modifier
                end
                if useDebug then
                   print('adding items to pockets')
                end
                addItem(item.name, math.random(1,12), item.info, src)
            end
        end```
#

thats to give multiple items at a mathrandom, im gonna try to do the blueprint one now