Jump to content

Ground Position (server)


Clipper_

Recommended Posts

I want to create a random supply drop script that moves a certain object from a position in the air to the ground position vertically.

-- SERVERSIDE
local object = {id = 1271, x = 1000, y = 1000, z = 200}

function moveSupply(source, command)
	local box = createObject(object.id, object.x, object.y, object.z, 0, 0, 0)
  	-- here it should be something that calculates 'ground' as the z coordonate of the ground object point
  	moveObject(box, 10000, object.x, object.y, ground)
  	-- etc
end
addCommandHandler("supply", moveSupply)

. The problem is that there is no support for getting the specific ground position in serverside, only in clientside. Waiting an idea or any other method that can work.

Link to comment

You can make a function on the client side and trigger it using a custom event. Then you trigger another event on the server that receives the ground position. An example:

-- client side
addEvent('getGroundPos', true)

addEventHandler('getGroundPos', resourceRoot, function(x, y, z)
	triggerServerEvent('onGetGroundPos', resourceRoot, getGroundPosition(x, y, z))
end)

-- server side
addEvent('onGetGroundPos', true)

addEventHandler('onGetGroundPos', resourceRoot, function(groundPos)
	print(groundPos)
	-- continue your function here
end)

The only bad thing about this is that you always need a player nearby to get the ground position but there's no other way around it as far as I know.

You may also need an additional check to make sure the server event is only triggered once, if you have multiple players on your server then it gets triggered by every player.

Edited by Tails
Link to comment

Only solution that won't require any players nearby would be to manually collect the possible positions for the airdrop ground point and 'fake' the randomness by just randomly selecting one location from your list and spawn supplies there (or actually 200 units above, so you can move it to the ground). I personally dislike this type of solution as it requires quite a bit of setup, but I believe there's no other way that wouldn't imply having a player present in the area to query the engine for ground position. I'd recommend using a custom element type in the map editor for the supply drop, to quickly lay out the locations and to keep them easily editable.

  • Like 1
Link to comment
4 hours ago, Zorgman said:

Only solution that won't require any players nearby would be to manually collect the possible positions for the airdrop ground point and 'fake' the randomness by just randomly selecting one location from your list and spawn supplies there (or actually 200 units above, so you can move it to the ground). I personally dislike this type of solution as it requires quite a bit of setup, but I believe there's no other way that wouldn't imply having a player present in the area to query the engine for ground position. I'd recommend using a custom element type in the map editor for the supply drop, to quickly lay out the locations and to keep them easily editable.

I still think you could retrieve ground position of anywhere by dropping a bot ped and letting it fall, no need to even make it transparent if you know how to work with dimension.
Not positive it would work though.
Maybe could even work with vehicles.

Link to comment

I think the ped would only be virtualized and won't fall at all until a player gets in streaming distance. Even if it would fall, the ground itself/collisions are not loaded unless a player is in the area, so the ped would just fall forever and again. I'm not completely sure of this, though - maybe somebody more knowledgeable can step in and give us a definitive answer?

  • Like 1
Link to comment

The best solution I could implement is with predefined position. Although I have to create a database for those, which is not hard at all.

18 hours ago, Zorgman said:

I think the ped would only be virtualized and won't fall at all until a player gets in streaming distance. Even if it would fall, the ground itself/collisions are not loaded unless a player is in the area, so the ped would just fall forever and again. I'm not completely sure of this, though - maybe somebody more knowledgeable can step in and give us a definitive answer?

The ped solution is similar with getGroundPosition function, eliminated from first try.

Link to comment

You don't really need a database, a lua table would suffice.

But I strongly suggest you use an .edf for this kind of task - not sure why people don't seem to use them at all :)
 

<def name="airdroplocations">

    <element name="Airdrop_location" friendlyname="Airdrop" icon="airdrop.png">
        <data name="position" type="coord3d" default="0,0,0" />
        <marker type="checkpoint" size="1" color="#99ff66"/>
        <data name="Airdrop_type" type="selection:Supplies,Weapons" description="What type of items should the airdrop yeld?" required="false" default="Supplies" />
        <data name="Airdrop_altitude" type="integer" description="What altitude should the airdrop spawn and descend from?" required="false" default="200" />  
    </element>

</def>

Just add the above in a txt file file, name it airdroplocations.edf,  put it in a map resource folder and add the following to the info element in meta.xml:

edf:definition="airdroplocations.edf"

Also add an airdrop.png in the folder, so it has an icon (not really required, it just looks neater)

Then fire up the map editor and load the new definition. Upon scrolling on the bottom bar (the one with vehicles, peds etc.), the new definition should appear. Now you should be able to place these airdrop points like you would place any other map elements and save them to a .map file. Add the map file to your airdrop resource, and use getElementsByType("Airdrop_location") to retrieve them all. Whenever you want to change their locations, remove some etc., all you need to do is open the map and edit away.

You can see there are two additional 'data' elements at the bottom of the .edf i pasted above. I added those only as examples, you can really do anything along those lines. Key point is that any attribute you add like this can be later read in by using getElementData.

Hope this helps.

Edited by Zorgman
Link to comment

Could you try...?

-- 
-- SERVER

local object = {id = 1271, x = 1000, y = 1000, z = 200}

function moveSupply(source, command)
	local box = createObject(object.id, object.x, object.y, object.z, 0, 0, 0)
	triggerClientEvent(source, "onGroundPosGot", box)
end
addCommandHandler("supply", moveSupply)

addEvent("onBoxMove", true)
addEventHandler("onBoxMove", root, 
	function(Z)
		moveObject(source, 10000, object.x, object.y, Z)
	end
)

--
-- CLIENT

addEvent("onGroundPosGot", true)
addEventHandler("onGroundPosGot", root, 
	function()
		if isElementStreamedIn(source) then
			triggerServerEvent("onBoxMove", source, getGroundPosition(getElementPosition(source)))
			setElementData(source, "falling" true)
		else
			addEventHandler("onClientElementStreamIn", source, getGrondPosFromStreamIn)
		end
	end
)

function getGrondPosFromStreamIn()
	if not getElementData(source, "falling") then
		triggerServerEvent("onBoxMove", source, getGroundPosition(getElementPosition(source)))
		setElementData(source, "falling" true)
	end
end

 

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