ProcessTick
#7

Quote:
Originally Posted by snoob
Посмотреть сообщение
Hi all
Lets say in ProcessTick() I have a condition that would call a callback
Код:
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick()
{
   if(blah == something)
   {
	cell amx_Ret;
	int amx_Idx;

	if(amx_FindPublic(ThatAMX, "OnSnoobIsLost", &amx_Idx) == AMX_ERR_NONE) 
	{
		amx_Exec(ThatAMX,&amx_Ret,amx_Idx);
	}
   }
}
How can one loop thru all the Abstract Machine? (ThatAMX)

Thank you.
You need to use AmxLoad and AmxUnloac to construct a list of all the abstract machines:
pawn Код:
vector          <AMX *>                         amx_list;
PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx )
{
    amx_list.push_back(amx);
    return amx_Register( amx, AMXNatives, -1 );
}

PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx )
{
    std::vector<AMX *>::iterator i = amx_list.begin();
    while (i != amx_list.end())
    {
        i = amx_list.erase(i);
    }
    return AMX_ERR_NONE;
}
//edit: I think I see a bug in my snippet, probably it should be, anyone confirm?:
PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx )
{
    std::vector<AMX *>::iterator i = amx_list.begin();
    while (i != amx_list.end())
    {
        if(amx == amx_list.at(i))amx_list.erase(i);
        ++i;
    }
    return AMX_ERR_NONE;
}
then you can loop them in different ways, I do this like:
pawn Код:
PLUGIN_EXPORT void PLUGIN_CALL
    ProcessTick()
{
    if(g_Ticked == g_TickMax)
    {
        if(!locked.passer)//try another time if locked, won't lagg the server, while(true) {} would
        {
            locked.passer = true;
            if(!PassVector.empty())
            {
                cell amx_addr = NULL;
                cell * amx_physAddr = NULL;
                int ptr;
                for (std::vector<AMX *>::iterator a = amx_list.begin(); a != amx_list.end(); ++a)
                {
                    if (!amx_FindPublic(* a, "GPS_WhenRouteIsCalculated", &ptr) && PassVector.front().script == *a)
                    {
                        amx_Push(* a, PassVector.front().MoveCost);
                        amx_Push(* a, PassVector.front().amount_of_nodes);
                        amx_PushArray(* a, &amx_addr, &amx_physAddr, PassVector.front().Paths, 1792);
                        amx_Push(* a, PassVector.front().extraid);
                        amx_Exec(* a, NULL, ptr);
                        amx_Release(* a,amx_addr);
                    }
                }
                PassVector.pop();
            }
            locked.passer = false;
        }
    }
}
(Code snippet from RouteConnector plugin)
Reply


Messages In This Thread
ProcessTick - by Scottas - 07.09.2011, 19:01
Re: ProcessTick - by Gamer_Z - 07.09.2011, 19:43
Re: ProcessTick - by Tony_Montana - 07.09.2011, 21:19
Re: ProcessTick - by Scottas - 08.09.2011, 06:58
Re: ProcessTick - by Gamer_Z - 08.09.2011, 13:31
Re: ProcessTick - by snoob - 24.02.2012, 00:08
Re: ProcessTick - by Gamer_Z - 24.02.2012, 15:12
Re: ProcessTick - by T0pAz - 24.02.2012, 15:16
Re: ProcessTick - by RyDeR` - 24.02.2012, 17:09
Re: ProcessTick - by Gamer_Z - 24.02.2012, 18:32
Re: ProcessTick - by snoob - 24.02.2012, 23:07
Re: ProcessTick - by Gamer_Z - 27.02.2012, 14:50
Re: ProcessTick - by Gamer_Z - 27.02.2012, 15:23
Re: ProcessTick - by Gamer_Z - 27.02.2012, 16:17

Forum Jump:


Users browsing this thread: 1 Guest(s)