Jump to content

[Help] Bug in Spin Recource


BieHDC

Recommended Posts

Hello,

i have an epic bug in the following code, if you spin for a negative ammount of money and loose you get money.

but i cant find out how to fix, so please hel me

thanks

function Spin_Func(thePlayer, cmd, amount) 
    local winchance = math.random(1,3) 
    local spintimer = getElementData(thePlayer,"spintimer") 
    local money = getPlayerMoney(thePlayer) 
    if spintimer == false then 
        if (money >= tonumber(amount)) then 
            if winchance == 1 or winnchance == 3 then 
                outputChatBox("#ffffff"..getPlayerName(thePlayer).." spinned for "..amount.." and lost.", getRootElement(),0,0,0,true) 
                takePlayerMoney(thePlayer,amount) 
                setElementData(thePlayer,"spintimer", true) 
                setTimer( function () setElementData(thePlayer,"spintimer", false) 
                end, 30000,1) 
            elseif winchance == 2 then 
                outputChatBox("#ffffff"..getPlayerName(thePlayer).." spinned for "..amount.."$ and won ".. amount*2 .."$.", getRootElement(),0,0,0,true) 
                givePlayerMoney(thePlayer, amount) 
                setElementData(thePlayer,"spintimer", true) 
                setTimer( function () setElementData(thePlayer,"spintimer", false) 
                end, 30000,1) 
            end 
        else 
            outputChatBox("You don't have enough money!", thePlayer, 255,0,0) 
        end 
    else 
        outputChatBox("You can spin only all 30 Seconds.",thePlayer, 255,0,0) 
    end 
end 
addCommandHandler("spin", Spin_Func) 

Link to comment
function Spin_Func ( thePlayer, cmd, amount ) 
    local winchance = math.random ( 1, 3 ) 
    local spintimer = getElementData ( thePlayer, "spintimer" ) 
    local money = getPlayerMoney ( thePlayer ) 
    local amount = tonumber ( amount ) or 0 
    if ( amount < 1 ) then 
        outputChatBox ( "Invalid amount.", thePlayer, 255, 0, 0 ) 
        return 
    end 
  
    if ( spintimer == false ) then 
        if ( money >= amount ) then 
            if ( winchance == 1 or winnchance == 3 ) then 
                outputChatBox ( "#ffffff"..getPlayerName ( thePlayer ) .." spinned for ".. amount .." and lost.", root, 0, 0, 0, true ) 
                takePlayerMoney ( thePlayer, amount ) 
                setElementData ( thePlayer, "spintimer", true ) 
                setTimer ( 
                    function ( ) 
                        setElementData ( thePlayer, "spintimer", false ) 
                    end 
                    ,30000, 1 
                ) 
            elseif ( winchance == 2 ) then 
                outputChatBox ( "#ffffff".. getPlayerName ( thePlayer ) .." spinned for ".. amount .."$ and won ".. ( amount * 2 ) .."$.", root, 0, 0, 0, true ) 
                givePlayerMoney ( thePlayer, amount ) 
                setElementData ( thePlayer, "spintimer", true ) 
                setTimer ( 
                    function ( ) 
                        setElementData ( thePlayer, "spintimer", false ) 
                    end 
                    ,30000, 1 
                ) 
            end 
        else 
            outputChatBox ( "You don't have enough money!", thePlayer, 255, 0, 0 ) 
        end 
    else 
        outputChatBox ( "You can spin only all 30 Seconds.", thePlayer, 255, 0, 0 ) 
    end 
end 
addCommandHandler ( "spin", Spin_Func ) 

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...