SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 29/03/2019, 08:26 PM   #1
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default A problem

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.
SymonClash is offline   Reply With Quote
Old 29/03/2019, 09:31 PM   #2
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,632
Reputation: 535
Default Re: A problem

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.
NaS is offline   Reply With Quote
Old 29/03/2019, 09:44 PM   #3
Hunud
Gangsta
 
Hunud's Avatar
 
Join Date: Jun 2016
Location: Right here.
Posts: 605
Reputation: 53
Default Re: A problem

use break;
Hunud is offline   Reply With Quote
Old 29/03/2019, 11:52 PM   #4
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default Re: A problem

Any example?
SymonClash is offline   Reply With Quote
Old 30/03/2019, 12:42 AM   #5
Kasichok
Big Clucker
 
Kasichok's Avatar
 
Join Date: Sep 2018
Location: weed farm
Posts: 56
Reputation: 24
Default Re: A problem

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;
    }
}
__________________



STRESSED? TRY KASICHOK AND RELAX


Kasichok is offline   Reply With Quote
Old 30/03/2019, 09:49 AM   #6
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default Re: A problem

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);
SymonClash is offline   Reply With Quote
Old 30/03/2019, 11:13 AM   #7
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,632
Reputation: 535
Default Re: A problem

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...
NaS is offline   Reply With Quote
Old 30/03/2019, 11:16 AM   #8
Bolex_
Gangsta
 
Bolex_'s Avatar
 
Join Date: Aug 2015
Location: Croatia.
Posts: 586
Reputation: 117
Default Re: A problem

Switch to areas.
Bolex_ is offline   Reply With Quote
Old 30/03/2019, 02:00 PM   #9
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default Re: A problem

Nas thank you, i removed the second break and it works, thanks!
SymonClash is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Hash Problem & MYSQL Saving Problem Faqahat Scripting Help 3 18/04/2016 11:54 AM
[SOLVED] 3 problem's! (1 problem still unsolved, but stopped solving.) Mechscape Help Archive 9 24/12/2009 08:47 PM


All times are GMT. The time now is 02:52 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.