Code not working.
#1

Код:
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.
Reply
#2

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

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? :/
Reply
#4

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

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?
Reply
#6

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

Reply
#7

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.
Reply
#8

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 );
Reply
#9

Would you please tell me what do you want exactly ?
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)