Jump to content

Vehicle shop not working:/


Xwad

Recommended Posts

Hi i made a weapon shop for my server but isnt working..

Debugscript: ERROR loading script failed: Shop/server.lua:41:'end' expected (to close 'if' at line 15) near 'elseif'

here is a part of the script

server.lua

  
if(weapon_name == "weapon_plane") then 
                local USAteam = getTeamFromName("USA") 
                if (USAteam) then  
                if(player_money >= tonumber(price_plane)) then 
                takePlayerMoney(source, tonumber(price_plane)) 
                local x,y,z = getElementPosition(source) 
                local vehicle = createVehicle(476,-2117.46, -2340.69, 100 + 3) 
                warpPedIntoVehicle(source,vehicle) 
                fadeCamera(source, true) 
                setCameraTarget(source, source) 
                outputChatBox("You have bought a plane.", source, 0, 255, 0) 
                end 
            else 
                local Axisteam = getTeamFromName("Axis") 
                if (Axisteam) then  
                if(player_money >= tonumber(price_plane)) then 
                takePlayerMoney(source, tonumber(price_plane)) 
                local x,y,z = getElementPosition(source) 
                local vehicle = createVehicle(446,-2117.46, -2340.69, 100 + 3) 
                warpPedIntoVehicle(source,vehicle) 
                fadeCamera(source, true) 
                setCameraTarget(source, source) 
                outputChatBox("You have bought a plane.", source, 0, 255, 0) 
                end              
            else 
                outputChatBox("You do not have enough money to buy a plane.", source, 255, 0, 0) 
            end 
  

Link to comment
if(weapon_name == "weapon_plane") then 
                local USAteam = getTeamFromName("USA") 
                if (USAteam) then 
                if(player_money >= tonumber(price_plane)) then 
                takePlayerMoney(source, tonumber(price_plane)) 
                local x,y,z = getElementPosition(source) 
                local vehicle = createVehicle(476,-2117.46, -2340.69, 100 + 3) 
                warpPedIntoVehicle(source,vehicle) 
                fadeCamera(source, true) 
                setCameraTarget(source, source) 
                outputChatBox("You have bought a plane.", source, 0, 255, 0) 
                end 
            else 
                local Axisteam = getTeamFromName("Axis") 
                if (Axisteam) then 
                if(player_money >= tonumber(price_plane)) then 
                takePlayerMoney(source, tonumber(price_plane)) 
                local x,y,z = getElementPosition(source) 
                local vehicle = createVehicle(446,-2117.46, -2340.69, 100 + 3) 
                warpPedIntoVehicle(source,vehicle) 
                fadeCamera(source, true) 
                setCameraTarget(source, source) 
                outputChatBox("You have bought a plane.", source, 0, 255, 0) 
                end             
            else 
                outputChatBox("You do not have enough money to buy a plane.", source, 255, 0, 0) 
            end 
            end 
            end 

Link to comment

here ios the full client side script :

  
function BuyWeaponOnServer(weapon_name) 
  
    player_money      = getPlayerMoney(source) 
    player_account    = getPlayerAccount(source) 
  
    local price_plane       = "5000" 
     
    if(getAccountData(player_account, "GunLicense") == true) then 
     
            if(weapon_name == "weapon_plane") then 
                local USAteam = getTeamFromName("USA") 
                if (USAteam) then 
                if(player_money >= tonumber(price_plane)) then 
                takePlayerMoney(source, tonumber(price_plane)) 
                local x,y,z = getElementPosition(source) 
                local vehicle = createVehicle(476,-2117.46, -2340.69, 100 + 3) 
                warpPedIntoVehicle(source,vehicle) 
                fadeCamera(source, true) 
                setCameraTarget(source, source) 
                outputChatBox("You have bought a plane.", source, 0, 255, 0) 
                end 
            else 
                local Axisteam = getTeamFromName("Axis") 
                if (Axisteam) then 
                if(player_money >= tonumber(price_plane)) then 
                takePlayerMoney(source, tonumber(price_plane)) 
                local x,y,z = getElementPosition(source) 
                local vehicle = createVehicle(446,-2117.46, -2340.69, 100 + 3) 
                warpPedIntoVehicle(source,vehicle) 
                fadeCamera(source, true) 
                setCameraTarget(source, source) 
                outputChatBox("You have bought a plane.", source, 0, 255, 0) 
                end             
            else 
                outputChatBox("You do not have enough money to buy a plane.", source, 255, 0, 0) 
            end 
            end 
            end 
         
    else 
        outputChatBox("You dont have a license to buy arms.", source, 255, 0, 0) 
    end 
  
end 
addEvent("onClientBuyWeapon", true) 
addEventHandler("onClientBuyWeapon", getRootElement(), BuyWeaponOnServer) 
  
  
  
function BuyWeaponLicense() 
     
    player_money = getPlayerMoney(source) 
    player_account = getPlayerAccount(source) 
     
    local license_price = "55000" 
     
    if(getAccountData(player_account, "GunLicense") == false) then 
        if(player_money >= tonumber(license_price)) then 
            setAccountData(player_account, "GunLicense", true) 
            takePlayerMoney(source, tonumber(license_price)) 
            outputChatBox("Now you have a license for arms.", source, 0, 255, 0) 
        else 
            outputChatBox("You do not have enough money to buy a license for arms.", source, 255, 0, 0) 
        end 
    else 
        outputChatBox("You already have a license for arms.", source, 255, 0, 0) 
    end 
     
end 
addEvent("onClientBuyLicense", true) 
addEventHandler("onClientBuyLicense", getRootElement(), BuyWeaponLicense) 
  

