Get random coordinates in an area
#1

Hi eveyone,

I am making a fire system for my Fire Department faction, and now i was curious, is there any way to get random coodinates in an area?

So, that it only gives coordinates in the area Los Santos?


Thanks in advance
Reply
#2

This require alot of code, but it is very possibly done.

You'll need:
- Map Andreas.
- A zone script.
- Updates (Keys, in range, health, etc)
Reply
#3

You would have to /save all the co-ordinates of the fires into an array, then access them using a random timer and the random function.

- Removed: Bad Example -

You could use the method above, but it would be much simpler to choose the places of fires rather than placing them randomly. Map Andreas runs up your RAM too.
Reply
#4

You could modify the function in my sig, i haven't tested this but i think it should work.

pawn Code:
stock RandPosInArea( Float: minx, Float: miny, Float: maxx, Float: maxy, &fDestX, &fDestY )
{
    new
        iMin, iMax,
        Float:mul = floatpower(10.0, 4)
    ;

    iMin = floatround(minx * mul);
    iMax = floatround(maxx * mul);

    fDestX = float(random(iMax - iMin) + iMin) / mul;

    iMin = floatround(miny * mul);
    iMax = floatround(maxy * mul);

    fDestY = float(random(iMax - iMin) + iMin) / mul;

}
Usage:

pawn Code:
//create variables to store co-ordinates
new RandX, RandY;

//first 4 arguments are the area (minx, miny, maxx, maxy)
//last 2 arguments are the variables to store the random co-ordinates passed by reference
RandPosInArea( -840.807, -1272.888, 665.6389, 373.692, RandX, RandY );

//RandX and RandY hold the 2D co-ordinates
This doesn't work for the z axis (height) you would need to use mapandreas plugin for that. Or know the height in advance.

EDIT: This wouldn't work well for a whole city. But with this you could create several areas in a city and choose one at random, then create a fire at a random point in that area. But like i said it would need to be flat ground so you know the height, or use mapandreas plugin to get the height.
Reply
#5

Thanks alot everyone
I will try a combination of those, like, choosing already defined places by me, and also try some of your suggestions

Isn't it possible to create it only at specefic object ids though? like, that it only makes fires at houses?
This would be very nice...

thanks anyways
Reply
#6

You can use CreateExplosion for client-sided fire, or you can use these object ID's to create server-sided fires. A mix of both would be best.
Reply
#7

So.. how can i make that these objects will be created randomly at one of some houses?

EDIT: can't i use the CP coords of my house system??
Maybe i can let the script create the script fires at random CP's...?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)