Jump to content

Buy Weapon/Bullets


yMassai

Recommended Posts

          local price_m4          = 18000 
          local bullet_m4          = 300 
  
function BuyWeaponOnServer(weapon_name) 
  
    player_money      = getPlayerMoney(source) 
    player_account    = getPlayerAccount(source) 
  
    if (getAccountData(player_account, "GunLicense")) then             
        if(weapon_name == "weapon_m4") then 
            if(player_money >= price_m4) then 
            takePlayerMoney(source, price_m4) 
            setAccountData(player_account, "m4data", true) 
                if(not getAccountData(player_account, "m4data")) then 
                return               
                    if(player_money >= bullet_m4) then 
                        giveWeapon(source, 31, 50) 
                        takePlayerMoney(source, bullet_m4) 
                    outputChatBox("Você comprou uma M4.", source, 0, 255, 0) 
                else 
                    outputChatBox("Você não tem dinheiro para comprar uma M4.", source, 255, 0, 0) 
                end 
            end 
        end 
end 
addEvent("onClientBuyWeapon", true) 
addEventHandler("onClientBuyWeapon", getRootElement(), BuyWeaponOnServer) 
  
function BuyWeaponLicense() 
     
    player_money = getPlayerMoney(source) 
    player_account = getPlayerAccount(source) 
     
    local license_price = 55000 
     
    if(not getAccountData(player_account, "GunLicense")) then 
        if(player_money >= license_price) then 
            setAccountData(player_account, "GunLicense", true) 
            takePlayerMoney(source, license_price) 
            outputChatBox("Agora você tem uma Licença para portar Armas!", source, 0, 255, 0) 
        else 
            outputChatBox("Você não tem dinheiro pra comprar a Licença!", source, 255, 0, 0) 
        end 
    else 
        outputChatBox("Você já tem uma licença para portar Armas!", source, 255, 0, 0) 
    end 
     
end 
addEvent("onClientBuyLicense", true) 
addEventHandler("onClientBuyLicense", getRootElement(), BuyWeaponLicense) 

I wanted the player buy the license, then the gun and after bullets.

Link to comment

You seem to have problem with code indentation. Indent your code properly and you'll find your problem, also check debugscript window to trace your errors. You haven't even explained what your problem is.

Link to comment
local aPrices = 
{ 
    ['M4'] = 18000, 
    ['Ammo M4'] = 300, 
    ['License'] = 55000; 
} 
  
addEvent( 'onClientBuyWeapon', true ); 
addEvent( 'onClientBuyLicense', true ); 
  
addEventHandler( 'onClientBuyWeapon', root, 
    function( sWeapon ) 
        local pAccount = getPlayerAccount( source ); -- is source defined? 
        local nMoney = getPlayerMoney( source ); -- is source defined? 
         
        if( getAccountData( pAccount, 'GunLicense' ) ) then 
            if( sWeapon == 'weapon_m4' ) then 
                if( nMoney >= ( aPrices['M4'] + aPrices['Ammo M4'] ) ) then 
                    takePlayerMoney( source, aPrices['M4'] + aPrices['Ammo M4'] ); 
                    setAccountData( pAccount, 'm4data', true ); 
                    giveWeapon( source, 31, 50 ); 
                    outputChatBox( 'Você comprou uma M4!', source, 0, 255, 0, false ); 
                else 
                    outputChatBox( 'Você não tem dinheiro para comprar uma M4!', source, 255, 0, 0, false ); 
                end 
            end 
        else 
            outputChatBox( 'Você não tem licença de arma!', source, 255, 0, 0, false ); 
        end 
    end 
) 
  
addEventHandler( 'onClientBuyLicense', root, 
    function( ) 
        local pAccount = getPlayerAccount( source ); 
        local nMoney = getPlayerMoney( source ); 
         
        if( not getAccountData( pAccount, 'GunLicense' ) ) then 
            if( nMoney >= aPrices['License'] ) then 
                setAccountData( pAccount, 'GunLicense', true ); 
                takePlayerMoney( source, aPrices['License'] ); 
                outputChatBox( 'Você comprou uma licença para portar armas!', source, 0, 255, 0, false ); 
            else 
                outputChatBox( 'Você não tem grana suficiente para comprar a licença!', source, 255, 0, 0, false ); 
            end 
        else 
            outputChatBox( 'Você já tem uma licença para portar armas!', source, 255, 0, 0, false ); 
        end 
    end 
) 

The problem: You forgot an '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...