Login

russian armor

Using scar to reduce VPs depending on casualties taken

25 Apr 2020, 10:24 AM
#1
avatar of host_leaver

Posts: 6

Hello,
I'm trying to make a victory condition mod that works like normal VP but reduces tickets based on losing units. This is my first attempt at modding and I've run into several issues I'd like to ask for help with.

I'm using aabattle_vptickerwin-annihilate_functions.scar as the basis for my main.scar file. I just pasted all of it in there since I couldn't get my main.scar to import another .scar file. Is that possible and if so, how? Is this a good approach?

At the moment, I'm checking the infantry lost stat every time VPTicker_MainRule() is called, but I'd like to be able to keep track of different unit types and I need some help here.
I tried the following bit of code:
local inftroops1 = EGroup_Count(Player_GetEntitiesFromType( World_GetPlayerAt(1), "infantry" ))
PrintOnScreen("Player1 has " .. inftroops1 .. " troops ")
The expected behavior is that it creates an EGroup with all the entities that have the type "infantry" owned by player 1, then counts all its members and prints the result.
The actual behavior is that it always prints 0. If I replace the part where it checks if an entity has the type "infantry" and make it just count all the entities owned by a player, the result is a number that changes depending on the number of all owned entities as I play. This leads me to believe that infantry entities don't have a type called "infantry", but that soldiers are entities, because afterwards I tried the following code:

infantryAmount = 0
squadgroup = Player_GetSquads(World_GetPlayerAt(1))
squadcount = SGroup_CountSpawned(squadgroup)

for i = 1, squadcount do
local squad = SGroup_GetSpawnedSquadAt( squadgroup, i )
for j = 0, (Squad_Count(squad)-1) do
local entity = Squad_EntityAt(squad, j)
if Entity_IsOfType(entity, "infantry") then
infantryAmount = infantryAmount + 1
end
end
end

This checks if an entity has a type "infantry". infantryamount is incremented according to the number of infantry entities I spawn in a game. The problem here is US vehicles (and I suspect garrisons in general), because entities despawn when they enter vehicles and I can't check through both spawned and despawned squads at the same time because there is no function like SGroup_GetSquad().
Is there a way to iterate through squads in an SGroup without a function?
something like: squad = someSGroup.squad[0]

Also, I don't really understand EGroups and SGroups. They're objects that can hold entity type objects, right? But SGroups can also hold squad type objects, which in turn, can hold entity objects?

tl,dr: I want to check all of a player's entities for a certain type. If I get the entities from an EGroup of all the player's entities, it doesn't work. If I get the entities from every spawned squad from an SGroup of all the player's spawned squads, it works and I don't understand why, since it's a bunch of entities in both cases.

I think the mod tools are great, but it would really help to be able to talk to someone knowledgeable about scar so... help, please?
26 Apr 2020, 20:12 PM
#2
avatar of RagnarTheGamer
Master Modmaker Badge

Posts: 317

Hey, first things first let's fix the imports. The import of the file you are trying to import should look like this:
import("Prototype/VPTickerWin-Annihilate_Functions.scar")


Now for the gamemode. To check if an entity or squad died I would advise you to use function called Rule_AddGlobalEvent(rule, eventType). As rule you should put in a function that will be executed everytime eventType is triggered. And as eventType you can put in GE_SquadKilled or GE_EntityKilled that is up to you what you chose.

For the rule function, you can use Setup_GetWinConditionOption() function that will return the number of VPs the player selected to play with. With this, you can do whatever you want your function to do. I would also recommend doing a Lua table of all entities you want to affect the VPs. In the table, you could also set for different entities different VP bleed, etc.


27 Apr 2020, 11:51 AM
#3
avatar of host_leaver

Posts: 6

Thank you for replying,
So, if I got this right, this will trigger myFunction when a squad is killed, right?
Rule_AddGlobalEvent(myFunction, GE_SquadKilled)

How do I reference the squad killed that triggers the event inside myFunction?
I assume I can then do Player_GetTeam(GetPlayerOwner(squad)), but I don't know how to reference the killed squad.
27 Apr 2020, 12:41 PM
#4
avatar of RagnarTheGamer
Master Modmaker Badge

Posts: 317

Thank you for replying,
So, if I got this right, this will trigger myFunction when a squad is killed, right?
Rule_AddGlobalEvent(myFunction, GE_SquadKilled)

Yes.

How do I reference the squad killed that triggers the event inside myFunction?
I assume I can then do Player_GetTeam(GetPlayerOwner(squad)), but I don't know how to reference the killed squad.

You use a Lua table for that for example. And then you can run an if statement to check the squad.
27 Apr 2020, 12:48 PM
#5
avatar of host_leaver

Posts: 6

Yes, but where do I get the squad that was killed so that I can check it against a table?



28 Apr 2020, 11:54 AM
#6
avatar of host_leaver

Posts: 6

Alright, I figured it out. This works:

function CheckTanksKilled(victim, killer)
if Table_Contains(t_tanklist, Squad_GetBlueprint(victim)) then
local adjustedTicker = VPTicker_GetTeamTickers(Player_GetTeam(Util_GetPlayerOwner(victim))) - 50
VPTicker_SetTeamTickers(Player_GetTeam(Util_GetPlayerOwner(victim)), math.max(adjustedTicker, 0), true)
end


Apparently, Rule_AddGlobalEvent(myFunction, GE_SquadKilled) passes 2 variables called victim and killer to myFunction. This is great, but I never would've figured it out. I assume most events pass variables like this, but is there a list somewhere?

Thanks for pointing me in the right direction!
28 Apr 2020, 15:16 PM
#7
avatar of RagnarTheGamer
Master Modmaker Badge

Posts: 317

There isn't a list as far as I know. But it will be defined somewhere in relics SCAR files.

EDIT: GE_SquadKilled -> victim, killer and GE_EntityKilled -> entity
1 user is browsing this thread: 1 guest

Ladders Top 10

  • #
    Steam Alias
    W
    L
    %
    Streak
Data provided by Relic Relic Entertainment

Replay highlight

VS
  • U.S. Forces flag cblanco ★
  • The British Forces flag 보드카 중대
  • Oberkommando West flag VonManteuffel
  • Ostheer flag Heartless Jäger
uploaded by XXxxHeartlessxxXX

Board Info

853 users are online: 853 guests
0 post in the last 24h
8 posts in the last week
34 posts in the last month
Registered members: 49113
Welcome our newest member, Dedek545
Most online: 2043 users on 29 Oct 2023, 01:04 AM