if..getting correct id...getplayername
#1

Hello..
I'm trying to fix some bug for almost week. A lot of scripters have tried to fix it, but unsuccesful.
Topic: https://sampforum.blast.hk/showthread.php?pid=1204429#pid1204429

I have tested and debugged almost every day with different scripts, same bug all the time.

Here's debug script:
pawn Код:
for(new i=0;i<MAX_PLAYERS;i++)
        {
        if(IsPlayerInAnyVehicle(playerid)) // also with i
            {
            new string[64];
            format(string,sizeof(string),"%d",i);
            SendClientMessageToAll(COLOR_RED,string);
            GetPlayerName(i, uzvaretajs, sizeof(uzvaretajs));
            format(string,sizeof(string),"%s",uzvaretajs);
            SendClientMessageToAll(COLOR_RED,string);
           
            }
        }
uzvaretajs = string for GetPlayerName

Winner should be only one, this is how chat looks:


starting from id 0 (when showing ID 0, server prints out my nick). There was only two players in server (id 0, id 1 - necu), MAX_PLAYERS are set to 40, not 37. When player dies, he spawns somewhere under sea on foot. I can even see those players and they are on foot, not in the car, so if(IsPl.. fails and lets thru all players. In

I can give full gm script to any moderator, just pm me.

EDIT: i tried with PlayerInfo[i][dead] in if(..), same bug.
Reply
#2

Код:
if(IsPlayerInAnyVehicle(playerid))
to
Код:
if(IsPlayerInAnyVehicle(i))
Reply
#3

Quote:
Originally Posted by Macluawn
Посмотреть сообщение
Код:
if(IsPlayerInAnyVehicle(playerid))
to
Код:
if(IsPlayerInAnyVehicle(i))
As i said before, i tried also with PlayerInfo.. Then i used "i".
Reply
#4

You should also consider the fact, that a mistake could be somewhere else.
For years there haven't been any mistake in that function, you just have to use everything correctly.
Judging for your past mistakes, I bet my left leg, that the mistake is your fault.
Reply
#5

You should use IsPlayerConnected or something similar to check if the player you're getting the name of is actually there .. Second, it serves absolutely no purpose to copy the name into another string (which is the wrong way to do it, by the way), because the name is already a string itself. Third: you should avoid using a foreign language to name your variables. I, for that matter, have no idea what the word 'uzvaretajs' would mean if you didn't tell me.
pawn Код:
if(GetPlayerName(i, uzvaretjs, sizeof(uzvaretajs)))
            {
                SendClientMessageToAll(COLOR_RED, uzvaretajs).
            }
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
You should use IsPlayerConnected or something similar to check if the player you're getting the name of is actually there .. Second, it serves absolutely no purpose to copy the name into another string (which is the wrong way to do it, by the way), because the name is already a string itself. Third: you should avoid using a foreign language to name your variables. I, for that matter, have no idea what the word 'uzvaretajs' would mean if you didn't tell me.
pawn Код:
if(GetPlayerName(i, uzvaretjs, sizeof(uzvaretajs)))
            {
                SendClientMessageToAll(COLOR_RED, uzvaretajs).
            }
I did use IsPlayerConnected in normal script.. This is just for debugging. Also, i'm putting name into string to use it in sentence (Example: Winner is %s).
Reply
#7

In `for` spaces(" ") are important, i guess.
Quote:

Winner should be only one

If you want only one winner just add `break` at the end.
That should work:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
        {
        if(IsPlayerInAnyVehicle(i)) // also with i
            {
             new uzvaretajs[24], string[64];
            format(string,sizeof(string),"%d",i);
            SendClientMessageToAll(COLOR_RED,string);
            GetPlayerName(i, uzvaretajs, sizeof(uzvaretajs));
            format(string,sizeof(string),"%s",uzvaretajs);
            SendClientMessageToAll(COLOR_RED,string);
           //  break;
            }
        }
Reply
#8

Quote:
Originally Posted by GaGlets®
Посмотреть сообщение
In `for` spaces(" ") are important, i guess.
No.

pawn Код:
for(new i; i < MAX_PLAYERS; ++i)
{
    if(IsPlayerInVehicle(i, vehicleid))
    {
        new
            string[64]
        ;
        GetPlayerName(i, string, MAX_PLAYER_NAME);
        format(string, sizeof(string), "Winner %s (ID: %d)", string, i);
        SendClientMessageToAll(COLOR_RED, string);
        break;
    }
}
Try it like this. (Don't forget to replace the vehicleid with the vehicleid the player has to in to win)
Reply
#9

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
No.

pawn Код:
for(new i; i < MAX_PLAYERS; ++i)
{
    if(IsPlayerInVehicle(i, vehicleid)) // bug is there
    {
        new
            string[64]
        ;
        GetPlayerName(i, string, MAX_PLAYER_NAME);
        format(string, sizeof(string), "Winner %s (ID: %d)", string, i);
        SendClientMessageToAll(COLOR_RED, string);
        break;
    }
}
Try it like this. (Don't forget to replace the vehicleid with the vehicleid the player has to in to win)
It's not checking ALL Id's, but only ID 0.. ID 0 is always the winner, even if he isn't. Still same bug with if(..). I have send you a GM @ PM, please take a look.
Reply
#10

bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)