You set a sound flag to activate sound one time, and then turn it off like this;
"playingsound = 1"
Now, you just needed a similar approach to modulate the character when approaching,
"approachplr[e] = 1"
and shuffle a few lines around to suit
So, in the end, it should look like this;
..........................................................................................
local approachplr = {}
local playingsound = {}
function npc_approaching2_init(e)
CharacterControlUnarmed(e)
approachplr[e] = 0
playingsound[e] = 0
end -- init
function npc_approaching2_main(e)
PlayerDist = GetPlayerDistance(e)
if GetPlayerDistance(e) < 600 and GetPlayerDistance(e) > 200 and approachplr[e] == 0 then
LookAtPlayer(e)
RotateToPlayer(e)
SetCharacterToWalk(e) -- new edit
AIEntityGoToPosition(g_Entity[e]['obj'],g_PlayerPosX,g_PlayerPosZ) -- new eidt
approachplr[e] = 1
end
if approachplr[e] == 1 then
if GetPlayerDistance(e) < 200 then
Prompt("Hello, how may I help you?", 5000)
AIEntityStop(g_Entity[e]['obj'])
StopAnimation(e)
approachplr[e] = 0
if playingsound[e] == 0 then
PlaySound(e,1);
playingsound[e] = 1
end
end
end
end -- main