Raised This Month: $51 Target: $400
 12% 

Player entering a zone


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-01-2014 , 15:38   Player entering a zone
Reply With Quote #1

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 
aPlayers32 ], iNumidiZoneTypeiCurrentZone
    get_players
aPlayersiNum"a" )
    
    for( new 
iCountiCount iNumiCount ++ )
    {
        
id aPlayersiCount ]
        
        
// looping through all the zones
        
for( new ig_iTotalZones++ )
        {    
            
// just caching the zone type of the zone
            
iZoneType g_ZoneType]
            
// g_iCurrentZone holds the current zone ID the player is in, you can see it later in the code
            
iCurrentZone g_iCurrentZoneid ]
        
            
//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_zoneid) )
            {
                
// 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( != 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 == -|| iZoneType != g_ZoneTypeiCurrentZone ] )
                    {
                        new 
iRet
                        ExecuteForward
g_iForwardIdsForward_EnteredZone ], iRetidiZoneType )
                    }
                    
// set the current zone to the new one
                    
g_iCurrentZoneid ] = i
                    
                    
break
                }
            }
            
// self explanatory
            
else if( iCurrentZone != -&& iZoneType == g_ZoneTypeiCurrentZone ] )
            {
                
g_iCurrentZoneid ] = -1
                
                
new iRet
                ExecuteForward
g_iForwardIdsForward_LeftZone ], iRetidiZoneType )
            }
        }
    }

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.
Backstabnoob is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode