local shot_taken = {} local shot_delay = {} local is_hit = {} local plr_damage = {} eye_pox = {} local entity_tracker = {} local sound_ricochet = {} local sound_fire = {} local hit_chance = {} local fakex = {} local fakey = {} local fakez = {} local fnpcy = {} -- object to npc angle local obstacle = {} npc_alerted = {} local some_time = {} -- must wait a tad before we acivate when we interact with other entities.... function EntityLookingAtPlayer(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3800 end if v == nil then v = 32 end local destx = g_PlayerPosX - GetEntityPositionX ( e ) local destz = g_PlayerPosZ - GetEntityPositionZ ( e ) if math.sqrt((destx*destx)+(destz*destz)) <= dis then local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if ( L < R ) and ( GetEntityAngleY ( e ) > L and GetEntityAngleY ( e ) < R ) then return 1 elseif ( L > R ) and ( GetEntityAngleY ( e ) > L or GetEntityAngleY ( e ) < R ) then return 1 else return 0 end else return 0 end -- distance check end -- entity exists // e > 0 end -- function object looking at player function fake_news5_init(e) ------------ You will set the NPC entity # here (below) \/ entity_tracker[e] = 3 -- EXAMPLE: entity_tracker[e] = 16 shot_taken[e] = 0 shot_delay[e] = math.random(150, 450) is_hit[e] = 0 plr_damage[e] = 0 eye_pox[e] = 0 hit_chance[e] = 0 sound_ricochet[e] = 0 sound_fire[e] = 1 some_time[e] = 0 obstacle[e] = 0 npc_alerted[e] = 0 fnpcy[e] = 0 CollisionOff(e) -- Hide(e) -- make active after testing... math.randomseed( os.time() ) end -- init function fake_news5_main(e) if some_time[e] < 9 then some_time[e] = some_time[e] + 1 return end fakex[e], fakey[e], fakez[e], _, fnpcy[e], _ = GetEntityPosAng( entity_tracker[e] ) SetPosition(e, fakex[e], fakey[e], fakez[e]) ResetPosition(e, fakex[e], fakey[e], fakez[e]) SetRotation(e, 0, fnpcy[e], 0 ) ResetRotation(e, 0, fnpcy[e], 0 ) eye_pox[e] = math.floor( GetPlayerDistance(e) ) npc_alerted[e] = EntityLookingAtPlayer(e, eye_pox[e]+5, 32) Text(11,30,1,"npc alerted; "..npc_alerted[e] ) hit_chance[e] = 100 - (math.floor ( eye_pox[e] / 50 ) ) Text(11,14,1, "plrdist; "..eye_pox[e]) Text(11,17,1, "hit chance; "..hit_chance[e] ) Text(11,20,1, "is_hit; "..is_hit[e] ) Text(11,23,1, "obstacle; "..obstacle[e] ) if npc_alerted[e] == 1 then obstacle[e] = IntersectAll(fakex[e], fakey[e]+40, fakez[e], g_PlayerPosX, g_PlayerPosY+30, g_PlayerPosZ, g_Entity[entity_tracker[e]]['obj'] ) if obstacle[e] == 0 then -- can't shoot if obstacle if eye_pox[e] < 3872 then -- close enough to try... // you can modify to any distance // if shot_taken[e] == 0 then shot_delay[e] = shot_delay[e] - 1 Text(11,11,1, "delay; "..shot_delay[e] ) if shot_delay[e] < 190 then Text(50,50,3, "Yo someone just shot at us!!" ) if is_hit[e] <= hit_chance[e] then Text(50,53,3, "We where hit with "..plr_damage[e].." in damage! " ) end -- shot hits player if is_hit[e] > hit_chance[e] then Text(50,53,3, "Luckily they missed! " ) end -- shot misses player Text(50,56,3, "Where did it come from?!" ) end if shot_delay[e] < 1 then shot_taken[e] = 1 shot_delay[e] = math.random(250, 450) is_hit[e] = math.random(1, 100) plr_damage[e] = math.random(5, 12) * 5 -- (25-65) end end if shot_taken[e] == 1 then shot_taken[e] = 0 --------- You will injure player here if is_hit[e] <= hit_chance[e] then HurtPlayer(e, plr_damage[e]) end -- shot hits player --------- You will play a shot sound here (bang and / or ricochet ) --[[ SetSoundVolume(hit_chance[e]) PlaySound(e, sound_fire[e] ) if is_hit[e] > hit_chance[e] then SetSoundVolume(100) PlaySound(e, sound_ricochet[e] ) end --]] end -- shot taken = 1 end -- eye_pox = good distance end -- no obstacles end -- looking at player // npc_alerted[e] = 1 end -- main