Help: How to make a command find the closest co-ords
#1

So i have made a /work command for my missions but they choose a random mission each time. What I want to do is for the command to find the closest set of co-ords for the first mission.

For example: If i was a pilot and i did /work in LSA the checkpoint would be one of the LS checkpoints not one of LV or SF.

I just hate having to travel cross the map to start a mission. Its the same for Truck missions as well.

Any idea how to do this or if I need a loop or something cuz im completely in the dark with this problem.
Reply
#2

Try and post your script for the /work command.
Use pastebin if possible.
Reply
#3

http://pastebin.com/Up9JE9GU
Reply
#4

Hmm, i think GetPlayerPos and IsPlayerInRangeOfPoint May Help in it.
Reply
#5

mhm That may work but it would mean a fuck ton of scripting. But good idea.
Just gonna see if there is an alternative option. Thanks anyway Thour

Plus i have multiple missions going from the same checkpoint.

Example co-ords 0,0,0 will goto 1000,1000,0 and another mission to -1000,-1000,0
Reply
#6

as soon the script knows the checkpoint, you can go further and associate it with your mission array. i guess its 2 dimensional? anyways, one already mentioned solution could be calculating all checkpoints' distances, and then chosing the smallest one. if there are a few, like <20 checkpoints only, then this can work.
as soon you have more and more checkpoints, the longer the calculation loop will take just to get one value (the closest CP's id) back, so you should consider a more flexible way. i think about creating a dynamic areas wchich cover each checkpoint in a distance like 2000 units.
IsPlayerInDynamicArea() could then be used to check if a player is in a certain position, and therefore start the accoring mission.
may i ask how many checkpoints locations you already have? if there are more than 100 locations, with like >50 units in between each, or if you intent to let your system react on changes (in position or amount of checkpoints etc), tell us if so, please. its easier to help you if we know what you want to achieve.
one aspect is clear already: the factions/teams. a pilot should not be able to start a trash pickup mission indeed, so there a multi-pass sorting/pruning would be a neat thing already: throwing invalid mission startpoints away before calculating the distance, in different words...
Reply
#7

I have currently got 32 Mission checkpoints but that will be increasing alot as I finish more maps/classes. And when I have time to collect more Co-ords .

I have heard about IsPlayerInDynamicArea() before, however Im not really sure how to implement this into my code. I will agree with you on the fact that "IsPlayerInDynamicArea()" would be a wise choice.

However one question remains. What would happen if a player were to /work if they are not in a dynamic area.

Sorry if I sound like a noob in this, unfortunately I have never used it.
Reply
#8

haha, iam glad that you came up with that question - thats whats the logical conclusion when thinking about how to spread them zones around the whole map. or, when a checkpoint is CLOSE at the border to the next zone = a player standing 2 meters east of a mission checkpoint in the "west"-zone, could not start a mission.
the best idea is to split the whole map into areas, and loop through them, for each zone calculate the closest checkpoint (especially if the zone does NOT contain one).
6000mІ split into 100mІunits, would give you... erm.. 6000/100=60І=3600 zones. a
pawn Код:
new ZoneXYClosestCP[60][60];
...and then looped through each 100 missions' checkpoints, assigning the closest ID "where to go for the next mission":
pawn Код:
for(new y=0;y<60;y++)
{
for(new x=0;x<60;x++)
{
for(new CPid=0;CPid<sizeof(Missions);CPid++)
{
GetDistance(blablalba);
//insert more code to remember the smallest amount yet, start with 1000, not 6000 or more if you're sure that there WILL be a mission CP close. to be discussed later maybe?
}
}
}
...would be a hard job ONCE at server-startup.
BUT eversice there is no need to calculate ANY checkpoint anymore (at least for starting a mission).
this concept can be driven further: calculate a checkpoint with a BIg distance or the biggest one for a hard mission. SAVE those values in a []second array in your variable, and access the distance CP according to the "level" chosen!
the sacrifice of some CPU time to precalculate a pseudo random CP array (to be changed at each server start) will make it possible to team-up for truckers since WHEN they start a mission together, they will get redirected to the same start. when you script it clever, you might let them do the same mission together aswell
Reply
#9

Hmm, gonna try this then. Ill keep you updated on how I progress.

To be honest I have not seen much or any reference to this at all on the Forums. Just wish there was a tutorial.

Might need more of your help though in the future. If you would like I am willing to send you a copy of the gamemode (isnt too big at the moment) for you too see how this would work with this code. And if you wanted you could use the code for an example to show others how to do it. Although I bet you could make something better.
Reply
#10

This is a similiar way I use to get closest co-ords to a player.
pawn Код:
stock ClosestTruckLoad(playerid)
{
    new closest = -1, Float:dist=9999999;
    for(new i; i < sizeof(TruckLocations); i++)
    {
        if(closest == -1 || dist > GetPlayerDistanceFromPoint(playerid, TruckLocations[i][LoadX], TruckLocations[i][LoadY], TruckLocations[i][LoadZ]))
        {
            closest = i;
            dist = GetPlayerDistanceFromPoint(playerid, TruckLocations[i][LoadX], TruckLocations[i][LoadY], TruckLocations[i][LoadZ]);
        }
    }
    return closest;
}
Just change 'new MisRand = random(sizeof(TruckLocations));' to 'new MisRand = ClosestTruckLoad(playerid);'

This is untested.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)