Quantcast
Channel: SA-MP Forums
Viewing all articles
Browse latest Browse all 18226

This function is breaking my script

$
0
0
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 Code:

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?

Viewing all articles
Browse latest Browse all 18226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>