29.09.2017, 06:32
Simple random player in range and if npc see player.
Libs:
3DTryg
PHP Code:
stock GetTarget(npcid){
new Float:x, Float:y, Float:z, Float:angle, pstate,
pool_players[MAX_PLAYERS], pool_upp = -1;
FCNPC_GetPosition(npcid,x,y,z);
angle = FCNPC_GetAngle(npcid);
Tryg3D::Foreach(i){
pstate = GetPlayerState(i);
if(GetElementsDistance(i,item_player,npcid,item_fcnpc) <= 300.0 && GetPlayerInterior(i) == 0 && GetPlayerVirtualWorld(i) == 0){
if(pstate != PLAYER_STATE_SPECTATING && pstate != PLAYER_STATE_WASTED){
if(IsElementOnFakeScreen(x,y,z,i,item_player,0.0,angle)){ //for vehicle collision: .veh_col=true
pool_upp++;
pool_players[pool_upp] = i;
}
}
}
}
if(pool_upp == -1) return INVALID_PLAYER_ID;
return pool_players[random(pool_upp+1)];
}
3DTryg