The code I can provide will certainly need some adjustments, but I hope you'll get the idea behind "Giving player a job and checking if he has completed it"
First is the CPlayersJob class which defines a job. It defines job as a X/Y coords player has to reach and a reward he gets.
class CPlayersJob
{
public int xCoord, yCoord; //Coordinates of the target destination which player has to reach to complete the job
public int plid; //PLID of the player this job is assigned to
public int reward; //How much money the player gets after completing the job
public bool isFinished = false; //Set to "true" when the job is finished
CPlayersJob(int in_xCoord, int in_yCoord, int in_plid, int in_reward)
{
xCoord = in_xCoord;
yCoord = in_yCoord;
plid = in_plid;
reward = in_reward;
}
/** Checks if the player is at the target destination.
Returns "true" if he is, otherwise returns "false".
Input parameters are coordinates of the player's car.
It also marks the job as finished when the target dest. is reached.
*/
bool IsDestinationReached(int in_xCoord, in_yCoord)
{
if((in_xCoord == xCoord) && (in_yCoord == yCoord))
{
isFinished = true;
return true;
}
return false;
}
}
This is a method you'll probably want to call to give player a job. I'd have to have access to the full source of your application to be more specific about it, but I guess you'll figure out how to use it.
/** Call this method to give player a job. This method will add a new CPlayersJob object
to the activeJobs list. "targetX/YCoords" are coordinates of the destination the player
has to reach to complete the job, plid is player's PLID.
*/
void givePlayerAJob()
{
activeJobs.Add(new CPlayersJob(targetXCoord, targetYCoord, plid, reward));
}
And finally the code you'll want to add to your applications main loop (you know what I mean by "main loop", right?).
/*Boatload of other variables and stuff
...
*/
List<CPlayersJob> activeJobs = new List<CPlayersJob>(); //A list of all active jobs
mainLoop()
{
/*Lots of other stuff your application does
...
...
*/
//Check if any player completed his job
foreach(Info i in MCI.Info) //Iterate through all players
{
int plrId = i.PLID; //Get player's PLID
int x = i.X / 196608;
int y = i.Y / 192608;
foreach(job in activeJobs) //Iterate through all currently active jobs
{
if(job.plid == plrId) //Check if a job is assigned to a player we're processing
{
if(job.IsDestinationReached(x, y)) //Check if a player is at the target destination
{
//He is, reward him.
givePlayerAReward(job.reward); //I don't know how your application handles money, so you'll want to change this
}
}
}
//Remove all finished jobs
activeJobs.RemoveAll(JobIsFinished);
}
/** Predicate that checks if a job is finished or not.
You need to have this to make use of "RemoveAll" method provided by List.
*/
private static bool JobIsFinished(CPlayersJob job)
{
if(job.isFinished)
{
return true;
}
return false;
}
I'm nowhere near a C# compiler so I cannot test anything of this. I might be wrong about few things, but I'm sure that other folks on the forum with more C# knowledge will help you out if something doesn't work...
(really, can anyone actually check out this code? I don't want to confuse manza with some s**t I didn't bother to test)