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

RevScripts Lever Shop, change payment to item and amount

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,076
Solutions
15
Reaction score
370
Location
Sweden
YouTube
Joriku
Hi,
Don't ask me why but I had too little sleep for this. Been sitting with this for around 4 hours on a non sleep and can't manage to get it to take my item as payment instead of money.
Original script
Lua:
-- Script by Klonera/Joriku
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)

local spellName = "Increment Mana"
local price = 1000000

function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    print("Test Script Loaded In Successfully.")
    if player:hasLearnedSpell(spellName) then
            player:sendCancelMessage("You already have this spell.")
            return true
        end
    if player:getMoney() < price then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough money.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end
        player:learnSpell(spellName)
        player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You buy %s for %s gold coins.", spellName, price))
        fromPosition:sendMagicEffect(CONST_ME_HEARTS)
        player:removeMoney(price)
    print("Test Script Ended Successfully.")
    return true
end

testAction:aid(667) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed



Something I've tried out of alot of options
Lua:
-- Script by Klonera/Joriku
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)

local c = {
    ['spellName'] = "Increment Super Mana"
    ['item'] = 2294,
    ['price'] = 1
}

function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    print("Test Script Loaded In Successfully.")
    if player:hasLearnedSpell(c.spellName) then
            player:sendCancelMessage("You already have this spell.")
            return true
        end
    if player:getId(c.item) == c.price then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough tokens.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end
        player:learnSpell(c.spellName)
        player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You buy %s for %s tokens.", c.spellName, c.price))
        fromPosition:sendMagicEffect(CONST_ME_HEARTS)
        player:removeMoney(c.price)
    print("Test Script Ended Successfully.")
    return true
end

testAction:aid(660) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed


I managed to make it give it inc. check the item but not to remove it for some reason, then I compleatley lost it
 
Hi,
Don't ask me why but I had too little sleep for this. Been sitting with this for around 4 hours on a non sleep and can't manage to get it to take my item as payment instead of money.
Original script
Lua:
-- Script by Klonera/Joriku
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)

local spellName = "Increment Mana"
local price = 1000000

function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    print("Test Script Loaded In Successfully.")
    if player:hasLearnedSpell(spellName) then
            player:sendCancelMessage("You already have this spell.")
            return true
        end
    if player:getMoney() < price then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough money.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end
        player:learnSpell(spellName)
        player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You buy %s for %s gold coins.", spellName, price))
        fromPosition:sendMagicEffect(CONST_ME_HEARTS)
        player:removeMoney(price)
    print("Test Script Ended Successfully.")
    return true
end

testAction:aid(667) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed



Something I've tried out of alot of options
Lua:
-- Script by Klonera/Joriku
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)

local c = {
    ['spellName'] = "Increment Super Mana"
    ['item'] = 2294,
    ['price'] = 1
}

function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    print("Test Script Loaded In Successfully.")
    if player:hasLearnedSpell(c.spellName) then
            player:sendCancelMessage("You already have this spell.")
            return true
        end
    if player:getId(c.item) == c.price then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough tokens.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end
        player:learnSpell(c.spellName)
        player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You buy %s for %s tokens.", c.spellName, c.price))
        fromPosition:sendMagicEffect(CONST_ME_HEARTS)
        player:removeMoney(c.price)
    print("Test Script Ended Successfully.")
    return true
end

testAction:aid(660) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed


I managed to make it give it inc. check the item but not to remove it for some reason, then I compleatley lost it

Are you trying to remove 1x2294 ?

Lua:
-- Script by Klonera/Joriku
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)
local c = {
    spellName = "Increment Super Mana",
    item = 2294,
    price = 1
}

function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    if player:hasLearnedSpell(c.spellName) then
        player:sendCancelMessage("You already have this spell.")
        return true
    end

    local tokenCount = player:getItemCount(c.item)
    if tokenCount and tokenCount >= c.price then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough tokens.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end

    player:learnSpell(c.spellName)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You buy %s for %s tokens.", c.spellName, c.price))
    fromPosition:sendMagicEffect(CONST_ME_HEARTS)
    local tokens = player:getItemById(c.item)
    tokens:remove(c.price)
    return true
end

testAction:aid(660) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed
 
Are you trying to remove 1x2294 ?

Lua:
-- Script by Klonera/Joriku
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)
local c = {
    spellName = "Increment Super Mana",
    item = 2294,
    price = 1
}

function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    if player:hasLearnedSpell(c.spellName) then
        player:sendCancelMessage("You already have this spell.")
        return true
    end

    local tokenCount = player:getItemCount(c.item)
    if tokenCount and tokenCount >= c.price then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough tokens.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end

    player:learnSpell(c.spellName)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You buy %s for %s tokens.", c.spellName, c.price))
    fromPosition:sendMagicEffect(CONST_ME_HEARTS)
    local tokens = player:getItemById(c.item)
    tokens:remove(c.price)
    return true
end

testAction:aid(660) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed
Dang, giving out 2294. Removing 9020. I re-wrote that when I we're tired. WIll give it another try (Updating this post
 
Are you trying to remove 1x2294 ?

