SA-MP Forums Archive
A problem - 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: A problem (/showthread.php?tid=665300)



A problem - SymonClash - 29.03.2019

Can someone tell me why this code doesn't show the SpawnpointTD even if i'm at the spawnpoint?

pawn Code:
for(new j; j < MAX_RANDOM_SPAWNS; j++)
{
    if(IsPlayerInRangeOfPoint(i, 3, RandomSpawn[j][0], RandomSpawn[j][1], RandomSpawn[j][2]) && Player[i][PlayerSpawned] == true)
    {
        PlayerTextDrawShow(i, SpawnpointTD[i]);
    }
    else
    {
        PlayerTextDrawHide(i, SpawnpointTD[i]);
    }
}
RandomSpawn:

pawn Code:
static const Float:RandomSpawn[][4] =
{
    {1320.7914,1262.0884,10.8203,357.0813},
    {408.3192,2452.5623,16.5000,5.9386},
    {-1321.2762,-219.7926,14.1484,12.5747 },
    {1910.8484,-2419.6887,13.5391,182.4597},
    {-2310.8376,-1616.5333,483.8190,176.1664},
    {-2416.7188,332.4720,34.9688,240.4801},
}
I tried with a simple SendClientMessage and it says i'm not at the spawnpoint, even if i spawn at RandomSpawn coordinates.


Re: A problem - NaS - 29.03.2019

What your loop does is repeatedly show and hide it for every spawn point.

Assume you're at Spawn Point ID 2, the loop will hide the TD for ID 0 and 1, then show it for 2 and then hide it again at 3, 4 and 5. So in the end it will still be hidden. Theoretically only the last one works at the moment.

What you need to do is stop the loop when a Spawn Point was found, and only hide it if none of the Spawn Points are near the player (so after the loop finished).
You can use a variable declared before the loop to keep track of which one was found, and if one was found at all, then act accordingly.

Sorry for the earlier replies, I mistook i for j in the TD code.


Re: A problem - Hunud - 29.03.2019

use break;


Re: A problem - SymonClash - 29.03.2019

Any example?


Re: A problem - Kasichok - 30.03.2019

Code:
for(new j; j < MAX_RANDOM_SPAWNS; j++)
{
    if(IsPlayerInRangeOfPoint(i, 3, RandomSpawn[j][0], RandomSpawn[j][1], RandomSpawn[j][2]) && Player[i][PlayerSpawned] == true)
    {
        PlayerTextDrawShow(i, SpawnpointTD[i]);
        break;
    }
    else
    {
        PlayerTextDrawHide(i, SpawnpointTD[i]);
        break;
    }
}



Re: A problem - SymonClash - 30.03.2019

Thanks but doesn't work.



As you can see, i'm at a random spawnpoint (random spawn), and the textdraw is supposed to show above the radar, but nothing.

This is the textdraw code:

pawn Code:
SpawnpointTD[playerid] = CreatePlayerTextDraw(playerid, 28.000000, 305.000000, "You're near a ~s~spawnpoint~w~!~n~~r~Spawnkill ~w~is ~r~forbidden ~w~here!");
    PlayerTextDrawBackgroundColor(playerid, SpawnpointTD[playerid], 255);
    PlayerTextDrawFont(playerid, SpawnpointTD[playerid], 2);
    PlayerTextDrawLetterSize(playerid, SpawnpointTD[playerid], 0.140000, 1.100000);
    PlayerTextDrawColor(playerid, SpawnpointTD[playerid], -1);
    PlayerTextDrawSetOutline(playerid, SpawnpointTD[playerid], 1);
    PlayerTextDrawSetProportional(playerid, SpawnpointTD[playerid], 1);
    PlayerTextDrawSetSelectable(playerid, SpawnpointTD[playerid], 0);



Re: A problem - NaS - 30.03.2019

Quote:
Originally Posted by Kasichok
View Post
Code:
for(new j; j < MAX_RANDOM_SPAWNS; j++)
{
    if(IsPlayerInRangeOfPoint(i, 3, RandomSpawn[j][0], RandomSpawn[j][1], RandomSpawn[j][2]) && Player[i][PlayerSpawned] == true)
    {
        PlayerTextDrawShow(i, SpawnpointTD[i]);
        break;
    }
    else
    {
        PlayerTextDrawHide(i, SpawnpointTD[i]);
        break;
    }
}
You only need a break when a Spawn Point was found. Otherwise this loop will always stop after the first iteration...


Re: A problem - Bolex_ - 30.03.2019

Switch to areas.


Re: A problem - SymonClash - 30.03.2019

Nas thank you, i removed the second break and it works, thanks!