string gun_target = "";
void OnStart()
{
//Player & Items
SetSanityDrainDisabled(true);
GiveItemFromFile("lantern", "lantern.ent");
//SetLanternActive(true, true);
//Variables
AddLocalVarInt("AmmoCounter", 50); // Amount of munition
AddLocalVarInt("MonsterSelection", 0); // With this variable you select the monster you want to give damage
AddLocalVarInt("MonsterHitCounter_1", 0);//Hitcounter for monster A. One for each monster
//LookAtCallbacks ..... One Callback for each enemy !
SetEntityPlayerLookAtCallback("gun_target_1", "SetGunTarget_1", false);
SetEntityPlayerLookAtCallback("gun_target_2", "SetGunTarget_2", false);
SetLanternLitCallback("FireGun");
}
void SetGunTarget_1(string &in entity, int state)
{
gun_target = (state == 1) ? entity : "";
SetLocalVarInt("MonsterSelection", 1);
}
void SetGunTarget_2(string &in entity, int state)
{
gun_target = (state == 1) ? entity : "";
SetLocalVarInt("MonsterSelection", 2);
}
//Shooting Script
void FireGun(bool lit)
{
if(GetLocalVarInt("AmmoCounter")>0){
if (gun_target != "")
{
//SetPropActiveAndFade(gun_target, false, 1);
PlaySoundAtEntity("","gun_fire.snt", "Player", 0, false);
gun_target = "";
SetMessage("Messages", "Hit", 1);
SetLocalVarInt("AmmoCounter", GetLocalVarInt("AmmoCounter")-1);
switch( GetLocalVarInt("MonsterSelection") )
{
case 1:
SetLocalVarInt("MonsterHitCounter_1", GetLocalVarInt("MonsterHitCounter_1")+1);
break;
case 2:
SetLocalVarInt("MonsterHitCounter_2", GetLocalVarInt("MonsterHitCounter_2")+1);
break;
}
for (int i = 1; GetEntityExists("gun_target_"+i); ++i){
if(GetLocalVarInt("MonsterHitCounter_"+i)==4){
FadeEnemyToSmoke("gun_target_"+i, false);
}
}
}
else
SetMessage("Messages", "Miss", 1);
PlaySoundAtEntity("","gun_fire.snt", "Player", 0, false);
SetLocalVarInt("AmmoCounter", GetLocalVarInt("AmmoCounter")-1);
}
else
SetMessage("Messages", "Empty", 1);
PlaySoundAtEntity("","empty.snt", "Player", 0, false);
if (!GetLanternActive())
{
SetLanternLitCallback("");
SetLanternActive(true, true);
SetLanternLitCallback("FireGun");
}
}