Lua:
-- Script by Klonera/Joriku
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)
local c = {
    spellName = "Increment Super Mana",
    item = 2294,
    price = 1
}

function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    if player:hasLearnedSpell(c.spellName) then
        player:sendCancelMessage("You already have this spell.")
        return true
    end

    local tokenCount = player:getItemCount(c.item)
    if tokenCount and tokenCount >= c.price then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough tokens.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end

    player:learnSpell(c.spellName)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You buy %s for %s tokens.", c.spellName, c.price))
    fromPosition:sendMagicEffect(CONST_ME_HEARTS)
    local tokens = player:getItemById(c.item)
    tokens:remove(c.price)
    return true
end

testAction:aid(660) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed
Lua:
    local tokens = player:getItemById(c.item)
    tokens:remove(c.price)
Why this? xD
just do
Lua:
player:removeItem(itemId, count[, subType = -1[, ignoreEquipped = false]])
player:removeItem(c.item, c.price)
 
Tbh, my brain exploaded. I managed to get it to add the item and remove the item once but then it messed up so it just continued to do so even if you had no tokens..
I've been doing this for an hour now and Idk.. xD
Let's just make it do an item, so removing the spell.
Lua:
-- Script by Klonera/Joriku
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)
local c = {
    tokenId = 9020,
    itemid = 2294,
    price = 1
}

function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    print("Test Script Loaded In Successfully.")
    local tokenCost = player:getItemById(c.tokenId)
    if tokenCost < c.price then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough money.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end
        
    if tokenCost >= c.price then
        player:addItem(c.itemid)
        player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You buy %s for %s gold coins.", ItemType(c.itemid):getName(), c.price))
        fromPosition:sendMagicEffect(CONST_ME_HEARTS)
        player:removeItem(c.tokenId, .price)
        return true
    end            
    print("Test Script Ended Successfully.")
    return true
end

testAction:aid(661) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed

Then another question after this one is solved,
how would it be done if we take cost of a table like premium_points?
 
Tbh, my brain exploaded. I managed to get it to add the item and remove the item once but then it messed up so it just continued to do so even if you had no tokens..
I've been doing this for an hour now and Idk.. xD
Let's just make it do an item, so removing the spell.
Lua:
-- Script by Klonera/Joriku
local testAction = Action() -- this is our header, the first thing we have to write (except for configuration tables and such)
local c = {
    tokenId = 9020,
    itemid = 2294,
    price = 1
}

function testAction.onUse(player, item, fromPosition, target, toPosition, isHotkey) -- now we can design the action itself
    print("Test Script Loaded In Successfully.")
    local tokenCost = player:getItemById(c.tokenId)
    if tokenCost < c.price then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have enough money.")
        fromPosition:sendMagicEffect(CONST_ME_POFF)
        return true
    end
       
    if tokenCost >= c.price then
        player:addItem(c.itemid)
        player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You buy %s for %s gold coins.", ItemType(c.itemid):getName(), c.price))
        fromPosition:sendMagicEffect(CONST_ME_HEARTS)
        player:removeItem(c.tokenId, .price)
        return true
    end           
    print("Test Script Ended Successfully.")
    return true
end

testAction:aid(661) -- the item is a scythe
testAction:register() -- this is our footer, it has to be the last function executed

Then another question after this one is solved,
how would it be done if we take cost of a table like premium_points?
line 11 is wrong. should use getItemCount instead.
line 22 .price should be c.price

additionally, remove lines 18, 23, 24 as they are currently serving no purpose.
 
how would it be done if we take cost of a table like premium_points?
by executing the following query:
Get premium points: (maybe there's already a method for this somewhere 🤔 )
Lua:
local resultId = db.query('SELECT `premium_points` FROM `accounts` WHERE `id` = ' .. player:getAccountId())
if resultId then
    local points = result.getNumber(resultId, 'premium_points')
    -- do something with points
    result.free(resultId)
end


Remove premium points:
Lua:
db.query('UPDATE `accounts` SET `premium_points` = `premium_points` - '.. c.price ..' WHERE `id` = '.. player:getAccountId())
 
line 11 is wrong. should use getItemCount instead.
line 22 .price should be c.price

additionally, remove lines 18, 23, 24 as they are currently serving no purpose.
What would I do without you?
by executing the following query:
Get premium points: (maybe there's already a method for this somewhere 🤔 )
Lua:
local resultId = db.query('SELECT `premium_points` FROM `accounts` WHERE `id` = ' .. player:getAccountId())
if resultId then
    local points = result.getNumber(resultId, 'premium_points')
    -- do something with points
    result.free(resultId)
end


Remove premium points:
Lua:
db.query('UPDATE `accounts` SET `premium_points` = `premium_points` - '.. c.price ..' WHERE `id` = '.. player:getAccountId())
Thank you, will try to do something with this. Appreciate all the help<3


BTW: Xikini finished my request, will mark it as solved later.
Might come up something else, will post it up in this one aswell to avoid more spam. Hope that's alright


Also: Now when it comes to revscripts, is it possible to log the errors of a purchase that went wrong? Like if it doesn't give it out or just crashes?
 
Back
Top