GetNearestBus
#1

I'm sleepy, very sleepy.
Someone help me out, It's not returning me the name of the area.




pawn Code:
enum BusStopsMain
{
    BusName[34],
    Float:BusCords[3]
};

static const BusStops[][BusStopsMain] =
{
    {"Doherty Station",                 {-2002.7013,145.5387,27.63840}}, // BusStop 1: Train Station
    {"National Bank",                   {-1998.4659,471.1749,35.10720}}, // BusStop 2: San Fierro Bank
    {"Department of Licenses",          {-1869.0721,600.3917,35.11500}}, // Bus Stop 3: Department of licenses
    {"San Fierro Police Department",    {-1631.8818,726.1474,14.56140}}, // Bus Stop 4: San Fierro Police Department
    {"Westside Avenue",                 {-1529.6941,961.0469,7.132800}}, // Bus Stop 5: Docks
    {"Oto's Motorbikes",                {-1630.6411,1251.6025,7.14990}}, // Bus Stop 6: Oto's autos
    {"Pier-39",                         {-1990.4875,1314.1171,7.13860}}, // Bus Stop 7: Pier 39
    {"Calton Heights",                  {-2147.3218,1278.8663,24.6881}}, // Bus Stop 8: Calton Heights
    {"Juniper Hill",                    {-2271.9961,1064.8588,81.8771}}, // Bus Stop 9:Juniper Hill
    {"Chinatown",                       {-2272.3606,689.1893,49.39800}}, // Bus Stop 10: Chinatown
    {"San Fierro Medical Center",       {-2588.3118,571.5823,14.56070}}, // Bus Stop 11: San Fierro Medical Center
    {"Ocean Flats",                     {-2710.1938,-26.9371,4.350200}} // Bus Stop 12: Ocean Flats South
};

