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

Multi In-game store configuration

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,107
Solutions
15
Reaction score
393
Location
Sweden
YouTube
Joriku
Joriku submitted a new resource:

Multi In-game store configuration - ingame-store

Today I am releasing an updated version for in-game stores that takes the player's bank balance, verifying it. This script allows you to have any game store in one configuration by using aid's and a simple configuration method.

View attachment 84855

Lua:
-- Version 1.0
-- Script made by Joriku, or Joelslamospersson at github.
local thaisdiamond = Action()

function thaisdiamond.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local...

Read more about this resource...
 
Nice!
Btw you don't need to check if player has money because removeMoney function will do that alredy :D
Here you can see how you could make it even easier with a simple config :D

Lua:
-- Version 1.0
-- Simple all-in-one configuration store
local thaisdiamond = Action()

local config = {
    [31063] = {totalCost = 100000, rewardItemId = 2496, rewardAmount = 100},
    [31021] = {totalCost = 60000, rewardItemId = 3155, rewardAmount = 1},
}

function thaisdiamond.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local buyItem = config[item:getActionId()]
    if not buyItem then
        return true
    end
    if player:removeMoney(buyItem.totalCost) then -- Make sure money is removed from player
        player:addItem(buyItem.rewardItemId, buyItem.rewardAmount)
        player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have successfully purchased " .. buyItem.rewardAmount .. " amount of " .. ItemType(buyItem.rewardItemId):getName() .. " for " .. buyItem.totalCost .. " gold.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have enough money to complete this purchase. You need at least " .. buyItem.totalCost .. " gold.")
    end
    -- Handle item transformation based on current state
    if item:getId() == 1945 then -- Lever ID 1
        item:transform(1946) -- Lever ID 2
    elseif item:getId() == 1945 then -- Lever ID 1
        item:transform(1945) -- Lever ID 2
    end
    return true
end

for x, y in pairs(config) do
    thaisdiamond:aid(x) -- Register the action id of lever used
end
thaisdiamond:register()
 
Last edited:
Nice!
Btw you don't need to check if player has money because removeMoney function will do that alredy :D
Here you can see how you could make it even easier with a simple config :D

Lua:
-- Version 1.0
-- Simple all-in-one configuration store
local thaisdiamond = Action()

local config = {
    [31063] = {totalCost = 100000, rewardItemId = 2496, rewardAmount = 100},
    [31021] = {totalCost = 60000, rewardItemId = 3155, rewardAmount = 1},
}

function thaisdiamond.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local buyItem = config[item:getActionId()]
    if not buyItem then
        return true
    end
    if player:removeMoney(buyItem.totalCost) then -- Make sure money is removed from player
        player:addItem(buyItem.rewardItemId, buyItem.rewardAmount)
        player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have successfully purchased " .. buyItem.rewardAmount .. " amount of " .. ItemType(buyItem.rewardItemId):getName() .. " for " .. buyItem.totalCost .. " gold.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have enough money to complete this purchase. You need at least " .. buyItem.totalCost .. " gold.")
    end
    -- Handle item transformation based on current state
    if item:getId() == 1945 then -- Lever ID 1
        item:transform(1946) -- Lever ID 2
    elseif item:getId() == 1945 then -- Lever ID 1
        item:transform(1945) -- Lever ID 2
    end
    return true
end

for x, y in pairs(config) do
    thaisdiamond:aid(x) -- Register the action id of lever used
end
thaisdiamond:register()
Thank you, will take the configuration with me for the future. Started using that kind of config for newer scripts with more complex handling for easier handle.

The reason I got a check is to avoid any issues with custom currencies (in my case),
so It firstly checks the currecy if it's valid, then removes the money and checks if the money was removed. This is for effciency and safety. So unless you're a 100% sure that it will and can't change in rapid enviroments (Lots of actions occuring, does not only have to be the script (If I am right), you'll be fine but this is just a good check for safety and working purposes to validate the actions.
 
Back
Top