string gun_target = "";
void OnStart()
{
//Player
SetSanityDrainDisabled(true);
//Shooting Script
AddLocalVarInt("AmmoCounter", 15); // Amount of munition
GiveItemFromFile("lantern", "lantern.ent");
for (int i = 1; GetEntityExists("gun_target_"+i); ++i){
SetEntityPlayerLookAtCallback("gun_target_"+i, "SetGunTarget", false);
AddLocalVarInt("HitCounter_"+i+"", 0);
}
SetLanternLitCallback("FireGun");
}
void SetGunTarget(string &in entity, int state)
{
gun_target = (state == 1) ? entity : "";
}
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);
}
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");
}
}
Now with munitioncounter !