Vehicle Zangle calculations problem
#1

Hello, I am making a new server and I got a scripting problem again..

I have made it this way that you can create races in-game and stored in a MySQL database, the races are saved in 2 tables, one for the information about the race: name, raceId, creator's name and an Angel, this angele is for the Spawn at the begin of race. The other table is linked to the first and contains the coordinates of the checkpoints. For now the scripting was going good until I came at this point.
When the race starts the creator of that race event will spawn first at the start line. that without problem. because I have the coordinates of that fist point and the vehicle Z angle saved in the database.

But here is my problem, I don't know how to calculate the positions for the other opponents at the start line.
I hope someone can help me with this.
Reply
#2

Bump
(I cannot continue my scripting ffs..)
Reply
#3

Two methods:

1) Create ready-made slots for spawn x,y,z,za for all racers.

2) Automatic: (Note: Will be buggy if the surface isn't flat)

pawn Код:
#define OPPONENT_FRONT  0
#define OPPONENT_BACK   180
#define OPPONENT_LEFT   90
#define OPPONENT_RIGHT  270

stock GetOpponentPositionFrom(vehicleid, direction, Float:offset, &Float:X, &Float:Y, &Float:Z, &Float:ZA)
{   //iPLEOMAX

    GetVehiclePos(vehicleid, X, Y, Z);
    GetVehicleZAngle(vehicleid, ZA);

    X += offset * floatsin(-(ZA+direction), degrees);
    Y += offset * floatcos(-(ZA+direction), degrees);
}
Appropriate offset for FRONT/BACK would be 8 and for LEFT/RIGHT is 5.

Usage:
pawn Код:
CMD:createracer(playerid, params[])
{
    new Float:X, Float:Y, Float:Z, Float:ZA;
    switch(strval(params))
    {
        case 0: GetOpponentPositionFrom(GetPlayerVehicleID(playerid), OPPONENT_FRONT, 5, X, Y, Z, ZA);
        case 1: GetOpponentPositionFrom(GetPlayerVehicleID(playerid), OPPONENT_BACK, 5, X, Y, Z, ZA);
        case 2: GetOpponentPositionFrom(GetPlayerVehicleID(playerid), OPPONENT_LEFT, 5, X, Y, Z, ZA);
        case 3: GetOpponentPositionFrom(GetPlayerVehicleID(playerid), OPPONENT_RIGHT, 5, X, Y, Z, ZA);
    }
    CreateVehicle(400, X, Y, Z, ZA, -1, -1, 0);
    return true;
}
Output:



And remember that you can enter custom direction angle (45) to make diagonal positions!
Reply
#4

I'll go for option 2. I want my script as dynamic a possible.

Thanks a lot!
Reply
#5

thanks for you edit but how can I put my cars 2 on 2? like 2 on the first line and 2 behind them. I think that one car that comes in the new corner spot isn't in the circle u use. hmm...
Reply
#6

Just use GetOpponentPositionFrom(...); on the vehicle behind the first..

For example, create/tele a vehicle on the right side of the main one, then create cars behind each of them.
Reply
#7

oh yes, thanks again.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)