Cammand keep crashing the server
#1

Each time i use this command that i have made it crashes the server, idk why

PHP код:
CMD:tempban(playerid,params[])
{
    if(
IsPlayerAdmin(playerid) || pInfo[playerid][Admin] >= 1)
    {
        new 
id,reason[50],time;
         new 
hourbminbsecb;
        
gettime(hourb,minb,secb);
        new 
yearbmonthbdayb;
        
getdate(yearb,monthb,dayb);
        if(
sscanf(params,"us[50]i",id,reason,time)) return SendClientMessage(playerid,-1,"Usage : /tempban (id) (reason) (time)");
        
pInfo[id][BanTime] = gettime();
        
pInfo[id][BanDay] =  60*60*24time;
        
pInfo[id][Banned] = 1;
        new 
INI:File INI_Open(UserPath(id));
        
INI_SetTag(File,"data");
           
INI_WriteString(File,"BanReason",reason);
           
INI_WriteString(File,"Banby",GetName(playerid));
        
INI_Close(File);
        new 
message[128];
          
format(messagesizeof(message), "[AdmCmd]:{FF6347}%s has been Temporarily Banned from the server. | Reason: %s || Time: %d Day(s)"GetName(id), reasontime);
        
SendClientMessageToAll(redmessage);
        
SendClientMessage(id,red,"=====================================================");
        
SendClientMessage(id,red,"{FF6347}You have been Banned from Caribbean Mafia Warz.");
        
format(messagesizeof(message),"Your Name: %s - Your IP: %s",GetName(playerid), pIP);
        
SendClientMessage(id,-1,message);
        
format(messagesizeof(message),"Banned by: %s "GetName(playerid));
        
SendClientMessage(id,-1,message);
        
format(messagesizeof(message),"Banned Reason: %s "reason);
        
SendClientMessage(id,-1,message);
        
format(messagesizeof(message),"Unban in %d Day(s)",time );
        
SendClientMessage(id,-1,message);
        
format(messagesizeof(message),"Date: %d/%d/%d || Time: %d:%d:%d",dayb,monthb,yearb,hourb,minb,secb );
        
SendClientMessage(id,-1,message);
        
SendClientMessage(id,red,"{FF6347}Visit our forums at: "SERVER_FORUMS" - ScreenShot is required for an appeal.");
        
SendClientMessage(id,red,"=====================================================");
        
SendClientMessage(id,red,"{FF6347}Server Administrators has been notified.");
           
SetTimerEx("BanPlayer",200,false,"ud"id,2);
    }
     else return 
ShowMessage(playeriderror1);
    return 
1;
}
/* 
Reply
#2

I've seen in the past INI_Open crashing the server but in the old version (3.1) of it. For a detailed log about the crash, load crashdetect: https://github.com/Zeex/samp-plugin-...etect/releases
Compile with debug info: https://github.com/Zeex/samp-plugin-...ith-debug-info

Next time it will crash, post your server log. On another hand, updating to the latest version of YSI (https://github.com/Misiur/YSI-Includes) is a good idea.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I've seen in the past INI_Open crashing the server but in the old version (3.1) of it. For a detailed log about the crash, load crashdetect: https://github.com/Zeex/samp-plugin-...etect/releases
Compile with debug info: https://github.com/Zeex/samp-plugin-...ith-debug-info

Next time it will crash, post your server log. On another hand, updating to the latest version of YSI (https://github.com/Misiur/YSI-Includes) is a good idea.
Ok so i did what you say step by step right, so now when i run crashdetect it keep on spamming me with this error

PHP код:
[22:42:05] [debugRun time error 4"Array index out of bounds"
[22:42:05] [debug]  Attempted to read/write array element at index 1000 in array of size 1000
[22:42:05] [debugAMX backtrace:
[
22:42:05] [debug#0 0005ce9c in public Checker () from ODA.amx 
and each time itry to do the command i get this error
PHP код:
[22:40:02] [debugAMX backtrace:
[
22:40:02] [debug#0 00000038 in public OnPlayerDisconnect () from ODA.amx
[22:40:02] [debug#1 native Kick () from samp-server.exe
[22:40:02] [debug#2 000698ac in public BanPlayer (0, 2) from ODA.amx 
I will be looking for some possible ways to resolve this but i will also still be looking forward for a reply from you and i will keep updating the post .
Reply
#4

I can see the mistake now.
Код:
SetTimerEx("BanPlayer",200,false,"ud", id,2);
"u" is only a specifier for sscanf, you pass "d" or "i" for integers in SetTimerEx function. About the run time error, post Checker public function. Most likely it is a loop that goes on like this:
Код:
for (new i = 0; i <= MAX_PLAYERS; i++)
The equal sign would cause it as an array with size of 1000 has valid indexes betweeen 0 and 999. But I can't be sure without looking at the code.

PS: You didn't compile with debug info though, that would give the exact line and would be easier to track down.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I can see the mistake now.
Код:
SetTimerEx("BanPlayer",200,false,"ud", id,2);
"u" is only a specifier for sscanf, you pass "d" or "i" for integers in SetTimerEx function. About the run time error, post Checker public function. Most likely it is a loop that goes on like this:
Код:
for (new i = 0; i <= MAX_PLAYERS; i++)
The equal sign would cause it as an array with size of 1000 has valid indexes betweeen 0 and 999. But I can't be sure without looking at the code.

PS: You didn't compile with debug info though, that would give the exact line and would be easier to track down.
Ok i compiled with the debug and it says the error is in this line 2163
PHP код:
    for (new 0<= MAX_PLAYERSi++)
    {
          new 
eveh GetPlayerVehicleID(i);
           if(
PlayerTemp[i][isevent] == && eveh != EventCars[i] || PlayerTemp[i][isevent] == && eveh != EventCars[i])// line with the error
           

also the other error about when i use the command
PHP код:
 [debugAMX backtrace:
[
22:27:09] [debug#0 00000030 in public OnPlayerDisconnect () at <unknown file>:0
[22:27:09] [debug#1 native Kick () from samp-server.exe
[22:27:09] [debug#2 00081560 in public KickPlayer (playerid=0) at ./comps/callbacks.pwn:3016
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public KickPlayer(playerid)
{
    
Kick(playerid);// this is line 3016
    
return 1;

Reply
#6

There are better alternatives than looping 1000 times. The correct way would be i < MAX_PLAYERS and not i <= MAX_PLAYERS. However, you can replace:
pawn Код:
for (new i = 0; i <= MAX_PLAYERS; i++)
with:
pawn Код:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
or better yet, use foreach (y_iterate).

---

I assume you pass "u" as format specifier again in SetTimeEx for KickPlayer. Find it/these parts and replace with "d" or "i".
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
There are better alternatives than looping 1000 times. The correct way would be i < MAX_PLAYERS and not i <= MAX_PLAYERS. However, you can replace:
pawn Код:
for (new i = 0; i <= MAX_PLAYERS; i++)
with:
pawn Код:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
or better yet, use foreach (y_iterate).

---

I assume you pass "u" as format specifier again in SetTimeEx for KickPlayer. Find it/these parts and replace with "d" or "i".
Ok bro i have made the changes throughout the whole script and it has stopped the spamming error , which i thank you very much for your dedication and help but the kickplayer error stills happen only when i use the /tempban command, i am wondering if there is a problem with the command itself, because to my knowledge i dont see any and i made it from my head without looking at a tutorial because i cant find a good tutorial on a tempban system.

PHP код:
[01:45:50] [debugRun time error 6"Invalid instruction"
[01:45:50] [debug]  Unknown opcode 0x1062ebe at address 0x00000039
[01:45:50] [debugAMX backtrace:
[
01:45:50] [debug#0 00000039 in public OnPlayerDisconnect () at <unknown file>:0
[01:45:50] [debug#1 native Kick () from samp-server.exe
[01:45:50] [debug#2 00081580 in public KickPlayer (playerid=0) at ./comps/callbacks.pwn:3016 
As you can see i still get the error on the line 3016
Reply
#8

But the /tempban command only calls timer BanPlayer and not KickPlayer. Can you show line 3016 and/or how you call KickPlayer with SetTimerEx?

The command is okay, you only forgot to check if player is connected which will give run time error 4 if sscanf returns INVALID_PLAYER_ID and you use it in pInfo array; although it's irrelevant at the moment.
Reply
#9

PHP код:
public KickPlayer(playerid

    
Kick(playerid);// this is line 3016 
    
return 1
}
SetTimerEx("KickPlayer",200,false,"d"id,2); 
Reply
#10

1 format specifier, 2 arguments. The last one is not used anywhere so just:
pawn Код:
SetTimerEx("KickPlayer",200,false,"d", id);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)