Jump to content

Vehicle Shop HELP!


Xwad

Recommended Posts

Hi i made a vehicle shop script for my server but i have 2 problems: when i buy the vehicle then the vehicle always falls on me and i die.. How can i make that when i buy the vehicle then the script takes me in the car? another problem is that the script dosent take the money when i buy the vehicle! here is a part of the script:

function vehicleFBITruck( player ) 
if source == vehicleFBITruck then 
triggerServerEvent("vehFBITruck",localPlayer) 
guiSetVisible(vehicleGUI,false) 
showCursor( false ) 
outputChatBox("You have bought Sd.Kfz.222 vehicle.",source) 
   if ( getPlayerMoney (source) >= 3000 ) then 
    takePlayerMoney(source, 3000) 
else 
outputChatBox('You don\'t have enough money to buy this Vehicle.', source, 255, 0, 0 ) 
end 
end 
end  
end 
end) 
addEventHandler("onClientGUIClick",getRootElement(),vehicleFBITruck) 

Edited by Guest
Link to comment

is your cods

function vehicleFBITruck( player ) 
if source == vehicleFBITruck then 
triggerServerEvent("vehFBITruck",localPlayer) 
guiSetVisible(vehicleGUI,false) 
showCursor( false ) 
outputChatBox("You have bought Sd.Kfz.222 vehicle.",source) 
if ( getPlayerMoney (source) >= 3000 ) then 
takePlayerMoney(source, 3000) 
else 
outputChatBox('You don\'t have enough money to buy this Vehicle.', source, 255, 0, 0 ) 
end 
end 
end  
end 
end) 
addEventHandler("onClientGUIClick",getRootElement(),vehicleFBITruck) 

Link to comment

??? this is the full code

s_vehicle.lua

function vehicleBlips() 
vehBlipOne = createBlip(-2404.1486816406, -2201.865234375, 32.2,55) 
end 
addEventHandler("onResourceStart",getRootElement(),vehicleBlips) 
  
function vehicleRhino( player ) 
local x, y, z = getElementPosition ( source ) 
createVehicle ( 432, x, y, z + 5 ) 
end  
addEvent("vehRhino",true) 
addEventHandler("vehRhino",root,vehicleRhino) 
  
function vehicleFBITruck( player ) 
local x, y, z = getElementPosition ( source ) 
createVehicle ( 528, x, y, z + 5 ) 
end  
addEvent("vehFBITruck",true) 
addEventHandler("vehFBITruck",root,vehicleFBITruck) 
  
function vehicleFlatbed( player ) 
local x, y, z = getElementPosition ( source ) 
createVehicle ( 455, x, y, z + 5 ) 
end  
addEvent("vehFlatbed",true) 
addEventHandler("vehFlatbed",root,vehicleFlatbed) 
  
function vehiclePatriot( player ) 
local x, y, z = getElementPosition ( source ) 
createVehicle ( 470, x, y, z + 5 ) 
end  
addEvent("vehPatriot",true) 
addEventHandler("vehPatriot",root,vehiclePatriot) 
  
  
  
  
  
c_vehicle.lua 
  
  
  
--[[ 
This script was created by FlowZ and all credits go to FlowZ, if you need any help setting up this script 
head to readme.txt for more instruction. 
]]-- 
  
local vehicleMarker = createMarker(-2404.1486816406, -2201.865234375, 32.2,"cylinder",1,255,255,255) 
  
function vehicleGUI() 
vehicleGUI = guiCreateWindow(277, 204, 269, 266, "Vehicle Shop", false) 
guiWindowSetSizable(vehicleGUI, false) 
  
vehicleRhino = guiCreateButton(9, 20, 250, 40, "Tiger Ausf. E", false, vehicleGUI) 
vehicleFBITruck = guiCreateButton(9, 69, 250, 40, "Sd.Kfz.222", false, vehicleGUI) 
vehicleFlatbed = guiCreateButton(9, 120, 250, 40, "Sd Kfz 251", false, vehicleGUI) 
vehiclePatriot = guiCreateButton(9, 170, 250, 40, "German staff car", false, vehicleGUI) 
vehicleClose = guiCreateButton(178, 218, 81, 27, "Close", false, vehicleGUI)     
  
if source == vehicleMarker then 
guiSetVisible(vehicleGUI, true) 
showCursor( true ) 
   end 
end 
addEventHandler("onClientMarkerHit",getRootElement(),vehicleGUI) 
  
