SA-MP Forums Archive
Problem in my racing system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem in my racing system (/showthread.php?tid=461950)



Problem in my racing system - knackworst - 04.09.2013

Hello

I'm trying to make a race system for my server, but I stumbled upon a problem in the very beginning already...
Anyway, my goal on this code is to show a race checkpoint whenever a player is near one of the starting race checkpoints.
Here's what I did:
pawn Код:
public OnGameModeInit()
{
   
    AddCheckpointToRace(0, 0, 2378.034423, -1256.948120, 23.392478);
    return 1;
}
So the first 0 stands for the raceid, the second for the CheckPoint ID (so if that's 0 it's the starting point of the race)
and then there's 3 chords
here's the stock:
pawn Код:
stock AddCheckpointToRace(RaceID, CheckPointID, Float:CheckPointX, Float:CheckPointY, Float:CheckPointZ)
{
    RInfo[RaceID][CPX][CheckPointID] = CheckPointX;
    RInfo[RaceID][CPX][CheckPointID] = CheckPointY;
    RInfo[RaceID][CPX][CheckPointID] = CheckPointZ;

    return 1;

}
and this:
pawn Код:
public HalfSecondTimer(playerid)
{
    for(new i = 0; i < MAX_CHECKPOINTS; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 10.0, RInfo[i][CPX][0], RInfo[i][CPY][0], RInfo[i][CPZ][0]))
        {
            SetPlayerRaceCheckpoint(i,2,RInfo[i][CPX][0], RInfo[i][CPY][0], RInfo[i][CPZ][0], 0.0,0.0,0.0,10);
        }
    }
    return 1;
}
and the RInfo:
pawn Код:
enum RaceInfo
{
//blabla
    Float:CPX[MAX_CHECKPOINTS],   //The CP cords
    Float:CPY[MAX_CHECKPOINTS],  
    Float:CPZ[MAX_CHECKPOINTS],
//blabla
}
new RInfo[MAX_RACES][RaceInfo];
but when I go ingame and go to the position where I should get the checkpoint I don't see it...
Anybody knows what could be wrong?
Thanks in advance



Re: Problem in my racing system - Konstantinos - 04.09.2013

pawn Код:
RInfo[RaceID][CPX][CheckPointID] = CheckPointX;
RInfo[RaceID][CPX][CheckPointID] = CheckPointY;
RInfo[RaceID][CPX][CheckPointID] = CheckPointZ;
It should be CPX, CPY, CPZ. That's why it returns false that you're in range.


Re: Problem in my racing system - knackworst - 04.09.2013

Omg I'm an idiot...

Anyways it works, however I have another question related to this one aswell so here's the code:
pawn Код:
public HalfSecondTimer(playerid)
{
    for(new i = 0; i < MAX_RACES; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 10.0, RInfo[i][CPX][0], RInfo[i][CPY][0], RInfo[i][CPZ][0]))
        {
            new Float:PX, Float:PY, Float:PZ;
            new raceid;
            raceid = i;
            PX = RInfo[raceid][CPX][0];
            PY = RInfo[raceid][CPY][0];
            PZ = RInfo[raceid][CPZ][0];
           
            JoinPickup = CreatePickup(1317, 1, PX,PY,PZ, -1);
           
            SendClientMessage(playerid,COLOR_YELLOW ,"Test");
        }
        else
        {
            DestroyPickup(JoinPickup);
        }
    }
    return 1;
}
So to to clean things up I changed it into a pickup.
Anyways what I wanted to ask was, how do I stop the loop? so that when the loop found the right checkpoint it stops looping, because now when I am in the checkpoint I get spammed with the clientmessage ("test")...


Re: Problem in my racing system - Dragonsaurus - 04.09.2013

Use break; after SendClientMessage(...);


Re: Problem in my racing system - Konstantinos - 04.09.2013

Use
pawn Код:
break;
However, you shouldn't get spammed if the races are not at the same startup.

Anyways I'd recommend you to load the races or even if you do them manually to create the pickups in OnGameModeInit. So it won't use a timer 500 ms, plus looping through all the races all the time. Just a suggestion.


Re: Problem in my racing system - knackworst - 04.09.2013

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Use
pawn Код:
break;
However, you shouldn't get spammed if the races are not at the same startup.

Anyways I'd recommend you to load the races or even if you do them manually to create the pickups in OnGameModeInit. So it won't use a timer 500 ms, plus looping through all the races all the time. Just a suggestion.
Yeah I hardly think mine is the most efficient way of doing this, would you mind showing me some code how you would do it?


Re: Problem in my racing system - Konstantinos - 04.09.2013

Pretty much what you did.
pawn Код:
// Global variable
new
    Race_Pickups[ MAX_RACES ]
;

public OnGameModeInit( )
{
    for( new i = 0; i < MAX_RACES; i++ ) Race_Pickups[ i ] = CreatePickup( 1317, 1, RInfo[ i ][ CPX ][ 0 ], RInfo[ i ][ CPY ][ 0 ], RInfo[ i ][ CPZ ][ 0 ], -1 );
    return 1;
}

public OnGameModeExit( )
{
    for( new i = 0; i < MAX_RACES; i++ ) DestroyPickup( Race_Pickups[ i ] );
    return 1;
}



Re: Problem in my racing system - knackworst - 04.09.2013

Wait, you're right, pickups tend to just to show whenever you stream in... And that's what I need...
Thanks man


Re: Problem in my racing system - knackworst - 04.09.2013

One problem though, the pickup isn't showing, I guess it's the type but I don't think there's any type that isn't pickupable and stays until it gets destroyed but still is there...?


Re: Problem in my racing system - Konstantinos - 04.09.2013

Hm, I don't know. I've never used a not pickable thing..

You could use Incognito's streamer for streaming the checkpoints. For your case; I believe, it's what you need!