Trucking Missions calculate paycheck
#1

Hello, I just made trucking missions using this tutorial https://sampforum.blast.hk/showthread.php?tid=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?
Reply
#2

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...
Reply
#3

How would I check the range and set the price according to it?
Reply
#4

You could do what Darren says but I think taking the loading/delivery point would be better. A little Googling gave me this code:
pawn Код:
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:
pawn Код:
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. )
Reply
#5

That old thing :P

Are you still using :

pawn Код:
iPay[MAX_PLAYERS];
Reply
#6

Quote:
Originally Posted by DobbysGamertag
Посмотреть сообщение
That old thing :P

Are you still using :

pawn Код:
iPay[MAX_PLAYERS];
yes i am
Reply
#7

Ok

pawn Код:
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,Float: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
Reply
#8

Quote:
Originally Posted by DobbysGamertag
Посмотреть сообщение
Ok

pawn Код:
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,Float: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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)