function vehicleClose() 
if source == vehicleClose then 
guiSetVisible(vehicleGUI,false) 
showCursor(false) 
end 
end 
addEventHandler("onClientGUIClick",getRootElement(),vehicleClose) 
  
function vehicleRhino( player ) 
if source == vehicleRhino then 
triggerServerEvent("vehRhino", localPlayer) 
guiSetVisible(vehicleGUI,false) 
showCursor(false) 
outputChatBox("You have bought a Tiger Ausf. E tank.",source) 
end  
end 
addEventHandler("onClientGUIClick",getRootElement(),vehicleRhino) 
  
function vehicleFBITruck( player ) 
if source == vehicleFBITruck then 
triggerServerEvent("vehFBITruck",localPlayer) 
guiSetVisible(vehicleGUI,false) 
showCursor( false ) 
outputChatBox("You have bought Sd.Kfz.222 vehicle.",source) 
end  
end 
addEventHandler("onClientGUIClick",getRootElement(),vehicleFBITruck) 
  
function vehicleFlatbed( player ) 
if source == vehicleFlatbed then 
triggerServerEvent("vehFlatbed",localPlayer) 
guiSetVisible(vehicleGUI,false) 
showCursor( false ) 
outputChatBox("You have Bought a German Sd Kfz 251 vehicle.",source) 
end  
end 
addEventHandler("onClientGUIClick",getRootElement(),vehicleFlatbed) 
  
function vehiclePatriot( player ) 
if source == vehiclePatriot then 
triggerServerEvent("vehPatriot",localPlayer) 
guiSetVisible(vehicleGUI,false) 
showCursor( false ) 
outputChatBox("You have bought a german staff car.",source) 
end  
end 
addEventHandler("onClientGUIClick",getRootElement(),vehiclePatriot) 

Link to comment

not working:/ But im Sure that i have do something worng in this part of the script

function vehicleFBITruck( player ) 
if source == vehicleFBITruck then 
triggerServerEvent("vehFBITruck",localPlayer) 
guiSetVisible(vehicleGUI,false) 
showCursor( false ) 
outputChatBox("You have bought Sd.Kfz.222 vehicle.",source) 
if ( getPlayerMoney (source) >= 3000 ) then 
takePlayerMoney(source, 3000) 
else 
outputChatBox('You don't have enough money to buy this Vehicle.', source, 255, 0, 0 ) 
end 
end 
end 
end 
end) 
addEventHandler("onClientGUIClick",getRootElement(),vehicleFBITruck) 
 

Edited by Guest
Link to comment
---SERVER-SIDE 
function vehicleFBITruck() 
if ( getPlayerMoney (source) >= 3000 ) then 
takePlayerMoney(source, 3000) 
outputChatBox("You have bought Sd.Kfz.222 vehicle.",source) 
else 
outputChatBox('You dont have enough money to buy this Vehicle.', source, 255, 0, 0 ) 
end 
end) 
addEvent("onVehicleBought", true) 
addEventHandler("onVehicleBought", getRootElement(), vehicleFBITruck) 

---CLIENT-SIDE 
triggerServerEvent("onVehicleBought", localPlayer) 

the rest you must add it.

Link to comment

i made the script but it does not work. The server sad : ERROR: Client (Xwad) triggered serverside event onVehicleBought, but event is not added serverside

This is the 2 code:

C_vehicle.lua

  
local vehicleMarker = createMarker(-2404.1486816406, -2201.865234375, 32.2,"cylinder",1,255,255,255) 
  
function vehicleGUI() 
vehicleGUI = guiCreateWindow(277, 204, 269, 266, "Vehicle Shop", false) 
guiWindowSetSizable(vehicleGUI, false) 
  
  
vehicleFBITruck = guiCreateButton(9, 69, 250, 40, "Sd.Kfz.222", false, vehicleGUI) 
vehicleClose = guiCreateButton(178, 218, 81, 27, "Close", false, vehicleGUI)     
  
if source == vehicleMarker then 
guiSetVisible(vehicleGUI, true) 
showCursor( true ) 
   end 
end 
addEventHandler("onClientMarkerHit",getRootElement(),vehicleGUI) 
  
function vehicleClose() 
if source == vehicleClose then 
guiSetVisible(vehicleGUI,false) 
showCursor(false) 
end 
end 
addEventHandler("onClientGUIClick",getRootElement(),vehicleClose) 
  
