I feel really bad about starting millions of threads daily with my little issues, but this has been driving me crazy. Again.
I'm using Connor's No Kill Zones plugin (a little changed so it actually contains more zones, but it's not important right now) and I'm trying to add an API to it. Two forwards and one native, to be exact. One forward which is called ONLY ONCE when a user enters the zone, one forward which is called ONLY ONCE when the user leaves the zone and a native to get the current zone, which is quite easy, though.
I'll post a picture here which could explain better exactly what I'm talking about.
Each zone has its own ID starting at 0 and each zone has some sort of type (no kill zone, trading zone, etc.). I have a function to check whether the user is in a certain zone, which works fine, however calling the forwards at the right time gives me headaches.
My current code is:
PHP Code:
// this task is called once each second. I don't want to call it in client_PreThink because that's a waste of resources which I really need to save as much as possible. Once a second is enough for me.
public _tCheckZones( )
{
new aPlayers[ 32 ], iNum, id, iZoneType, iCurrentZone
get_players( aPlayers, iNum, "a" )
for( new iCount; iCount < iNum; iCount ++ )
{
id = aPlayers[ iCount ]
// looping through all the zones
for( new i; i < g_iTotalZones; i ++ )
{
// just caching the zone type of the zone
iZoneType = g_ZoneType[ i ]
// g_iCurrentZone holds the current zone ID the player is in, you can see it later in the code
iCurrentZone = g_iCurrentZone[ id ]
//client_print( id, print_chat, "Data: i = %d, CurrentZone = %d, ZoneType = %d, CurrentZoneType = %d", i, iCurrentZone, iZoneType, iCurrentZone == -1 ? -1 : g_ZoneType[ iCurrentZone ] )
// this function works fine
if( is_user_in_zone( id, i ) )
{
// if the zone the player was in before is not the same as the one that's in the loop right now, we proceed
if( i != iCurrentZone )
{
// if the player is in no zone at all or the zone type of the new zone is different from the old zone type, we call the forward
if( iCurrentZone == -1 || iZoneType != g_ZoneType[ iCurrentZone ] )
{
new iRet
ExecuteForward( g_iForwardIds[ Forward_EnteredZone ], iRet, id, iZoneType )
}
// set the current zone to the new one
g_iCurrentZone[ id ] = i
break
}
}
// self explanatory
else if( iCurrentZone != -1 && iZoneType == g_ZoneType[ iCurrentZone ] )
{
g_iCurrentZone[ id ] = -1
new iRet
ExecuteForward( g_iForwardIds[ Forward_LeftZone ], iRet, id, iZoneType )
}
}
}
}
The forward should only be called when the user enters a new zone type, not zone ID. So if there are two zones with the same type next to each other, no forward should be called when going from one to the other one.
The problem with my code is that both the forwards are being called all the time when I'm in a zone (probably only when there are 2 or more zones of the same type but I didn't test this). My guess is that once the player enters the zone, the forward gets called, but then the other zone from the loop with the zame zone type passes and it thinks the player has left it.
Can anyone give me a logical example of how to get around this? Pretty please?
__________________
Currently busy working on a very large scale anime database project.