Jump to content

Checking ground level (getting the Z)


CodeMaster

Recommended Posts

I'm making an artillery script in my Mass War GM - a constant bombarding all over the battlefield. So far, so good, it works client-side.

I'd take a guess that client-side variant would look odd. If a player would be driver or something, and a artillery falls on the player, other's in the vehicle, would just see the vehicle launching away, and exploding.

Another thing is that I'd want it to be constantly on and synced for all people, so I'd need to get the ground Z position server-side.

Can that be somehow "improvised"?

Link to comment

One idea, which perhaps would take a bit of time, would be to go round and get the average z value for an area of ground, store it in a table/xml like this:

z = { 
    {minX=300, maxX=400, minY=300, maxY=400, avgZ=15}, 
    -- and so on.... 
} 

then do something like:

  
function getZgroundPos( x, y) 
    for i=0,#z do 
        if x > z[i].minX and x < z[i].maxX and y > z[i].minY and y < z[i].maxY then 
            return z[i].avgZ 
        end 
    end 
    return false 
end 
  

this would mean you'd have to go round and get the values - and as to how specific you get, well it doesn't really matter - for large areas of flat ground - have a big gap between minX, minY and maxX, maxY - for bumpy areas (chiliad) just do smaller areas...

hope that helps

Link to comment

LOL, Will. That really made me laugh! Are you serious? Such table would have to be HUGE and you wouldn't get exact Z coord which can be useful in some cases. Also, it wouuld take you ages to make such table... SA is about 6000x6000 units, that is a big piece of world.

Link to comment

i was responding to this, it sounded like a challenge:

Can that be somehow "improvised"?

I was thinking outside the box :P

yeh the table would be big and it would take ages to go round and map everywhere, but hey - if it is needed that desperately then it would be a solution

It wouldn't take that long to do if you wrote a function to record the values...

edit - just had another idea.

have a client connected to the server at all times with the sole purpose of recording z values. warp that player to the co-ordinates you want to get the z of, get the z clientside and then send it serverside with a triggerServerEvent :)

Link to comment

Why do you both complicate that simple task.

"have a client connected to the server at all times", what for? You probably don't need to get ground Z position if there is no players online, do you?

"warp that player to the co-ordinates you want to get the z of, get the z clientside and then send it serverside with a triggerServerEvent"

That's almost exactly what I said, almost because there is a client-side function which is very useful which CodeMaster probably know about, that's why he's asking for server-side solution.

triggerClientEvent - to get ground position with getGroundPosition

triggerServerEvent - to send the Z coord back to the server...

"Isn't it easier to just use processLineOfSight between x1, y1, z1 + n and x2, y2, z2 - n?"

Why not simply using getGroundPosition()? If you're in the air, say, Z > 500, you'd have to process: z1 + 800 and z2 - 800 (interiors start at around 1000 and the highest distance you can fly is around 700-800).

Link to comment

Why not simply using getGroundPosition()? If you're in the air, say, Z > 500, you'd have to process: z1 + 800 and z2 - 800 (interiors start at around 1000 and the highest distance you can fly is around 700-800).

Because getGroundPosition does not take custom placed MTA objects into account afaik. In that perspective processLineOfSight is more flexible because you can specify in detail what to check for. Also when you test the vertical line of sight for level Z, you probably want to go with a constant MIN and MAX value instead of using player Z positions.

Link to comment

@50p Yup your thinking is right (bombardment ain't necessary if there are no players), and so I thought it at first, but getRandomPlayer() bugged up for some reason, so I got stuck using getElementsByType("player") and selecting first player. In that case if player gets the game minimized bombardment stops. But luckily getRandomPlayer somehow works now, and it's all ok, thanks anyways.

@Willy :shock: You know normal people live about 60-70 years max, and I don't wanna spend the rest of my life doing the Z level for every single part of SA.

You shouldn't fully take the "improvisation" part ;)

@Ace_Gambit You're a genie!I needed that for my custom shelters!Can't believe I didn't think of that at first...

Some pics for those who are interested in how does it all look atm:

mtascreen0004hq7.th.png

+ some other pictures of other feats (custom markers. hp refill and defense sys)

mtascreen0007of5.th.png

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