Login

russian armor

Nil value on SGroup_IsUnderAttack and Entity_Kill()

14 May 2019, 07:10 AM
#1
avatar of jcbarth

Posts: 24

I'm trying to recreate the Civilian Rescue objective from the first mission of the campaign. I've extracted the .scar file from the mission and have been following how it was set up for the game, however, when I try to run a SGroup_IsUnderAttack check on my civilian SGroup or try to kill some members of the squad using Entity_Kill I receive the following error message:

SCAR ERROR Callstack: 
Lua city_centre_2.scar"] Ln 438 (_BonusObjective_Civs_Timer)
23:32:53.48 GameObj::OnFatalScarError: [[string "DATA:Scenarios\city_centre_2.scar"]:438: attempt to call global 'Entity_kill' (a nil value)]


Here's my current code (note: I removed the SGroup_IsUnderAttack, but receive the same error with Entity_Kill):

function _BonusObjective_Civs_Init()

-- Start civilian rescue bonus objective
Objective_Start(OBJ_Bonus_Civilians)

-- Set up up encounters
Rule_AddDelayedInterval(BONUS_CIVS_Encounters_Init, 1.5, 1)
end

function BONUS_CIVS_Encounters_Init()

if Objective_IsStarted(OBJ_Bonus_Civilians) then
Rule_RemoveMe()

--World_IncreaseInteractionStage()

sg_bonus_civs_e_all = SGroup_CreateIfNotFound("sg_bonus_civs_e_all")

BONUS_CIVS_Enemy_01()
BONUS_CIVS_Enemy_02()

EGroup_SetSelectable(eg_bonus_civs_building, true)

-- Spawn the units
sg_bonus_civs_a_all = SGroup_CreateIfNotFound("sg_bonus_civs_a_all")

Util_CreateSquads(player3, sg_bonus_civs_a_all, SBP.SOVIET.BASE_CONSCRIPT_SQUAD, eg_bonus_civs_building)
Util_CreateSquads(player3, sg_bonus_civs_a_all, SBP.SOVIET.BASE_CONSCRIPT_SQUAD, eg_bonus_civs_building)
--Util_CreateSquads(player3, sg_bonus_civs_a_all, SBP.SOVIET.BASE_CONSCRIPT_SQUAD, eg_bonus_civs_building)

Modify_WeaponDamage(sg_bonus_civs_a_all, "hardpoint_01", 0)

EGroup_EnableUIDecorator(eg_bonus_civs_building, false)

SGroup_SetInvulnerable(sg_bonus_civs_a_all, true)

--Event_GroupLeftAlive(_Bonus_Civs_Retreat_Enemies, nil, sg_bonus_civs_e_all, 3)
end
end

function _BonusObjective_Civs_Timer()
-- Check if both enemy groups are dead
if SGroup_TotalMembersCount(sg_bonus_civs_e_01) <= 0 and SGroup_TotalMembersCount(sg_bonus_civs_e_02) <= 0 then
Rule_RemoveMe()
return
end

-- first check to see if the timer is active
if Timer_Exists(tmr_bonus) then

-- Check the remaining time and check if any civilians have been under attack within the next 3 seconds
if Timer_GetRemaining(tmr_bonus) <= 0 then

-- -- select a random civlian squad
local sid = SGroup_GetRandomSpawnedSquad(sg_bonus_civs_a_all)

-- count remaining civilians in chosen squad
local count = Squad_Count(sid)

-- returns a random integer between 1 and the remaining civilians in the chosen squad
local index = World_GetRand(1, count)

-- select the random integer of civilians minus 1 to kill
local eid = Squad_EntityAt(sid, (index-1))

-- kill selected civilians from randomly chosen civilian squad
Entity_kill(eid)

--SGroup_Kill(sid)


-- Update the Objective_SetCounter
Objective_SetCounter(OBJ_Bonus_Civs_Loss, SGroup_TotalMembersCount(sg_bonus_civs_a_all))

Timer_End(tmr_bonus)
end

-- Rule if the timer is inactive
elseif Timer_Exists(tmr_bonus) == false then

-- check if all civilians are dead
if SGroup_TotalMembersCount(sg_bonus_civs_a_all) <= 0 then
Rule_RemoveMe()
Rule_Remove(_BonusObjective_Civs_Rescued)

-- enemies are victorious. They retreat back to the city centre
-- Cmd_Retreat(sg_bonus_civs_e_01, mkr_bonus_civs_e_retreat, mkr_bonus_civs_e_retreat)
-- Cmd_Retreat(sg_bonus_civs_e_02, mkr_bonus_civs_e_retreat, mkr_bonus_civs_e_retreat)

-- all civilians are dead, the objective is failed
Objective_Fail(OBJ_Bonus_Civilians)
return
end

-- restart the timer
Timer_Start(tmr_bonus, t_difficulty.death_rate)

end

end


I know that the SGroup is valid throughout this function because if I remove Entity_Kill the counter updates correctly with the number of troops in the SGroup "sg_bonus_civs_a_all", so I'm not sure why I'm receiving the nil value.

Any help would be greatly appreciated!

Thank you.
14 May 2019, 14:05 PM
#2
avatar of eliw00d
Honorary Member Badge

Posts: 756 | Subs: 8

It's actually right there in the error:

attempt to call global 'Entity_kill' (a nil value)

The k in Entity_Kill should be upper case. So, the nil value refers to the fact that Entity_kill does not exist.
14 May 2019, 16:02 PM
#3
avatar of jcbarth

Posts: 24

Oh my god. Thank you! I can't believe I didn't see that. Really appreciate your help.
14 May 2019, 16:16 PM
#4
avatar of eliw00d
Honorary Member Badge

Posts: 756 | Subs: 8

Sometimes it's the simplest thing. :)

Glad to be of help.
1 user is browsing this thread: 1 guest

Livestreams

unknown 1
Germany 1

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

346 users are online: 1 member and 345 guests
DerKuhlmann
12 posts in the last 24h
36 posts in the last week
151 posts in the last month
Registered members: 45182
Welcome our newest member, ariehartman
Most online: 2043 users on 29 Oct 2023, 01:04 AM