Skip to content
User Avatar
#3520
Auto-translated
Azgalor.
for e, enemy in enemy_creatures do
      for f, friend in friend_creatures do
	 if GetHeroCreatures(heroes, enemy) > 0 and GetHeroCreatures(heroes, enemy) <= 99 then
         reputation = reputation - 1
         sleep(1)
         elseif GetHeroCreatures(heroes, enemy) >= 100 then
         reputation = reputation - 2
         sleep(1)
	 elseif GetHeroCreatures(heroes, friend) > 0 then
         reputation = reputation + 1
            end
         end
      end
end

Let's go through it together with a counter. The first iteration of the e, enemy in enemy creatures loop. In it - a loop of 21 iterations (the inner loop f, friend in friend_creatures). The check for the presence of evil creatures takes place inside the inner loop, sorry for the tautology. This means that if there is 1 creature from the "evil" ones, it will perform the same check 21 times until the inner loop ends! That is, for 1 evil creature, as much as 21 reputation is deducted smile Hence, other funny things happen. The solution is that the loops should not be nested, but separate (I think you don't need to show how to separate them; check for evil creatures in the evil loop for, check for good ones - in the good loop for).

There is also a more elegant solution. First, let's create a global table "reputation", through which we will link all variables and tables. Let's put all IDs into one table with named fields:

reputation = {}
reputation.heroes = {'Valeria', 'Laslo'}
reputation.value = 1--Reputation value
reputation.creatures = {
[1] = {id = 1, mode = 'good', rep_decline = {['<100'] = +1, ['>100'] = +2},},
[2] = {id = 2, mode = 'good', rep_decline = {['<100'] = +1, ['>100'] = +2},},
[3] = {id = 101, mode = 'bad', rep_decline = {['<100'] = -1, ['>100'] = -2},},
[4] = {id = 114, mode = 'bad', rep_decline = {['<100'] = -1, ['>100'] = -2},},
[5] = {id = 98, mode = 'bad', rep_decline = {['<100'] = -1, ['>100'] = -2},},
--And so on
}

This way, we can vary the impact on reputation for each individual creature.

function reputation.condition()
for n, hero in reputation.heroes do
  for key, cr_properties in reputation.creatures do
     if GetHeroCreatures(hero, cr_properties.id)>0 and GetHeroCreatures(hero, cr_properties.id)<100 then
       reputation.value = reputation.value + cr_properties.rep_decline['<100']
     elseif GetHeroCreatures(hero, cr_properties.id)>100 then
       reputation.value = reputation.value + cr_properties.rep_decline['>100']
     end
  end
end

With this solution, you don't even need the "good/bad" field, but for clarity, let it be present. Accordingly, through the global table reputation, we create a table of the impact on the reputation of visiting buildings (in the same way); we write a function for triggers that affect all these objects. The keys in the building table fields will not be 1, 2, 3, etc., as above, but the names of the buildings.

reputation.buildings = {
['BuildingName1'] = {rep_decline = +100},
['BuildingName2'] = {rep_decline = -200},
['BuildingName3'] = {rep_decline = +55},
--And so on
}

function reputation.buildings_visit(hero,obj)
  reputation.value = reputation.value + reputation.buildings[obj].rep_decline
end

function reputation.building_triggers()
  for name, prop in reputation.buildings do
    Trigger(OBJECT_TOUCH_TRIGGER, name, 'reputation.buildings_visit')
  end
end

--Let's not forget to call the "hanging" of triggers. It will go automatically for all objects specified in the table
reputation.building_triggers()

Such global tables are needed so that when there are large volumes of scripts, the names of variables do not intersect. If you wish, you can absolutely erase the lines reputation. everywhere above, and everything will work.

С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________

Statistics

Welcome our newest member: leyu