Link to comment

EDIT: just tested it try this

  
function BuyWeaponOnServer(weapon_name) 
  
    player_money      = getPlayerMoney(source) 
    player_account    = getPlayerAccount(source) 
  
    local price_plane       = "5000" 
    
    if(getAccountData(player_account, "GunLicense") == true) then 
    
            if(weapon_name == "weapon_plane") then 
                local USAteam = getTeamFromName("USA") 
                if (USAteam) then 
                if(player_money >= tonumber(price_plane)) then 
                takePlayerMoney(source, tonumber(price_plane)) 
                local x,y,z = getElementPosition(source) 
                local vehicle = createVehicle(476,-2117.46, -2340.69, 100 + 3) 
                warpPedIntoVehicle(source,vehicle) 
                fadeCamera(source, true) 
                setCameraTarget(source, source) 
                outputChatBox("You have bought a plane.", source, 0, 255, 0) 
                end 
            else 
                local Axisteam = getTeamFromName("Axis") 
                if (Axisteam) then 
                if(player_money >= tonumber(price_plane)) then 
                takePlayerMoney(source, tonumber(price_plane)) 
                local x,y,z = getElementPosition(source) 
                local vehicle = createVehicle(446,-2117.46, -2340.69, 100 + 3) 
                warpPedIntoVehicle(source,vehicle) 
                fadeCamera(source, true) 
                setCameraTarget(source, source) 
                outputChatBox("You have bought a plane.", source, 0, 255, 0)           
            else 
          outputChatBox("You do not have enough money to buy a plane.", source, 255, 0, 0) 
    end 
    else 
        outputChatBox("You dont have a license to buy arms.", source, 255, 0, 0) 
        end 
      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(getAccountData(player_account, "GunLicense") == false) then 
        if(player_money >= tonumber(license_price)) then 
            setAccountData(player_account, "GunLicense", true) 
            takePlayerMoney(source, tonumber(license_price)) 
            outputChatBox("Now you have a license for arms.", source, 0, 255, 0) 
        else 
            outputChatBox("You do not have enough money to buy a license for arms.", source, 255, 0, 0) 
    end 
    else 
        outputChatBox("You already have a license for arms.", source, 255, 0, 0) 
    end 
   end 
addEvent("onClientBuyLicense", true) 
addEventHandler("onClientBuyLicense", getRootElement(), BuyWeaponLicense) 
  
  

Link to comment

I etited the script a littlebit but its still not working.. I want to make that if a player source the plane then the script will give the plane by checking the players team. I mean if the player is in USA team then he will get the vehicle 476 and if he is in axis team then he will get the vehicle 446.

debugscript: ERROR (client) Xwad triggered server side event onClientBuyWeapon but event is not added to serverside

i dont know why is that i added the serverside event..

client

  
function CreateShopWindow() 
    ShopWindow = guiCreateWindow(175,150,450,320,"BONUS shop",false) 
  
     
        local price_porrete     = "5.000" 
  
        btn_buy_porrete = guiCreateButton(29,140,60,15,price_porrete,false,ShopWindow) 
         
        addEventHandler("onClientGUIClick", btn_buy_porrete, BuyWeapon) 
         
  
        guiCreateStaticImage(30,80,60,60,"images/3.png", false,ShopWindow ) 
         
  
    guiWindowSetSizable(ShopWindow,false) 
    guiSetVisible(ShopWindow,false) 
end 
addEventHandler("onClientResourceStart", getRootElement(), CreateShopWindow) 
  
  
  
  
function BuyWeapon(button, state) 
  
    if (button == "left") then 
     
        if(source == btn_buy_porrete) then 
            triggerServerEvent("onClientBuyWeapon", localPlayer, "weapon_porrete") 
        end 
     
    end 
end 
  
  
  
  
  
function ShowGUI ( ) 
    guiSetVisible ( ShopWindow, not guiGetVisible ( ShopWindow ) ) 
    showCursor ( not isCursorShowing( ) ) 
end 
bindKey ( "F2","down", ShowGUI )  
  

server

  
function BuyWeaponOnServer(weapon_name) 
  
    player_money      = getPlayerMoney(source) 
    player_account    = getPlayerAccount(source) 
  
    local price_porrete     = "2500" 
     
        if(weapon_name == "weapon_porrete") then 
                local USAteam = getTeamFromName("USA") 
                if (USAteam) then 
                if(player_money >= tonumber(price_porrete)) then 
                takePlayerMoney(source, tonumber(price_porrete)) 
                local x,y,z = getElementPosition(source) 
                local vehicle = createVehicle(476,-2117.46, -2340.69, 100 + 3) 
                warpPedIntoVehicle(source,vehicle) 
                outputChatBox("You have bought a plane.", source, 0, 255, 0) 
            else 
                local Axisteam = getTeamFromName("Axis") 
                if (Axisteam) then 
                if(player_money >= tonumber(price_porrete)) then 
                takePlayerMoney(source, tonumber(price_porrete)) 
                local x,y,z = getElementPosition(source) 
                local vehicle = createVehicle(446,-2117.46, -2340.69, 100 + 3) 
                warpPedIntoVehicle(source,vehicle) 
                outputChatBox("You have bought a plane.", source, 0, 255, 0)  
            else 
                outputChatBox("You dont have enough money to buy a plane.", source, 255, 0, 0) 
end 
end 
end 
addEvent("onClientBuyWeapon", true) 
addEventHandler("onClientBuyWeapon", getRootElement(), BuyWeaponOnServer) 
  
  

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