pawn Code:
forward GetNearestBus(playerid, name[], len);
public GetNearestBus(playerid, name[], len)
{
    new Float:d = 0.000;
    new Float:dis = 0.0000;
    new number = -1;
    for(new i = 0; i <= sizeof(BusStops); i++)
    {
        dis = GetPlayerDistanceFromPoint(playerid, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
        if(dis > d)
        {
            d = dis;
            number = i;
        }
    }
    return format(name, len, BusStops[number][BusName], 0);
}
Example usage:

pawn Code:
new bs[34];
            GetNearestBus(playerid, bs, 34);
            new strr[128];
            format(strr, sizeof(strr), "Current Stop - %s  **Speaker**", bs);

It's like 4:30 AM here and I can barely think, but I want to finish this
Reply
#2

forward GetNearestBus(playerid, zone[], len);
stock GetNearestBus(playerid, zone[], len)

whats that? its a public or a stock? rofl xD
Reply
#3

Quote:
Originally Posted by StreetGT
View Post
forward GetNearestBus(playerid, zone[], len);
stock GetNearestBus(playerid, zone[], len)

whats that? its a public or a stock? rofl xD
SSSH, Im sleepy.


Anyway, with that changed it wont make a big difference anyway, will still be bugged.
Any solution? I want to go to bed but I can't before it's finished.
My eyes are slowly closing
Reply
#4

Nevermind.
Reply
#5

Quote:
Originally Posted by SuperViper
View Post
Nevermind.
That didn't really help me
Reply
#6

pawn Code:
forward GetNearestBus(playerid, name[], len);
public GetNearestBus(playerid, name[], len)
{
    new Float:d = 0.000;
    new Float:dis = 0.0000;
    new number = -1;
    for(new i = 0; i <= sizeof(BusStops); i++)
    {
        dis = GetPlayerDistanceFromPoint(playerid, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
        if(dis > d)
        {
            d = dis;
            number = i;
        }
    }
    return format(name, len, BusStops[number][BusName], 0);
The above is your posted code.

pawn Code:
forward GetNearestBus(playerid, &name[], len);
public GetNearestBus(playerid, &name[], len)
{
    new Float:d = 9999.000;
    new Float:dis = 0.0000;
    new number = -1;
    for(new i = 0; i <= sizeof(BusStops); i++)
    {
        dis = GetPlayerDistanceFromPoint(playerid, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
        if(dis < d)
        {
            d = dis;
            number = i;
        }
    }
format(name, len, BusStops[number][BusName], 0);
    return name;
}
The above code is my fix to your problem. Indent where needed.

Things wrong:
- Your finding the furthest bus stop... you should be finding the nearest.
- - Change if(dis > d) to if(dis < d)
- - Change new Float:d = 0.000; to new Float:d = 9999.000;
- You're returning the result of format, not the name of the bustop.
- - Redo the return.
Reply
#7

Quote:
Originally Posted by Sniper Kitty
View Post
pawn Code:
forward GetNearestBus(playerid, name[], len);
public GetNearestBus(playerid, name[], len)
{
    new Float:d = 9999.000;
    new Float:dis = 0.0000;
    new number = -1;
    for(new i = 0; i <= sizeof(BusStops); i++)
    {
        dis = GetPlayerDistanceFromPoint(playerid, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
        if(dis < d)
        {
            d = dis;
            number = i;
        }
    }
new name[34];
format(name, len, BusStops[number][BusName], 0);
    return name;
}
The above code is my fix to your problem. Indent where needed.

Things wrong:
- Your finding the furthest bus stop... you should be finding the nearest.
- - Change if(dis > d) to if(dis < d)
- - Change new Float:d = 0.000; to new Float:d = 9999.000;
- You're returning the result of format, not the name of the bustop.
- - Redo the return.
Biggest Bullshit ever for returning this....
Reply
#8

Go back up.
Reply
#9

Your saying

pawn Code:
new name[34];
format(name, len, BusStops[number][BusName], 0);
    return name;
}
While the callback is clearly

pawn Code:
forward GetNearestBus(playerid, name[], len);
public GetNearestBus(playerid, name[], len)
See what you'r doing wrong there?
Reply
#10

No dude go back up.

I fucking fixed it *excuse my language*
Reply
#11

Quote:
Originally Posted by Sniper Kitty
View Post
No dude go back up.

I fucking fixed it *excuse my language*
That doesn't change the fact that your creating a variable name for something that has already been created in the callback/function header.


And stop the language, we are old enough (atleast I am) to talk to eachother without swearing.
Reply
#12

Are you still not reviewing my first post... I fixed the mistakes I made, the updated code should work for you.

pawn Code:
forward GetNearestBus(playerid, name[], len);
public GetNearestBus(playerid, name[], len)
{
    new Float:d = 0.000;
    new Float:dis = 0.0000;
    new number = -1;
    for(new i = 0; i <= sizeof(BusStops); i++)
    {
        dis = GetPlayerDistanceFromPoint(playerid, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
        if(dis > d)
        {
            d = dis;
            number = i;
        }
    }
    return format(name, len, BusStops[number][BusName], 0);
The above is your posted code.

pawn Code:
forward GetNearestBus(playerid, &name[], len);
public GetNearestBus(playerid, &name[], len)
{
    new Float:d = 9999.000;
    new Float:dis = 0.0000;
    new number = -1;
    for(new i = 0; i <= sizeof(BusStops); i++)
    {
        dis = GetPlayerDistanceFromPoint(playerid, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
        if(dis < d)
        {
            d = dis;
            number = i;
        }
    }
format(name, len, BusStops[number][BusName], 0);
    return name;
}
The above code is my fix to your problem. Indent where needed.

Things wrong:
- Your finding the furthest bus stop... you should be finding the nearest.
- - Change if(dis > d) to if(dis < d)
- - Change new Float:d = 0.000; to new Float:d = 9999.000;
- You're returning the result of format, not the name of the bustop.
- - Redo the return.
- - Change name to &name in the parameters.
Reply
#13

Quote:

- You're returning the result of format, not the name of the bustop.
- - Redo the return.

And this is not true.
So you are saying that with for example this:

pawn Code:
stock getfactionname(playerid, faction[], len)
{
    if(PlayerInfo[playerid][Fmember] == 1) return format(faction, len, "San Fierro Police Department", 0);
    else if(PlayerInfo[playerid][Fmember] == 2) return format(faction, len, "F.B.I", 0);
    else if(PlayerInfo[playerid][Fmember] == 3) return format(faction, len, "San Fierro Medical Center", 0);
    else if(PlayerInfo[playerid][Fmember] == 4) return format(faction, len, "National Army", 0);
//Blablabla
//Blablabla


                    new factionn[128];
                    getfactionname(playerid, factionn, sizeof(factionn));
I'm not returning the name of the faction?
That piece of code is actually working and works the same way as the busstop, only without arrays
Reply
#14

Yeah, sniper kitty should be right, atleast I don't see anything wrong with his code.
Reply
#15

Would you just try the code I posted first?

I used to respect you but now your stubbornness is showing to me.

~ TheLazySloth ~
Reply
#16

Look


I am saving the variable 'bs' as the busstop name.

pawn Code:
new bs[34];
            GetNearestBus(playerid, bs, 34);
The bs represents the "name" part in GetNearestBus(playerid, NAME[], len);

34 presents "len".


This way it defines bs as name, which is what you are returning.
Your code isn't wrong there, but neither is mine.
And you'r claiming that mine is wrong, which is not true




Quote:
Originally Posted by Sniper Kitty
View Post
Would you just try the code I posted first?

I used to respect you but now your stubbornness is showing to me.

~ TheLazySloth ~
And yeah I will,
Reply
#17

Then how come mine worked for me on my test server... and yours isnt working for either me nor you?
Reply
#18

Quote:
Originally Posted by Sniper Kitty
View Post
Then how come mine worked for me on my test server... and yours isnt working for either me nor you?
Code:
C:\Users\Milan\Documents\GTA San Andreas Scripts + Server\Reality Roleplay Gamemode Script\RealityRPrr.pwn(36094) : error 067: variable cannot be both a reference and an array (variable "name")
C:\Users\Milan\Documents\GTA San Andreas Scripts + Server\Reality Roleplay Gamemode Script\RealityRPrr.pwn(36095) : error 067: variable cannot be both a reference and an array (variable "name")
C:\Users\Milan\Documents\GTA San Andreas Scripts + Server\Reality Roleplay Gamemode Script\RealityRPrr.pwn(36110) : error 090: public functions may not return arrays (symbol "GetNearestBus")
with your
pawn Code:
forward GetNearestBus(playerid, &name[], len);
public GetNearestBus(playerid, &name[], len)
{
    new Float:d = 9999.000;
    new Float:dis = 0.0000;
    new number = -1;
    for(new i = 0; i <= sizeof(BusStops); i++)
    {
        dis = GetPlayerDistanceFromPoint(playerid, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
        if(dis < d)
        {
            d = dis;
            number = i;
        }
    }
format(name, len, BusStops[number][BusName], 0);
    return name;
}

EDIT: Ill check this thread tomorrow if needed, sorry if I was wrong but I can't think atm.
I'll review it again tomorrow when I can actually think


G-Night
Reply
#19

98.154.158.193:1994 - On my test server it will tell you the nearest bus stop.

Edit: I closed the test server.

pawn Code:
enum BusStopsMain {
    BusName[34],
    Float: BusCords[3]
};

static const BusStops[][BusStopsMain] = {
    {"Doherty Station",                 {-2002.7013,145.5387,27.63840}}, // BusStop 1: Train Station
    {"National Bank",                   {-1998.4659,471.1749,35.10720}}, // BusStop 2: San Fierro Bank
    {"Department of Licenses",          {-1869.0721,600.3917,35.11500}}, // Bus Stop 3: Department of licenses
    {"San Fierro Police Department",    {-1631.8818,726.1474,14.56140}}, // Bus Stop 4: San Fierro Police Department
    {"Westside Avenue",                 {-1529.6941,961.0469,7.132800}}, // Bus Stop 5: Docks
    {"Oto's Motorbikes",                {-1630.6411,1251.6025,7.14990}}, // Bus Stop 6: Oto's autos
    {"Pier-39",                         {-1990.4875,1314.1171,7.13860}}, // Bus Stop 7: Pier 39
    {"Calton Heights",                  {-2147.3218,1278.8663,24.6881}}, // Bus Stop 8: Calton Heights
    {"Juniper Hill",                    {-2271.9961,1064.8588,81.8771}}, // Bus Stop 9:Juniper Hill
    {"Chinatown",                       {-2272.3606,689.1893,49.39800}}, // Bus Stop 10: Chinatown
    {"San Fierro Medical Center",       {-2588.3118,571.5823,14.56070}}, // Bus Stop 11: San Fierro Medical Center
    {"Ocean Flats",                     {-2710.1938,-26.9371,4.350200}} // Bus Stop 12: Ocean Flats South
};

// Indent where needed.
stock GetNearestBus(PlayerID, &Name[], Len) {
    new Float: d = 9999.000,
        Float: dis = 9999.0000,
        number = -1;
       
    for(new i = 0; i < sizeof(BusStops); i++) {
        dis = GetPlayerDistanceFromPoint(PlayerID, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
       
        if(dis < d) {
            d = dis;
            number = i;
        }
    }
   
    format(Name, Len, BusStops[number][BusName], 0);
    return Name;
}

public OnPlayerConnect(playerid) {
    new BusStop[34];

    GetNearestBus(playerid, BusStop, 34);
   
    new String[(34 + 20)];
   
    format(String, sizeof(String), "Nearest Bus Stop: %s", BusStop), SendClientMessage(playerid, -1, String);
    return true;
}
Reply
#20

I'm sorry Kitty, you were right. Quite obvious if I look at it now
I didnt got sleep for over 30 hours so I wasn't fully awake.


One more thing

pawn Code:
stock GetNearestBus(PlayerID, &Name[], Len)
{
    new Float: d = 9999.000,Float: dis = 9999.0000, number = -1;
    for(new i = 0; i < sizeof(BusStops); i++)
    {
        dis = GetPlayerDistanceFromPoint(PlayerID, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
        if(dis < d)
        {
            d = dis;
            number = i;
        }
    }

    format(Name, Len, BusStops[number][BusName], 0);
    return Name;
}
Should be

pawn Code:
stock GetNearestBus(PlayerID, Name[], Len)
{
    new Float: d = 9999.000,Float: dis = 9999.0000, number = -1;
    for(new i = 0; i < sizeof(BusStops); i++)
    {
        dis = GetPlayerDistanceFromPoint(PlayerID, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
        if(dis < d)
        {
            d = dis;
            number = i;
        }
    }

    format(Name, Len, BusStops[number][BusName], 0);
    return Name;
}
Otherwise it gives you an error
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)