SA-MP Forums Archive
Code not working. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Code not working. (/showthread.php?tid=645002)



Code not working. - Ritzy2K - 18.11.2017

Код:
stock OwnedTurfs2( teamid )
{
    new turf;
    for (new i = 0; i < MAX_TURFS; i++) if (turfs[ i ][TurfOwner] == teamid) TeamInfo[ teamid ][ TeamTurfs ] = 0,TeamInfo[ teamid ][ TeamTurfs ]++;
    return turf;
}
This is supposed to tell the turfs owned by specific team. It compiles perfectly but doesn't work.


Re: Code not working. - Sithis - 18.11.2017

Your loop code is a mess. How are you calling this function? What is the code supposed to do?


Re: Code not working. - Ritzy2K - 18.11.2017

This functions is being called through a loop where its supposed to show the turf owned by respective teams.

Edit: Can no one help me out? :/


Re: Code not working. - Juvanii - 18.11.2017

Your function will always return 0 as there is no changes on the variable 'turf' on the loop !


Re: Code not working. - Ritzy2K - 18.11.2017

Quote:
Originally Posted by Juvanii
Посмотреть сообщение
Your function will always return 0 as there is no changes on the variable 'turf' on the loop !
Isn't that loop looping and updating the turf's value and then returning it for further use?


Re: Code not working. - Juvanii - 18.11.2017

Quote:
Originally Posted by Ritzy
Посмотреть сообщение
Isn't that loop looping and updating the turf's value and then returning it for further use?
PHP код:
stock OwnedTurfs2(teamid//calling the function with a team id
{
    new 
turf//new variable 'turf' which has a value of 0
    
for (new 0MAX_TURFSi++) //looping from 0 to max turfs number
    
{
        if(
turfs[i][TurfOwner] == teamid//if the loop found that turf owner = teamid (i really don't know how would an owner name will equal a number)
        
{
            
TeamInfo[teamid][ TeamTurfs ] = // reseting team turfs to 0
            
TeamInfo[teamid][ TeamTurfs ]++; // add +1 to team turfs after resetting it to 0 (which make no sense)
        
}
    }
    return 
turf//return 0 which is variable 'turf' as u havent change the value of it




Re: Code not working. - Ritzy2K - 18.11.2017

Quote:
Originally Posted by Juvanii
Посмотреть сообщение
PHP код:
stock OwnedTurfs2(teamid//calling the function with a team id
{
    new 
turf//new variable 'turf' which has a value of 0
    
for (new 0MAX_TURFSi++) //looping from 0 to max turfs number
    
{
        if(
turfs[i][TurfOwner] == teamid//if the loop found that turf owner = teamid (i really don't know how would an owner name will equal a number)
        
{
            
TeamInfo[teamid][ TeamTurfs ] = // reseting team turfs to 0
            
TeamInfo[teamid][ TeamTurfs ]++; // add +1 to team turfs after resetting it to 0 (which make no sense)
        
}
    }
    return 
turf//return 0 which is variable 'turf' as u havent change the value of it

(This loop isn't written by me, I'm trying to fix a really buggy gamemode.)

PHP код:
stock OwnedTurfs2(teamid//calling the function with a team id
{
    new 
turf//new variable 'turf' which has a value of 0
    
for (new 0MAX_TURFSi++) //looping from 0 to max turfs number
    
{
        if(
turfs[i][TurfOwner] == teamid//if the loop found that turf owner = teamid (i really don't know how would an owner name will equal a number)
        
{
            
TeamInfo[teamid][ TeamTurfs ]++; // add +1 to team turfs after resetting it to 0 (which make no sense)
        
}
    }
    return 
turf//return 0 which is variable 'turf' as u havent change the value of it

I removed the part where the turfs were getting set to 0 over and over, and now the loop isn't stopping and is running over and over and the number of turfs owned by a team is getting increased by a fuckton of times.


Re: Code not working. - Ritzy2K - 18.11.2017

The script is calling this loop in a timer which is called every 0.3 seconds -
Код:
for (new teams=0; teams<MAX_TEAMS; teams++) OwnedTurfs2( teams );



Re: Code not working. - Juvanii - 18.11.2017

Would you please tell me what do you want exactly ?


Re: Code not working. - Ritzy2K - 18.11.2017

Okay, Okay see.
The function OwnedTurfs2 is supposed to loop through the turfs and return the turf value, so that it can be used.

Here, this part of code -
Код:
for (new teams=0; teams<MAX_TEAMS; teams++) OwnedTurfs2( teams );
This loop is assigned under a function which is being called every 0.3 seconds to update the textdraw which shows total players in team and turfs owned etc.

Edit: I forgot to tell that TurfOwner variable is Integer.