Jump to content

[HELP] Lucky thing


LabiVila

Recommended Posts

  
--server 
function allW (source) 
    triggerClientEvent (source, "passM") 
    givePlayerMoney (source, 10) 
end 
addEventHandler ("onClientResourceStart", getRootElement(), allW) 
  
function takeMoney (source) 
    local money = getPlayerMoney (source) 
    if (money > 500) then 
        triggerClientEvent ("parted", true) 
        takePlayeMoney (source, 500) 
    else 
        triggerClientEvent ("notparted", true) 
    end 
end 
addCommandHandler ("par", takeMoney) 
  
--client 
function passMessage () 
    setTimer (outputChatBox, 5000, 0, "* 5000$ will be given away randomly, participate by writing /par.", 255, 255, 255, root) 
end 
addEvent ("passM", true) 
addEventHandler ("onClientResourceStart", getRootElement(), passMessage) 
  
function participating ()    
    triggerServerEvent ("money", true) 
end 
addCommandHandler ("par", participating) 
  
function participated () 
    outputChatBox ("You participated") 
end 
addEvent ("parted", participated) 
  
  
function notParticipated () 
    outputChatBox ("Failed") 
end 
addEvent ("notparted", notParticipated) 
  

not sure what's not working, can you help me a bit?

Link to comment

I've written this script for you fast. Please look at the comments and change the values and also change the outputChatBox texts. This script is untested but shouldn't have any error

local par = { } 
local running = false 
  
function startGiveaway() 
    if running ~= true then 
        running = true 
        outputChatBox("Tell the players here, that the giveaway has started, the amount to win and how to participate", root, 255, 255, 255) 
        setTimer(function () 
            local randomWinner = par[math.random(#par)] 
            if randomWinner then 
                outputChatBox(("%s has won!"):format(getPlayerName(randomWinner)), root, 255, 255, 255) 
                givePlayerMoney(randomWinner, 0) -- change the 0 to an amount you like 
                running = false 
                for index, p in ipairs(par) do  
                    table.remove(par, index) 
                end 
            end 
        end, 0, 1) -- 0 = time in ms (1000 ms = 1 second); change the 0 to a value you like 
    end 
end 
  
-- Server 
addEventHandler("onResourceStart", resourceRoot, 
function () 
    startGiveaway() 
end) 
  
addCommandHandler("par", 
function (player, cmd) 
    local money = getPlayerMoney(player) 
    if money >= 500 then 
        if not par[player] then 
            par[player] = true 
            takePlayerMoney(player, 500) 
            outputChatBox("Inform the player here, that he is participating in the giveaway", player, 255, 255, 255) 
        else 
            outputChatBox("Inform the player here, that he is already participating", player, 255, 255, 255) 
        end 
    else 
        outputChatBox("Tell the player here, that is money is not enough", player, 255, 255, 255) 
    end 
end) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...