DreaM40BG Posted June 25, 2020 Share Posted June 25, 2020 Hello, I'm new at Lua and I want help - can you give me a script which when I'm near a car write /owner and it shows a GUI or idk outputchatbox with the last 5 drivers for example. Link to comment
Moderators Patrick Posted June 25, 2020 Moderators Share Posted June 25, 2020 (edited) Hi! This is not script-request section, we can't send you done scripts. But you can do it yourself. Whats you need: onPlayerVehicleEnter, addCommandHandler, outputChatBox You can detect if someone enter to a vehicle with onPlayerVehicleEnter event, and then save player's name to a table for example. And you need a command, what loop trough your table and print player names out to the chat. Edited June 25, 2020 by Patrick 1 Link to comment
DreaM40BG Posted June 25, 2020 Author Share Posted June 25, 2020 28 minutes ago, Patrick said: Hi! This is not script-request section, we can't send you done scripts. But you can do it yourself. Whats you need: onPlayerVehicleEnter, addCommandHandler, outputChatBox You can detect if someone enter to a vehicle with onPlayerVehicleEnter event, and then save player's name to a table for example. And you need a command, what loop trough your table and print player names out to the chat. Like triggerserverevent or what? And how to make a "radar" for these cars, I mean how to see the driver list of the car in front of me, not to all in the server? Link to comment
nxFairlywell Posted June 25, 2020 Share Posted June 25, 2020 (edited) Hmm, i think that will be helpful. So, you have to use this code in client side of Lua script : local Distance = 100; -- Distance between vehicles and the player that written /owner addCommandHandler("owner", function(cmd) local x, y, z = getElementPosition(localPlayer); local nearestVehicle = false; local vehicles = {}; for key, veh in ipairs (getElementsByType("vehicle")) do local vehX,vehY,vehZ=getElementPosition(veh); local dist = getDistanceBetweenPoints3D (x,y,z,vehX,vehY,vehZ); if dist<=Distance then table.insert(vehicles,veh); end end local SortedTable = {}; for key, veh in ipairs (vehicles) do local vehX,vehY,vehZ=getElementPosition(veh); local vehDistance = getDistanceBetweenPoints3D (x,y,z,vehX,vehY,vehZ); SortedTable[#SortedTable+1] = {}; SortedTable[#SortedTable].distance = vehDistance;SortedTable[#SortedTable].vehicle = veh; end table.sort(SortedTable, function(a,b) return (a.distance<b.distance) end ); local vehicle = SortedTable[1].vehicle; local data = getElementData(vehicle,"$vehicle_details$"); if data and type(data)=="table" and #data>0 then for key, player in ipairs (data) do outputChatBox(getPlayerName(player)); end return true end return false end ); Server side : function table.find(t,v) for i = 1, #t do if t[i]==v then return true end; end return false; end function OnVehicleEnter(player) local vehicle = source; local vehicle_details = getElementData(vehicle,"$vehicle_details$"); local new_details = {}; if not vehicle_details then setElementData(vehicle,"$vehicle_details$",{player}); return true; end if vehicle_details and type(vehicle_details)=="table" and #vehicle_details>0 then if not table.find(vehicle_details,player) then if #vehicle_details==5 then new_details = {vehicle_details[2],vehicle_details[3],vehicle_details[4],vehicle_details[5],player}; setElementData(vehicle,"$vehicle_details$",new_details); elseif #vehicle_details<=4 then table.insert(vehicle_details,player); setElementData(vehicle,"$vehicle_details$",vehicle_details); end end end end addEventHandler("onVehicleEnter",root,OnVehicleEnter); Edited June 25, 2020 by VenomNX 1 Link to comment
DreaM40BG Posted June 25, 2020 Author Share Posted June 25, 2020 I will check it tomorrow and I will write. Thank you Link to comment
nxFairlywell Posted June 25, 2020 Share Posted June 25, 2020 2 minutes ago, DreaM40BG said: I will check it tomorrow and I will write. Thank you np, you're welcome 1 Link to comment
Moderators IIYAMA Posted June 25, 2020 Moderators Share Posted June 25, 2020 (edited) Moved to resources, since it was a scripting request. Edited June 25, 2020 by IIYAMA 1 Link to comment
DreaM40BG Posted June 26, 2020 Author Share Posted June 26, 2020 The script is not working. :[ @VenomNX Link to comment
nxFairlywell Posted June 26, 2020 Share Posted June 26, 2020 (edited) 1 hour ago, DreaM40BG said: The script is not working. :[ @VenomNX Its working for me. Anyway, start the script and write "/debugscript 3", if you see any bugs, take a picture and show me . Might it doesn't work how you like to be. - you have to be near from the nearest vehicle that you want to see its owners. - you have to make sure if there is an owner for that vehicle or not, if no owner, the script can't show you the owners. - i edited the client side script, some issues have fixed. local Distance = 100; addCommandHandler("owner", function(cmd) local x, y, z = getElementPosition(localPlayer); local vehicles = {}; for key, veh in ipairs (getElementsByType("vehicle")) do local vehX,vehY,vehZ=getElementPosition(veh); local dist = getDistanceBetweenPoints3D (x,y,z,vehX,vehY,vehZ); if dist<=Distance then table.insert(vehicles,veh); end end local SortedTable = {}; for key, veh in ipairs (vehicles) do local vehX,vehY,vehZ=getElementPosition(veh); local vehDistance = getDistanceBetweenPoints3D (x,y,z,vehX,vehY,vehZ); SortedTable[#SortedTable+1] = {}; SortedTable[#SortedTable].distance = vehDistance;SortedTable[#SortedTable].vehicle = veh; end table.sort(SortedTable, function(a,b) return (a.distance<b.distance) end ); local vehicle = SortedTable[1].vehicle; local data = getElementData(vehicle,"$vehicle_details$"); local vehX,vehY,vehZ =getElementPosition(vehicle) if data and type(data)=="table" and #data>0 then for key, player in ipairs (data) do outputChatBox(getVehicleName (vehicle).."'s Owner "..tostring(key).." : "..getPlayerName(player)); end return true else outputChatBox(getDistanceBetweenPoints3D (x,y,z,vehX,vehY,vehZ)); outputChatBox(getVehicleName (vehicle).." has no owners."); return false; end return false end ); Edited June 26, 2020 by VenomNX Some fixes Link to comment
DreaM40BG Posted June 26, 2020 Author Share Posted June 26, 2020 2 hours ago, VenomNX said: Its working for me. Anyway, start the script and write "/debugscript 3", if you see any bugs, take a picture and show me . Might it doesn't work how you like to be. - you have to be near from the nearest vehicle that you want to see its owners. - you have to make sure if there is an owner for that vehicle or not, if no owner, the script can't show you the owners. - i edited the client side script, some issues have fixed. local Distance = 100; addCommandHandler("owner", function(cmd) local x, y, z = getElementPosition(localPlayer); local vehicles = {}; for key, veh in ipairs (getElementsByType("vehicle")) do local vehX,vehY,vehZ=getElementPosition(veh); local dist = getDistanceBetweenPoints3D (x,y,z,vehX,vehY,vehZ); if dist<=Distance then table.insert(vehicles,veh); end end local SortedTable = {}; for key, veh in ipairs (vehicles) do local vehX,vehY,vehZ=getElementPosition(veh); local vehDistance = getDistanceBetweenPoints3D (x,y,z,vehX,vehY,vehZ); SortedTable[#SortedTable+1] = {}; SortedTable[#SortedTable].distance = vehDistance;SortedTable[#SortedTable].vehicle = veh; end table.sort(SortedTable, function(a,b) return (a.distance<b.distance) end ); local vehicle = SortedTable[1].vehicle; local data = getElementData(vehicle,"$vehicle_details$"); local vehX,vehY,vehZ =getElementPosition(vehicle) if data and type(data)=="table" and #data>0 then for key, player in ipairs (data) do outputChatBox(getVehicleName (vehicle).."'s Owner "..tostring(key).." : "..getPlayerName(player)); end return true else outputChatBox(getDistanceBetweenPoints3D (x,y,z,vehX,vehY,vehZ)); outputChatBox(getVehicleName (vehicle).." has no owners."); return false; end return false end ); Link to comment
nxFairlywell Posted June 26, 2020 Share Posted June 26, 2020 (edited) show me the meta.xml file don't edit the code, that might causes a trouble if you actually edited the code, show me what you did Edited June 26, 2020 by VenomNX Link to comment
DreaM40BG Posted June 26, 2020 Author Share Posted June 26, 2020 Apf, I was sleepy and I defined client.Lua as a server, now It is working but it has a bug: If the owner leave the server and connect again when I write /owner it shows that this car doesn't have an owner. Link to comment
DreaM40BG Posted June 27, 2020 Author Share Posted June 27, 2020 It shows 1.XXXXXXXXXXXXXXX and the owner but when the owner leave the server it resets and doesn't show the owner, or when join again - doesn't show 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