Let's upgrade NPCs, a Demo Script.

Post » Sat May 26, 2012 12:23 am

The idea is to retain the meaning of faction and disposition, but also leave it up to an NPC's competency to recognize the player before attacking the player as an enemy. The npc does not have any factions listed for it, if it did it would autoaggro.

scn AwarenessTestScriptshort sDoOnceshort sIntelligenceshort sPerceptionshort sLuckshort sProximityfloat fDistancefloat fRankshort sGuessesfloat fRawRecognitionshort sRandValshort sAllowedErrorshort sProportionshort sReactionshort sGuessCountfloat fActivateRangefloat fPerceptionBonusBegin GameMode	if (sDoOnce == 0)		set sDoOnce to 1		set fRank to 1.0		set sIntelligence to GetActorValue Intelligence		set sIntelligence to sIntelligence / 2		set sPerception to GetActorValue Perception		set sPerception to sPerception / 2		set sLuck to GetActorValue Luck		set sLuck to sLuck / 2		set sGuesses to  ((((sIntelligence * 10) + (sPerception * 10) + (sLuck * 10)) / 3) * fRank) / 10		set sAllowedError to 10		SetAlert 0		set fActivateRange to 150.0		set fPerceptionBonus to sPerception * (100 / 2)		set fActivateRange to fActivateRange + fPerceptionBonus	endif	set sProximity to GetInSameCell player	set fDistance to GetDistance player	if (sProximity == 1 && fDistance <= fActivateRange && sGuesses > 0)		set fRawRecognition to  ((((sIntelligence * 10) + (sPerception * 10) + (sLuck * 10)) / 3) * fRank)		set sRandVal to (1 + (GetRandomPercent * fRawRecognition / 100))		set sRandVal to fRawRecognition + GetRandomPercent * (100-fRawRecognition+1) / 100		set sProportion to (100 - sRandVal)		if (sProportion <= sAllowedError)			SetAlert 1			SetActorAlpha 0.5			player.SetActorAlpha 0.5			set sGuesses to 0			set sReaction to GetFactionReaction AiAwareFaction PlayerFaction			if (sReaction < 0)				RemoveScriptPackage				AddScriptPackage AiAwareAmbushPackage				EvaluatePackage			endif		endif		set sGuesses to sGuesses - 1		set sGuessCount to sGuessCount + 1	endif	if (sProximity == 0 && fDistance >= fActivateRange)		SetAlert 0		SetActorAlpha 1		player.SetActorAlpha 1	endif	if (sProximity == 0 && sGuesses <= 0 && fDistance >= fActivateRange)		set sGuesses to  ((((sIntelligence * 10) + (sPerception * 10) + (sLuck * 10)) / 3) * fRank) / 10	endif	if (sGuessCount >= 10)		set sReaction to GetFactionReaction AiAwareFaction PlayerFaction		if (sReaction < 0)			RemoveScriptPackage			AddScriptPackage AiAwareAmbushPackage			EvaluatePackage		endif		set sGuessCount to 0	endifEnd

updated. going to test it again .
User avatar
Ron
 
Posts: 3408
Joined: Tue Jan 16, 2007 4:34 am

Post » Fri May 25, 2012 9:43 pm

Ok so I am not sure how well this works. But now I am using the agility stat to delay the npc before it actually is told to ambush. its 1/ agility. higher the agility the smaller the delay.
I also added a delay to its guessing process.

scn AwarenessTestScriptshort sDoOnceshort sIntelligenceshort sPerceptionshort sLuckshort sProximityfloat fDistancefloat fRankshort sGuessesfloat fRawRecognitionshort sRandValshort sAllowedErrorshort sProportionshort sReactionshort sGuessCountfloat fActivateRangefloat fPerceptionBonusshort sAgilityfloat fTimerDelayBegin GameMode    if (sDoOnce == 0)        set sDoOnce to 1        set sAgility to GetActorValue Agility        set fRank to 1.0        set sIntelligence to GetActorValue Intelligence        set sIntelligence to sIntelligence / 2        set sPerception to GetActorValue Perception        set sPerception to sPerception / 2        set sLuck to GetActorValue Luck        set sLuck to sLuck / 2        set sGuesses to  ((((sIntelligence * 10) + (sPerception * 10) + (sLuck * 10)) / 3) * fRank) / 10        set sAllowedError to 10        SetAlert 0        set fActivateRange to 150.0        set fPerceptionBonus to sPerception * (100 / 2)        set fActivateRange to fActivateRange + fPerceptionBonus    endif    set sProximity to GetInSameCell player    set fDistance to GetDistance player    if (sProximity == 1 && fDistance <= fActivateRange && sGuesses > 0 && fTimerDelay <= 0)        set fRawRecognition to  ((((sIntelligence * 10) + (sPerception * 10) + (sLuck * 10)) / 3) * fRank)        set sRandVal to (1 + (GetRandomPercent * fRawRecognition / 100))        set sRandVal to fRawRecognition + GetRandomPercent * (100-fRawRecognition+1) / 100        set sProportion to (100 - sRandVal)        if (sProportion <= sAllowedError)            SetAlert 1            SetActorAlpha 0.5            player.SetActorAlpha 0.5            set sGuesses to 0            set fTimerDelay to 1 / sAgility            set sReaction to GetFactionReaction AiAwareFaction PlayerFaction        endif        set sGuesses to sGuesses - 1        set sGuessCount to sGuessCount + 1        set fTimerDelay to 1    endif    if (sProximity == 0 && fDistance >= fActivateRange)        SetAlert 0        SetActorAlpha 1        player.SetActorAlpha 1    endif    if (sProximity == 0 && sGuesses <= 0 && fDistance >= fActivateRange)        set sGuesses to  ((((sIntelligence * 10) + (sPerception * 10) + (sLuck * 10)) / 3) * fRank) / 10    endif    if (sGuessCount >= 10)        set sReaction to GetFactionReaction AiAwareFaction PlayerFaction        if (sReaction < 0)            RemoveScriptPackage            AddScriptPackage AiAwareAmbushPackage            EvaluatePackage        endif        set sGuessCount to 0    endif    if (sReaction < 0 && fTimerDelay <= 0)        RemoveScriptPackage        AddScriptPackage AiAwareAmbushPackage        EvaluatePackage        set sReaction to 0    endif    if (fTimerDelay > 0)        set fTimerDelay to fTimerDelay - GetSecondsPassed    endifEnd
User avatar
Wanda Maximoff
 
Posts: 3493
Joined: Mon Jun 12, 2006 7:05 am


Return to Fallout 3