This function is breaking my script
#1

I have created this function to display match stats after a game. It runs loops to check how many goals all players scored and it will list multiple names for a record if there is a shared record. The function itself works perfectly fine. However the more times the function is run the more parts of the script that get broken.

Commands stop working, callbacks don't get called, timers don't run anymore. After running the function multiple times eventually the whole script is completely broken and all you can do is chat and log in to the RCON.

Here is the said function:

PHP код:
public DisplayMatchStats()
{
    new 
info[256],pname[20],gname[64],tname[64],result[10],goalsScored,tackles,lastpos,Float:redPossessionPerc,Float:bluePossessionPerc;
    if(
redscore bluescoreresult "Red Wins";
    if(
bluescore redscoreresult "Blue Wins";
    if(
redscore == bluescoreresult "Draw";
    
redPossessionPerc floatround(floatmul(floatdiv(redPossession,floatadd(redPossession,bluePossession)),100));
    
bluePossessionPerc floatround(floatmul(floatdiv(bluePossession,floatadd(redPossession,bluePossession)),100));
    for(new 
i=0;i<MAX_PLAYERS;i++) // Most Goals Scored
     
{
        if(
matchGoalsScored[i] >= goalsScored && matchGoalsScored[i] > 0)
        {
            if(
matchGoalsScored[i] == goalsScored// Tied record
            
{
                
GetPlayerName(i,pname,20);
                if(
lastpos 0)
                {
                    
strins(gname,", ",lastpos);
                    
lastpos lastpos 2;
                }
                
strins(gname,pname,lastpos);
                
lastpos lastpos strlen(pname);
            }
            else 
// New record
            
{
                 
goalsScored matchGoalsScored[i];
                
strdel(gname,0,64);
                
GetPlayerName(i,pname,20);
                
strins(gname,pname,lastpos);
                
lastpos strlen(pname);
            }
        }
    }
    if(
lastpos 0)
    {
        
format(pname,20," (%i)",goalsScored);
        
strins(gname,pname,lastpos);
    }
    
lastpos 0;
    for(new 
i=0;i<MAX_PLAYERS;i++) // Most tackles
     
{
        if(
matchTackles[i] >= tackles && matchTackles[i] > 0)
        {
            if(
matchTackles[i] == tackles// Tied record
            
{
                
GetPlayerName(i,pname,20);
                if(
lastpos 0)
                {
                    
strins(tname,", ",lastpos);
                    
lastpos lastpos 2;
                }
                
strins(tname,pname,lastpos);
                
lastpos lastpos strlen(pname);
            }
            else 
// New record
            
{
                 
tackles matchTackles[i];
                
strdel(tname,0,64);
                
GetPlayerName(i,pname,20);
                
strins(tname,pname,lastpos);
                
lastpos strlen(pname);
            }
        }
    }
    if(
lastpos 0)
    {
        
format(pname,20," (%i)",tackles);
        
strins(tname,pname,lastpos);
    }
    
format(info,sizeof(info),"Score: %i-%i %s\nBall Possession: Red %.0f%s - Blue %.0f%s\nMost Goals: %s\nMost Tackles: %s",redscore,bluescore,result,redPossessionPerc,"%",bluePossessionPerc,"%",gname,tname);
    for(new 
i=0;i<MAX_PLAYERS;i++)
     {
        if(
Spawned[i]) ShowPlayerDialog(i,255,DIALOG_STYLE_MSGBOX,"Match Stats",info,"OK","");
    }

Any ideas?
Reply
#2

im not sure but this callback needs to return a vale > you have to put

return 1;

at the end of callback i think it will fix that
Reply
#3

Quote:
Originally Posted by khRamin78
Посмотреть сообщение
im not sure but this callback needs to return a vale > you have to put

return 1;

at the end of callback i think it will fix that
Didn't work. Still the same problem.
Reply
#4

Quote:
Originally Posted by Celson
Посмотреть сообщение
I have created this function to display match stats after a game. It runs loops to check how many goals all players scored and it will list multiple names for a record if there is a shared record. The function itself works perfectly fine. However the more times the function is run the more parts of the script that get broken.

Commands stop working, callbacks don't get called, timers don't run anymore. After running the function multiple times eventually the whole script is completely broken and all you can do is chat and log in to the RCON.

Here is the said function:

PHP код:
public DisplayMatchStats()
{
    new 
info[256],pname[20],gname[64],tname[64],result[10],goalsScored,tackles,lastpos,Float:redPossessionPerc,Float:bluePossessionPerc;
    if(
redscore bluescoreresult "Red Wins";
    if(
bluescore redscoreresult "Blue Wins";
    if(
redscore == bluescoreresult "Draw";
    
redPossessionPerc floatround(floatmul(floatdiv(redPossession,floatadd(redPossession,bluePossession)),100));
    
bluePossessionPerc floatround(floatmul(floatdiv(bluePossession,floatadd(redPossession,bluePossession)),100));
    for(new 
i=0;i<MAX_PLAYERS;i++) // Most Goals Scored
     
{
        if(
matchGoalsScored[i] >= goalsScored && matchGoalsScored[i] > 0)
        {
            if(
matchGoalsScored[i] == goalsScored// Tied record
            
{
                
GetPlayerName(i,pname,20);
                if(
lastpos 0)
                {
                    
strins(gname,", ",lastpos);
                    
lastpos lastpos 2;
                }
                
strins(gname,pname,lastpos);
                
lastpos lastpos strlen(pname);
            }
            else 
// New record
            
{
                 
goalsScored matchGoalsScored[i];
                
strdel(gname,0,64);
                
GetPlayerName(i,pname,20);
                
strins(gname,pname,lastpos);
                
lastpos strlen(pname);
            }
        }
    }
    if(
lastpos 0)
    {
        
format(pname,20," (%i)",goalsScored);
        
strins(gname,pname,lastpos);
    }
    
lastpos 0;
    for(new 
i=0;i<MAX_PLAYERS;i++) // Most tackles
     
{
        if(
matchTackles[i] >= tackles && matchTackles[i] > 0)
        {
            if(
matchTackles[i] == tackles// Tied record
            
{
                
GetPlayerName(i,pname,20);
                if(
lastpos 0)
                {
                    
strins(tname,", ",lastpos);
                    
lastpos lastpos 2;
                }
                
strins(tname,pname,lastpos);
                
lastpos lastpos strlen(pname);
            }
            else 
// New record
            
{
                 
tackles matchTackles[i];
                
strdel(tname,0,64);
                
GetPlayerName(i,pname,20);
                
strins(tname,pname,lastpos);
                
lastpos strlen(pname);
            }
        }
    }
    if(
lastpos 0)
    {
        
format(pname,20," (%i)",tackles);
        
strins(tname,pname,lastpos);
    }
    
format(info,sizeof(info),"Score: %i-%i %s\nBall Possession: Red %.0f%s - Blue %.0f%s\nMost Goals: %s\nMost Tackles: %s",redscore,bluescore,result,redPossessionPerc,"%",bluePossessionPerc,"%",gname,tname);
    for(new 
i=0;i<MAX_PLAYERS;i++)
     {
        if(
Spawned[i]) ShowPlayerDialog(i,255,DIALOG_STYLE_MSGBOX,"Match Stats",info,"OK","");
    }

Any ideas?
and also you used I twice in a location for looping this may crash your server too but i dont think it freezez your cmds or callbacks :S just make one of for(.. from i to j
Reply
#5

I have solved the issue. I needed to put lastpos = 0; inside the 'new record' case. I don't know why but strdel was causing problems. All good now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)