Jump to content


BloodyVomit

Member Since 03 Oct 2019
Offline Last Active Aug 09 2020 07:59 PM

Posts I've Made

In Topic: Scar script questions

13 December 2019 - 11:19 AM

Oh, internet issues prevent me to notify that I have already done it by slightly modifying Player_GetBlueprintCount function.

 

@Gambit, thanks man, but your code counts all complited buildings, but I needed specific, namely necron generators.

 

Here is my code (not actually my, 99% of it is relic code):

function Player_HasNumberOfBuildingsType( player, blueprintname )
	local CountBlueprints = function(groupCaller, groupID)
		local blueprintCount = 0
		local Counter = function(groupID, itemIndex, itemID)
			if (groupCaller.GetItemBlueprint(itemID) == blueprintname) then
				if Entity_IsBuilding(itemID) and Entity_GetBuildingProgress(itemID) >= 1.0 then
					blueprintCount = blueprintCount + 1
				end
			end
			return true
		end
		groupCaller.ForEachAllOrAny(groupID, true, Counter)
		return blueprintCount
	end
	if( EBP_Exists( blueprintname ) ) then
		-- count entity blueprints
		return CountBlueprints( EGroupCaller, Player_GetEntities( player ) )
	end
	error("Invalid blueprint name "..blueprintname )
end

In Topic: Scar script questions

13 December 2019 - 03:12 AM

Another day - another problem. Not really a problem, but a good question. I need to check how many of certain fully constructed buildings a player has. Unfortunately, relic didn't include a function for that, however they included two others functions: 

Player_GetBuildingsCountOnly - counts the number of buildings owned by player, however building can be not complited

Player_HasBuildingType - finds if this player owns any of the indicated building type and they are fully constructed, but it returns boolean, so only one building will trigger it

I have tryed to combine this two functions in one or even created a new one, but failed. Maybe someone of you have already resolved such problems or can help me with it?


In Topic: Scar script questions

25 November 2019 - 11:22 AM

I understand, that my code is not good, that's why I ask for help. Just show it right from the SCAR to ensure you understand what I mean. Your variation is better, because it doesn't need second array and any cycles. Actually, I have never worked with Lua before, so I have taken the code from another campaigns SCARs and change it a little for my needs.


In Topic: Scar script questions

25 November 2019 - 02:09 AM

I understand your idea and maybe it's better than mine. But still I post it, as it doesn't require rewriting the array of intel events\

'Rule_MissionStart is called from OnInit after starting NIS is played'
function Rule_MissionStart()
 if not Event_IsAnyRunning() then
  'Here I create 2 tables, first for intel events, second for check is it played or not'
  t_RandomIE ={EVENTS.IE_RandomNIS1, 'and so on, 10 talks in summ'}
  t_RandomIEPlayed = {false, false, false, false, false, false, false, false, false, false}
  'Activate the repeating random talks'
  Rule_AddInterval(Rule_RandomIE, 30)
 end
end
​
function Rule_RandomIE()
 'Check for no other events'
 if Event_IsAnyRunning() == false then
  'Start cycle at least one time'
  repeat
   'Change variable until we find one that was not played. g_random is a variable from OnGameSetup'
   g_random = World_GetRand(1, 10)
  until t_RandomIEPlayed[g_random] == false
  'Play the event from the top table with the number given from the cycle'
  Util_StartIntel(t_RandomIE[g_random])
  'Mark this event played'
  t_RandomIEPlayed[g_random] = true
  'This is a variable from OnGameSetup. It will stop this rule if all events are already played'
  g_random_ie_counter = g_random_ie_counter + 1
 end
 'There is actual stop. If we played 10 events we will stuck in infinite loop in repeat-until 
 So we need to stop the rule to prevent infinite loop
 The rule is stopped on the tenth time of being executed, so no need to create conditions in the start of the rule'
 if g_random_ie_counter == 10 then
  Rule_Remove(Rule_RandomIE)
 end
end

In Topic: Scar script questions

24 November 2019 - 12:33 PM

I can explain. I use cycles to create random unrepeatable talks every 30 seconds. The map is pretty short, so I want to use as more intel events as possible. But if random will choose same number 2 times in a row the script will skip whole code and no intel event for 60 seconds. So I want to use cycles to reroll random number of intel event.
While I was writing the comment I understood what mistake I had made and how to improve my code. Just need some conditions with breaks inside the repeat-until