function vehicleFBITruck( player ) 
if source == vehicleFBITruck then 
triggerServerEvent("onVehicleBought",localPlayer) 
guiSetVisible(vehicleGUI,false) 
showCursor( false ) 
outputChatBox("You have bought Sd.Kfz.222 vehicle.",source) 
end 
end 
addEventHandler("onClientGUIClick",getRootElement(),vehicleFBITruck) 
  

s_vehicle

  
function vehicleFBITruck() 
if ( getPlayerMoney (source) >= 3000 ) then 
takePlayerMoney(source, 3000) 
outputChatBox("You have bought Sd.Kfz.222 vehicle.",source) 
else 
outputChatBox('You dont have enough money to buy this Vehicle.', source, 255, 0, 0 ) 
end 
end) 
addEvent("onVehicleBought", true) 
addEventHandler("onVehicleBought", getRootElement(), vehicleFBITruck) 
  

Link to comment

client.lua

  
local vehicleMarker = createMarker(-2404.1486816406, -2201.865234375, 32.2,"cylinder",1,255,255,255) 
  
function vehicleGUI() 
vehicleGUI = guiCreateWindow(277, 204, 269, 266, "Vehicle Shop", false) 
guiWindowSetSizable(vehicleGUI, false) 
guiSetVisible(vehicleGUI,false) 
  
  
vehicleFBITruck = guiCreateButton(9, 69, 250, 40, "Sd.Kfz.222", false, vehicleGUI) 
vehicleClose = guiCreateButton(178, 218, 81, 27, "Close", false, vehicleGUI)     
  
end 
addEventHandler("onClientResourceStart",resourceRoot,vehicleGUI) 
  
function playerOnMarker() 
if isElementWithinMarker(localPlayer, vehicleMarker) then 
guiSetVisible(vehicleGUI, true) 
showCursor( true ) 
   end 
end 
addEventHandler("onClientMarkerHit", vehicleMarker, playerOnMarker) 
  
  
function closeGUI() 
if source == vehicleClose then 
guiSetVisible(vehicleGUI,false) 
showCursor(false) 
end 
end 
addEventHandler("onClientGUIClick",getRootElement(),closeGUI) 
  
  
function vehicleBuy() 
if source == vehicleFBITruck then 
triggerServerEvent("onVehicleBought",localPlayer) 
guiSetVisible(vehicleGUI,false) 
showCursor( false ) 
end 
end 
addEventHandler("onClientGUIClick",getRootElement(),vehicleBuy) 
  

Link to comment
  
local vehicleMarker = createMarker(-2404.1486816406, -2201.865234375, 32.2,"cylinder",1,255,255,255) 
  
function vehicleGUI() 
vehicleGUI = guiCreateWindow(277, 204, 269, 266, "Vehicle Shop", false) 
guiWindowSetSizable(vehicleGUI, false) 
guiSetVisible(vehicleGUI,false) 
  
  
vehicleFBITruck = guiCreateButton(9, 69, 250, 40, "Sd.Kfz.222", false, vehicleGUI) 
vehicleClose = guiCreateButton(178, 218, 81, 27, "Close", false, vehicleGUI)     
  
end 
addEventHandler("onClientResourceStart",resourceRoot,vehicleGUI) 
  
function playerOnMarker() 
if isElementWithinMarker(localPlayer, vehicleMarker) then 
guiSetVisible(vehicleGUI, true) 
showCursor( true ) 
   end 
end 
addEventHandler("onClientMarkerHit", vehicleMarker, playerOnMarker) 
  
  
function closeGUI() 
if source == vehicleClose then 
guiSetVisible(vehicleGUI,false) 
showCursor(false) 
end 
end 
addEventHandler("onClientGUIClick",getRootElement(),closeGUI) 
  
  
function vehicleBuy() 
if source == vehicleFBITruck then 
triggerServerEvent("onVehicleBought",localPlayer) 
guiSetVisible(vehicleGUI,false) 
showCursor( false ) 
end 
end 
addEventHandler("onClientGUIClick",getRootElement(),vehicleBuy) 
  

Link to comment

clientside works perfectly

server-side

function vehicleFBITruck() 
if ( getPlayerMoney (source) >= 3000 ) then 
takePlayerMoney(source, 3000) 
outputChatBox("You have bought Sd.Kfz.222 vehicle.",source) 
else 
outputChatBox('You dont have enough money to buy this Vehicle.', source, 255, 0, 0 ) 
end 
end 
addEvent("onVehicleBought", true) 
addEventHandler("onVehicleBought", getRootElement(), vehicleFBITruck) 

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