PDA

View Full Version : Trucking Missions calculate paycheck


wumpyc
24/07/2013, 11:36 PM
Hello, I just made trucking missions using this tutorial http://forum.sa-mp.com/showthread.php?t=340517 and now I would like to modify it so the point that it would automatically calculate the distance between locations and based on that distance it would give money. Very long distance gives more, very small distance less.

Is this possible or do I have to manually set the prices?

DarrenReeder
24/07/2013, 11:40 PM
could get the X and Y position of where the player and destination is, and if the range is lower, you get less and if its high you get more...

wumpyc
24/07/2013, 11:47 PM
How would I check the range and set the price according to it?

jessejanssen
25/07/2013, 12:02 AM
You could do what Darren says but I think taking the loading/delivery point would be better. A little Googling gave me this code:
forward Float:GetDistanceFromPointToPoint(Float:X, Float:Y, Float:Z, Float:tX, Float:tY, Float:tZ);

public Float:GetDistanceFromPointToPoint(Float:X, Float:Y, Float:Z, Float:tX, Float:tY, Float:tZ)
{
return Float:floatsqroot((tX-X)*(tX-X)+(tY-Y)*(tY-Y)+(tZ-Z)*(tZ-Z));
}
And if you use this in a formula with giving money for example like this:
GivePlayerMoney(playerid, floatround(GetDistanceFromPointToPoint(LoadPointX, LoadPointY, LoadPointZ, DeliveryPointX, DeliveryPointY, DeliveryPointZ), floatround_round)*2);
It will give more money the further the delivery point is away from the loadpoint.

Best regards,
Jesse

EDIT:
I don't know how experienced you are with scripting, but at the moment I've set it so it'll give double the amount of metres driven in money. If you want to alter this number just change the *2 to *3 or anything else ( Except floats, because then you'd have to do it in a little different way. If you want to do that and don't know how ask me and I'll explain it to you. )

DobbysGamertag
25/07/2013, 12:09 AM
That old thing :P

Are you still using :


iPay[MAX_PLAYERS];

wumpyc
25/07/2013, 02:12 AM
That old thing :P

Are you still using :


iPay[MAX_PLAYERS];


yes i am

DobbysGamertag
25/07/2013, 02:25 AM
Ok :D


iPay[playerid] = GetDistance(X,Y,Z,unx[playerid],uny[playerid],unz[playerid]);//replace with your own methods if needed. Add it to the stock which selects the job.

//So it shoud look like:

unz[playerid] = MisLocationsUnloadEnum[MisRandUnLoad][UnLoadZ];
iPay[playerid] = GetDistance(X,Y,Z,unx[playerid],uny[playerid],unz[playerid]);
SetPlayerCheckpoint(playerid, X, Y, Z, 7);


//^^^ Thats from my own Gamemode(old version).


//giving the money when they finish

GivePlayerMoney(playerid,iPay[playerid]*AMOUNT);

//replace amount with whatever you see fit :)


//the stock you'll need

stock GetDistance(Float:x1,Float:y1,Float:z1,Float:x2,Fl oat:y2,Float:z2)
{
return floatround(floatsqroot(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)) + ((z1 - z2) * (z1 - z2))));
}




Let me know if you hit any errors. Ive got my iPay[playerid]*8 :)

wumpyc
25/07/2013, 03:11 AM
Ok :D


iPay[playerid] = GetDistance(X,Y,Z,unx[playerid],uny[playerid],unz[playerid]);//replace with your own methods if needed. Add it to the stock which selects the job.

//So it shoud look like:

unz[playerid] = MisLocationsUnloadEnum[MisRandUnLoad][UnLoadZ];
iPay[playerid] = GetDistance(X,Y,Z,unx[playerid],uny[playerid],unz[playerid]);
SetPlayerCheckpoint(playerid, X, Y, Z, 7);


//^^^ Thats from my own Gamemode(old version).


//giving the money when they finish

GivePlayerMoney(playerid,iPay[playerid]*AMOUNT);

//replace amount with whatever you see fit :)


//the stock you'll need

stock GetDistance(Float:x1,Float:y1,Float:z1,Float:x2,Fl oat:y2,Float:z2)
{
return floatround(floatsqroot(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)) + ((z1 - z2) * (z1 - z2))));
}




Let me know if you hit any errors. Ive got my iPay[playerid]*8 :)
Thanks man. Works like a charm +rep :)