24.02.2012, 15:12
Quote:
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); } } } Thank you. |
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;
}
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;
}
}
}