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

TalkAction Buy premium by modal window

ZeroSkyer

Member
Joined
May 17, 2019
Messages
62
Reaction score
9
Location
EEUU
I found this script I made a few months ago, it's not amazing the code but it works fine.
Lua:
function onSay(player, words, param)
    function Player:sendPremiumPacks()
    -- Modal Window Functionallity
    local function buttonAccept(button, choice)
        if choice.text == "Premium Days (15)" then
            player:Pack1()
        elseif choice.text == "Premium Days (30)" then
            player:Pack2()
        elseif choice.text == "Premium Days (60)" then
            player:Pack3()
        end   
    end
 
    -- Modal window design
    local window = ModalWindow {
        title = "Premium Account", -- Title of the modal window
        message = "Choose an option.", -- The message to be displayed on the modal window
    }
    
    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Ok", buttonAccept)
    window:addButton("Exit")

    -- Add Choices
    window:addChoice("Premium Days (15)")
    window:addChoice("Premium Days (30)")
    window:addChoice("Premium Days (60)")

    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Ok")
    window:setDefaultEscapeButton("Exit")
  
    -- Send the window to player
    window:sendToPlayer(self)
end


-- Premium Packs
function Player:FailedPurchase()
    -- Modal Window Functionality
    local function buttonAccept(button, choice)
        if button.text == "Back" then
            player:sendPremiumPacks()
        end
    end
    -- Modal window design
    local window = ModalWindow {
        title = "Purchase Failed", -- Title of the modal window
        message = "You do not have the money to make this purchase.", -- The message to be displayed on the modal window
    }
    
    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Back", buttonAccept)
    window:addButton("Exit")

    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Back")
    window:setDefaultEscapeButton("Exit")
  
    -- Send the window to player
    window:sendToPlayer(self)
end

-- Premium Packs
function Player:SuccessfulPurchase()
    -- Modal Window Functionality
    local function buttonAccept(button, choice)
        if button.text == "Back" then
            player:sendPremiumPacks()
        end
    end
    -- Modal window design
    local window = ModalWindow {
        title = "Successful Purchase", -- Title of the modal window
        message = "You have received " .. player:getStorageValue(ServerStorage.LastPremiumDays) .. " days premium and " .. player:getStorageValue(ServerStorage.LastLoyaltyPoints) .. " loyalty points. You need to reconnect.", -- The message to be displayed on the modal window
    }
    
    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Back", buttonAccept)
    window:addButton("Exit")

    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Back")
    window:setDefaultEscapeButton("Exit")
  
    -- Send the window to player
    window:sendToPlayer(self)
end

function Player:Pack1()
    -- Modal Window Functionallity
    local function buttonAccept(button, choice)
        if button.text == "Yes" then
            if player:getMoney() >= 15000000 then
                player:removeMoney(15000000)
                db.query('UPDATE accounts SET premdays = premdays+'.. 15 ..' WHERE id = ' .. player:getAccountId())
                player:addLoyaltyPoints(15)
                player:setStorageValue(ServerStorage.LastPremiumDays, 15)
                player:setStorageValue(ServerStorage.LastLoyaltyPoints, 15)
                player:getPosition():sendMagicEffect(28)
                player:SuccessfulPurchase()
            else
                player:FailedPurchase()
                player:getPosition():sendMagicEffect(CONST_ME_POFF)
            end
        elseif button.text == "Back" then
            player:sendPremiumPacks()
        end   
    end
 
    -- Modal window design
    local window = ModalWindow {
        title = "15 Premium Days", -- Title of the modal window
        message = "This will cost you 15,000,000 gold, do you want to buy?", -- The message to be displayed on the modal window
    }
    
    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Yes", buttonAccept)
    window:addButton("Back", buttonAccept)
    window:addButton("Cancel")

    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Yes")
    window:setDefaultEscapeButton("Cancel")
  
    -- Send the window to player
    window:sendToPlayer(self)
end

function Player:Pack2()
    -- Modal Window Functionallity
    local function buttonAccept(button, choice)
        if button.text == "Yes" then
            if player:getMoney() >= 30000000 then
                player:removeMoney(30000000)
                db.query('UPDATE accounts SET premdays = premdays+'.. 30 ..' WHERE id = ' .. player:getAccountId())
                player:addLoyaltyPoints(30)
                player:setStorageValue(ServerStorage.LastPremiumDays, 30)
                player:setStorageValue(ServerStorage.LastLoyaltyPoints, 30)
                player:SuccessfulPurchase()
                player:getPosition():sendMagicEffect(28)
            else
                player:FailedPurchase()
                player:getPosition():sendMagicEffect(CONST_ME_POFF)
            end
        elseif button.text == "Back" then
            player:sendPremiumPacks()
        end   
    end
 
    -- Modal window design
    local window = ModalWindow {
        title = "30 Premium Days", -- Title of the modal window
        message = "This will cost you 30,000,000 gold, do you want to buy?", -- The message to be displayed on the modal window
    }
    
    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Yes", buttonAccept)
    window:addButton("Back", buttonAccept)
    window:addButton("Cancel")

    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Yes")
    window:setDefaultEscapeButton("Cancel")
  
    -- Send the window to player
    window:sendToPlayer(self)
end

function Player:Pack3()
    -- Modal Window Functionallity
    local function buttonAccept(button, choice)
        if button.text == "Yes" then
            if player:getMoney() >= 60000000 then
                player:removeMoney(60000000)
                db.query('UPDATE accounts SET premdays = premdays+'.. 60 ..' WHERE id = ' .. player:getAccountId())
                player:addLoyaltyPoints(60)
                player:setStorageValue(ServerStorage.LastPremiumDays, 60)
                player:setStorageValue(ServerStorage.LastLoyaltyPoints, 60)
                player:SuccessfulPurchase()
                player:getPosition():sendMagicEffect(28)
            else
                player:FailedPurchase()
                player:getPosition():sendMagicEffect(CONST_ME_POFF)
            end
        elseif button.text == "Back" then
            player:sendPremiumPacks()
        end   
    end
 
    -- Modal window design
    local window = ModalWindow {
        title = "60 Premium Days", -- Title of the modal window
        message = "This will cost you 60,000,000 gold, do you want to buy?", -- The message to be displayed on the modal window
    }
    
    -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
    window:addButton("Yes", buttonAccept)
    window:addButton("Back", buttonAccept)
    window:addButton("Cancel")

    -- Set what button is pressed when the player presses enter or escape
    window:setDefaultEnterButton("Yes")
    window:setDefaultEscapeButton("Cancel")
  
    -- Send the window to player
    window:sendToPlayer(self)
end

player:sendPremiumPacks()

end
 
Back
Top