isa_Khamdan Posted August 11, 2013 Share Posted August 11, 2013 is it possible to use GiveVehicle without admin panel? like using it with command or something? Link to comment
tosfera Posted August 12, 2013 Share Posted August 12, 2013 There is, the thing you have to do is as following; -- get the player's location -- create the vehicle on the location and rotation (would be nice) -- warpPedIntoVehicle Thats all. Oh and you mind want to change the command to accept another argument; a vehicle ID. Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 There is, the thing you have to do is as following; -- get the player's location -- create the vehicle on the location and rotation (would be nice) -- warpPedIntoVehicle Thanks I will test it now Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 is this code correct? function createMyVehicle(vehicleid,x,y,z) -- check all the arguments exist if vehicleid and x and y and z then local Vehicle = createVehicle(vehicleid,x,y,z) warpPedIntoVehicle ( source, Vehicle ) end end Link to comment
tosfera Posted August 12, 2013 Share Posted August 12, 2013 It is but why do you want to type the coordinates. Just use; local x,y,z = getElementPosition( source ) Link to comment
DNL291 Posted August 12, 2013 Share Posted August 12, 2013 function createMyVehicle(thePlayer,vehicleid,x,y,z) -- check all the arguments exist if vehicleid and x and y and z then local Vehicle = createVehicle(vehicleid,x,y,z) warpPedIntoVehicle ( thePlayer, Vehicle ) end end Link to comment
tosfera Posted August 12, 2013 Share Posted August 12, 2013 function createMyVehicle(thePlayer,vehicleid,x,y,z) -- check all the arguments exist if vehicleid and x and y and z then local Vehicle = createVehicle(vehicleid,x,y,z) warpPedIntoVehicle ( thePlayer, Vehicle ) end end Pointless what you did there. Since its a command its suppose have; function (player, command, vehicleId, x, y, z) Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 function createMyVehicle(thePlayer,vehicleid,x,y,z) -- check all the arguments exist if vehicleid and x and y and z then local Vehicle = createVehicle(vehicleid,x,y,z) warpPedIntoVehicle ( thePlayer, Vehicle ) end end Pointless what you did there. Since its a command its suppose have; function (player, command, vehicleId, x, y, z) I tested it but it didn't work Client side function createVehicleHandler(button,state) if button == "left" and state == "up" then local row,col = guiGridListGetSelectedItem(PCSgridlist) if row and col and row ~= -1 and col ~= -1 then local selected = guiGridListGetItemData(PCSgridlist,row,col) selected = tonumber(selected) local rotz = getPedRotation(getLocalPlayer()) local x,y,z = getElementPosition(getLocalPlayer()) x = x y = y if selected and x and y and z then triggerServerEvent("createVehicleFromGUI",getRootElement(),selected,x,y,z) guiSetVisible(windowPCS,false) showCursor(false,false) else outputChatBox("Invalid arguments.") end else outputChatBox("Please select a vehicle.") end end end Server side function createMyVehicle(thePlayer,vehicleid,x,y,z) -- check all the arguments exist if vehicleid and x and y and z then local Vehicle = createVehicle(vehicleid,x,y,z) warpPedIntoVehicle ( thePlayer, Vehicle ) end end addEvent("createVehicleFromGUI",true) addEventHandler("createVehicleFromGUI",root,createMyVehicle) Link to comment
DNL291 Posted August 12, 2013 Share Posted August 12, 2013 (edited) If it's attached to a command handler then it should be as you said. But if it's a function to be called, my code is correct. Edit: Client: function createVehicleHandler(button,state) if button == "left" and state == "up" then local row,col = guiGridListGetSelectedItem(PCSgridlist) if row and col and row ~= -1 and col ~= -1 then local selected = tonumber(guiGridListGetItemText(PCSgridlist, row, col)) local rotz = getPedRotation(getLocalPlayer()) local x,y,z = getElementPosition(getLocalPlayer()) x = x y = y if selected and x and y and z then triggerServerEvent("createVehicleFromGUI",localPlayer,selected,x,y,z) guiSetVisible(windowPCS,false) showCursor(false,false) else outputChatBox("Invalid arguments.") end else outputChatBox("Please select a vehicle.") end end end Server: function createMyVehicle(vehicleid,x,y,z) -- check all the arguments exist if vehicleid and x and y and z then local Vehicle = createVehicle(vehicleid,x,y,z) warpPedIntoVehicle ( source, Vehicle ) end end addEvent("createVehicleFromGUI",true) addEventHandler("createVehicleFromGUI",root,createMyVehicle) Edited August 12, 2013 by Guest Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 Anyone know how can I fix it? Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 It is but why do you want to type the coordinates. Just use; local x,y,z = getElementPosition( source ) I don't type them on the client side there is a code that get them onguiclock Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 I edited my last post. It Doesn't work I can't spawn the vehicle Edit : it says invalid augment Link to comment
DNL291 Posted August 12, 2013 Share Posted August 12, 2013 Where debugscript shows that error? Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 Where debugscript shows that error? No errors in the debugscript 3 the client side is made to output this message if there is a mistake Link to comment
DNL291 Posted August 12, 2013 Share Posted August 12, 2013 See if 'selected' will return the vehicle ID on the chatbox. function createVehicleHandler(button,state) if button == "left" and state == "up" then local row,col = guiGridListGetSelectedItem(PCSgridlist) if row and col and row ~= -1 and col ~= -1 then local selected = tonumber(guiGridListGetItemText(PCSgridlist, row, col)) outputChatBox(selected) local rotz = getPedRotation(getLocalPlayer()) local x,y,z = getElementPosition(getLocalPlayer()) x = x y = y if selected and x and y and z then triggerServerEvent("createVehicleFromGUI",localPlayer,selected,x,y,z) guiSetVisible(windowPCS,false) showCursor(false,false) else outputChatBox("Invalid arguments.") end else outputChatBox("Please select a vehicle.") end end end Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 See if 'selected' will return the vehicle ID on the chatbox. function createVehicleHandler(button,state) if button == "left" and state == "up" then local row,col = guiGridListGetSelectedItem(PCSgridlist) if row and col and row ~= -1 and col ~= -1 then local selected = tonumber(guiGridListGetItemText(PCSgridlist, row, col)) outputChatBox(selected) local rotz = getPedRotation(getLocalPlayer()) local x,y,z = getElementPosition(getLocalPlayer()) x = x y = y if selected and x and y and z then triggerServerEvent("createVehicleFromGUI",localPlayer,selected,x,y,z) guiSetVisible(windowPCS,false) showCursor(false,false) else outputChatBox("Invalid arguments.") end else outputChatBox("Please select a vehicle.") end end end Now it say nill and invalid argument Link to comment
DNL291 Posted August 12, 2013 Share Posted August 12, 2013 Show how you created the grid list and how you used the guiGridListSetItemText function. Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 PCSgridlist = guiCreateGridList(10, 54, 197, 238, false, windowPCS) guiGridListAddColumn(PCSgridlist,"Vehicle",0.2) guiGridListAddColumn(PCSgridlist,"Type",0.2) guiGridListSetColumnWidth(PCSgridlist,1,0.4,true) guiGridListSetColumnWidth(PCSgridlist,2,0.5,true) populateGridlist() function populateGridlist() for name,vehicle in pairs(PCSTable) do local row = guiGridListAddRow(PCSgridlist) guiGridListSetItemText(PCSgridlist,row,1,name,false,false) guiGridListSetItemText(PCSgridlist,row,2,getVehicleType(vehicle),false,false) guiGridListSetItemData(PCSgridlist,row,1,tostring(vehicle)) end end Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 The whole script work and I am able to create the vehicles but I want it to warp the ped to the vehicle when it's created. Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 I fixed it thanks for everyone who helped me Edit : how can I replace the player vehicle with the new created vehicle just like the givevehicle on admin panel? function createMyVehicle(vehicleid,x,y,z,thePlayer) if vehicleid and x and y and z then local Vehicle = createVehicle(vehicleid,x,y,z) if thePlayer and Vehicle then warpPedIntoVehicle ( thePlayer, Vehicle ) end end end addEvent("createVehicleFromGUI",true) addEventHandler("createVehicleFromGUI",root,createMyVehicle) Link to comment
DNL291 Posted August 12, 2013 Share Posted August 12, 2013 Try this: function createMyVehicle(vehicleid,x,y,z,thePlayer) if vehicleid and x and y and z then local vehicle = getPedOccupiedVehicle(thePlayer) if (vehicle) then destroyElement(vehicle) end local Vehicle = createVehicle(vehicleid,x,y,z) if thePlayer and Vehicle then warpPedIntoVehicle ( thePlayer, Vehicle ) end end end addEvent("createVehicleFromGUI",true) addEventHandler("createVehicleFromGUI",root,createMyVehicle) Link to comment
isa_Khamdan Posted August 12, 2013 Author Share Posted August 12, 2013 Try this: function createMyVehicle(vehicleid,x,y,z,thePlayer) if vehicleid and x and y and z then local vehicle = getPedOccupiedVehicle(thePlayer) if (vehicle) then destroyElement(vehicle) end local Vehicle = createVehicle(vehicleid,x,y,z) if thePlayer and Vehicle then warpPedIntoVehicle ( thePlayer, Vehicle ) end end end addEvent("createVehicleFromGUI",true) addEventHandler("createVehicleFromGUI",root,createMyVehicle) I don't want to destroy the element just replace it like how the admin givevehicle option works Link to comment
DNL291 Posted August 12, 2013 Share Posted August 12, 2013 Replace: destroyElement(vehicle) With: removePedFromVehicle(thePlayer) 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