Das Array um den nächsten NPC zu speichern brauchst du eigentlich nicht.
Starte bei OnGameModeInit den Timer:
SetTimer("CheckNPCBubble", 1000, true);
Und dann das public dazu:
forward CheckNPCBubble();
public CheckNPCBubble()
{
new Float:x, Float:y, Float:z, str[145];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
new Float:dist = 10.0, Float:tmp, id = -1; //10.0 = maximaler Abstand
for(new n = 0; n < sizeof(NPCID); n++)
{
if(!IsPlayerNPC(NPCID[n])) continue;
GetPlayerPos(NPCID[n], x, y, z);
tmp = GetPlayerDistanceFromPoint(playerid, x, y, z);
if(tmp < dist)
{
dist = tmp;
id = n;
}
}
if(id != -1)
{
GetPlayerName(playerid, str, MAX_PLAYER_NAME);
format(str, sizeof(str), "Hallo %s!", str);
SetPlayerChatBubble(NPCID[id], str, 0xFFFFFFFF, 10.0, 10000);
//Gegebenenfalls kannst du hier dann einen switch machen, über die id,
//damit du weißt, welcher NPC das ist und so entsprechende
//Texte ausgeben kannst, für jeden NPC unterschiedlich.
}
}
return 1;
}
Alles anzeigen
Falls alle NPCs in der Nähe eine Nachricht ausgeben sollen, und nicht nur der nächste, dann so:
forward CheckNPCBubble();
public CheckNPCBubble()
{
new Float:x, Float:y, Float:z, str[145];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
for(new n = 0; n < sizeof(NPCID); n++)
{
if(!IsPlayerNPC(NPCID[n])) continue;
GetPlayerPos(NPCID[n], x, y, z);
if(!IsPlayerInRangeOfPoint(playerid, 10.0, x, y, z)) continue;
GetPlayerName(playerid, str, MAX_PLAYER_NAME);
format(str, sizeof(str), "Hallo %s!", str);
SetPlayerChatBubble(NPCID[id], str, 0xFFFFFFFF, 10.0, 10000);
//Gegebenenfalls kannst du hier dann einen switch machen, über die id,
//damit du weißt, welcher NPC das ist und so entsprechende
//Texte ausgeben kannst, für jeden NPC unterschiedlich.
}
}
return 1;
}
Alles anzeigen