Jump to content

[HELP] Vehicle owner info [IMPORTANT]


Recommended Posts

  • Moderators

Hi!
This is not script-request section, we can't send you done scripts.

But you can do it yourself.
Whats you need: onPlayerVehicleEnteraddCommandHandleroutputChatBox

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 by Patrick
  • Like 1
Link to comment
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: onPlayerVehicleEnteraddCommandHandleroutputChatBox

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

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 by VenomNX
  • Like 1
Link to comment
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 by VenomNX
Some fixes
Link to comment
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 
);

 

oAiG4RI.png

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