Jump to content

Check how many vehicle the player has in the base HELP URGENT


Recommended Posts

Hello, i need a help...

I have an base system on my MTA DayZ Server, that works like that: it creates an col zone, then when a player that is not from the group hit the col zone it gets teleported...

It's working fine but i need to add a function that i think its really simple but idk how...

This is what i need:
A function that when a member of the group enter the base it says how much vehicle it's on the base...

A function that when a player try to enter with a vehicle, if the base have more than 15 vehicles on the zone, it teleport the player out of the base...

 

Basically is this:

A function that checks how much vehicle has in the base, and a function that teleport the player if he tries to get more than 15 vehicles in the base zone...

 

Here is what i think it will look like:

function checkVehicles(theElement)
	--local veh = getPedOccupiedVehicle(theElement) -- random variable from the ready resource that identify the veh player is using
	--local accName = getAccountName(getPlayerAccount(theElement)) -- idk why i put that in but...
	if ( getElementData ( theElement , "Group" ) == GroupName ) and functionThatChecksVehiclesOnTheBase < 15 then
	sendMsg(theElement, "Welcome Player")
	end
	elseif functionThatChecksVehiclesOnTheBase > 15 then
    setElementPosition( theElement, TeleportLocation[1], TeleportLocation[2], TeleportLocation[3])
	end
end
addEventHandler("onColShapeHit", getRootElement(), checkVehicles)

 

 

Thanks !!!

Edited by Gabriel1375
Link to comment
function checkVehicles(theElement)
  if ( getElementData ( theElement , "Group" ) == GroupName ) and #getElementsWithinColShape(source, "vehicle") < 15 then
    sendMsg(theElement, "Welcome Player")
  elseif #getElementsWithinColShape(source, "vehicle") > 15 then
    setElementPosition(theElement, TeleportLocation[1], TeleportLocation[2], TeleportLocation[3])
  end
end
addEventHandler("onColShapeHit", getRootElement(), checkVehicles)

Here is the code if you would not understand it.

Link to comment

Job to help him, not to copy paste and write everything for him.

The way you have to do this by making a colshape and using getElementsWithinColShape "vehicle" and then it s hould be done

it is our duty to help him as long as he learns not blindly give codes all time

  • Like 2
Link to comment

I wont start a fight here, because this is a public-forum. But if he wanted to learn programming, he could do it already. You can easily learn programming by just looking at codes, and we can help the way we want. If I have time to just make a code for a guy who needs help, I'll do it. Thank ya @Anubhav.

Link to comment
12 hours ago, pa3ck said:

At least try to comment your code next time. Dont tell me your maths teacher solved all the equations for you without explaining. 

I'm not really a newbie at scripting, just at LUA scripting, i dont know about the functions and things like this...

But i understand scripts, my problem is at writing it...

Like the code:

function checkVehicles(theElement)
  if ( getElementData ( theElement , "Group" ) == GroupName ) and #getElementsWithinColShape(source, "vehicle") < 15 then
    sendMsg(theElement, "Welcome Player")
  elseif #getElementsWithinColShape(source, "vehicle") > 15 then
    setElementPosition(theElement, TeleportLocation[1], TeleportLocation[2], TeleportLocation[3])
  end
end
addEventHandler("onColShapeHit", getRootElement(), checkVehicles)

Means:

Declare function named checkVehicles(hereistheplayer)

if the group of the element its equal to groupname and the vehicles its minor of 15 then
send message only to the player saying Welcome Player

but if the vehicles is more than 15 then

set element position, teleport locations array

and end the code after this

and end the function after

set the event to happens only when hit the collision shape, element, and the function that will happens

 

My biggest problems is at writing it, to memorize the function names you know...

Link to comment
11 hours ago, Gabriel1375 said:

My biggest problems is at writing it, to memorize the function names you know...

1

Just use N++ or sublime autocomplete/syntax highlighter for the function names it helps a lot.

function checkVehicles(theElement)
	-- Check if theElement is a vehicle.
	if getElementType(theElement) == "vehicle" then
    	-- Get the driver of said vehicle.
		local driver = getVehicleController( theElement )
		-- Check if he belongs to the group and get the count of current vehicles in colshape.
		if ( getElementData ( driver , "Group" ) == GroupName ) and #getElementsWithinColShape(source, "vehicle") > 15 then
			-- Sets the position of the player's vehicle.
			setElementPosition(veh, TeleportLocation[1], TeleportLocation[2], TeleportLocation[3])
		else
			-- For each player in the vehicle...
			for _,plr in pairs (getVehicleOccupants( theElement )) do
				-- execute the sendMsg function.
				sendMsg(theElement, "Welcome Player")
			end
		end
	end
end
addEventHandler("onColShapeHit", root, checkVehicles)

 

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