#1

Why my code crash after "second check"? please help my solve because i working on this script 6 hours please help me to solve the problem
pawn Код:
stock LoadPlayerBan(playerid)
{
    mysql_format(duomenys, querys, "SELECT Time FROM `bans` WHERE `Name` = '%s'", PlayerName(playerid));
    mysql_function_query(data, querys, true, "OnLoadPlayerBan", "i", playerid);
    print("load bans");
}

forward OnLoadPlayerBan(playerid);
public OnLoadPlayerBan(playerid)
{
    print("ban start");
    if(!IsPlayerNPC(playerid))
    {
        new rows, fields;
        cache_get_data(rows, fields, data);

        if(rows)
        {
            print("first check");
            new timeban[MAX_PLAYERS] = 0;
            print("second check"); /// when this print server get crash
            cache_get_row(0, 3, timeban[playerid], data);
            print("third check");
            printf("Time: %d",timeban[playerid]);
   
            if(gettime() < timeban[playerid])
            {
                SendClientMessage(playerid,RED,"timeban exist test test test");
                Kick(playerid);
                print("completed timestamp");
            }
        }
    }
    return 1;
}
Reply
#2

Код:
new timeban[MAX_PLAYERS] = 0;
Why put "= 0" there? The variable has just been created, so it is automatically 0, learn this. Remove it and it should work. You can not change all arrays of one variable like this.

EDIT: Sorry, I didn't realise that you wrote AFTER the second check. Then there must be a problem with your function.
Reply
#3

i use BlueG R7 plungin so i dont have idea where can be a problem
Reply
#4

It may very well be that your cache_get_data has wrong parameters passed to it. The 3rd parameter needs to be the connection ID value, so replace it with duomenys (which is apparently the array you store the connection ID in).

The source of your problem is this line:
pawn Код:
cache_get_row(0, 3, timeban[playerid], data);
Your query returns ONE FIELD, but you're asking the script to look for the FOURTH FIELD - this will not work. Please learn that the numbering of the returned fields is RELATIVE TO THE QUERY itself, so doing
SELECT name FROM players WHERE id=1;
will return ONE FIELD with the index of 0.

Furthermore, you could optimize your whole process a bit by never even calling the query for NPCs. What you currently do is call the query, but don't process its result? What's the point of this? Simply don't execute the query in case the player is a NPC.

// EDIT:
About the declaration of arrays with default values.
Something like this will not work indeed (it may, well, but I'm quite sure it won't do what you want it to):
pawn Код:
new Array[20] = 1;
Instead, you need to use code like this:
pawn Код:
new Array[20] = {1, ...};
This will set all the values in the array (indexes 0-19) to 1.

Doing
pawn Код:
new Array[20] = {0, ...};
is not necessary as values are set to 0 by default.

Good luck coding!
Reply
#5

AndreT so after you post i understand that
pawn Код:
cache_get_row(0, 3, timeban[playerid], data);
i << 3, server call Three fields but i want just get "Time" from my database, maybe is another way to call "Time" row from database?

And
pawn Код:
new timeban[MAX_PLAYERS] = 0;
is my integer which i used to set my info from "Time" row and then i check is timeban higher than gettime, if it so i kick player and send message


And "data" and "duomenys" is same script i wrote them because i'am bit lazy i create two scripts data and duomenys but this is not a problem i have another script which work with data and duomenys and script works perfectly so i thing something is wrong with cache and i feel i know where is can be a problem
Reply
#6

any ideas how to fix?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)