Xwad Posted July 27, 2015 Share Posted July 27, 2015 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
HUNGRY:3 Posted July 27, 2015 Share Posted July 27, 2015 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
Xwad Posted July 27, 2015 Author Share Posted July 27, 2015 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
HUNGRY:3 Posted July 27, 2015 Share Posted July 27, 2015 you can't use getaccontdata,setaccountdata and warppedintovehicle in client side Link to comment
Xwad Posted July 27, 2015 Author Share Posted July 27, 2015 sorry its not client its server side:D Link to comment
Xwad Posted July 27, 2015 Author Share Posted July 27, 2015 ERROR loading script failed: Shop/server.lua:51:'end' expected (to close 'if' at line 31)near 'elseif' Link to comment
HUNGRY:3 Posted July 27, 2015 Share Posted July 27, 2015 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
Xwad Posted July 28, 2015 Author Share Posted July 28, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now