function Enplacement_Stat_Add(i, pid, enplacement_entity, SquadID, squadtruck, Enplacement_point)local Truck_Leave = falselocal Table_Ref, Crew_Squad local sg_temp, eg_temp, Truck_Grouplocal enplacement_entity = enplacement_entity local SquadID = SquadIDlocal squadtruck = squadtruck local Enplacement_point = Enplacement_point local func_ref local Entity_ID = Entity_GetGameID(enplacement_entity)print("EID", Entity_GetGameID(enplacement_entity)) print("valid", Entity_IsValid(Entity_ID))print("Alive", Entity_IsAlive(enplacement_entity))print("command", Entity_GetActiveCommand(enplacement_entity)) -- ref for dynamic functions if func_ref == nil then func_ref = 1 else func_ref = func_ref + 1 end if Player[pid].DynamicFunctions.Build_Check == nil then Player[pid].DynamicFunctions.Build_Check = {} end if Player[pid].DynamicFunctions.Pause_Code == nil then Player[pid].DynamicFunctions.Pause_Code = {} end -- dynamic function names (for if more than one emplacement is building at the same time). -- call every second check if the enplacement has been completed, killed or just canceled. Player[pid].DynamicFunctions.Build_Check[func_ref] = function() print("EID_CALLED", Entity_GetGameID(enplacement_entity)) if Entity_IsValid(Entity_ID) == false or Entity_IsAlive(enplacement_entity) == false or Entity_GetActiveCommand(enplacement_entity) ~= 0 then if Entity_IsValid(Entity_ID) == false then -- The enplacement has been canceled so nothing happens, the player can just start again. elseif Entity_GetHealth(enplacement_entity) < 1 then -- the enplacement has been killed, im not sure if a dead one will return -- the same as a cancelled one so i have a few extra checks. -- The enplacements drop a marker when they die, Grab all the ones on the map into an EGroup. eg_temp = EGroup_CreateIfNotFound("eg_temp") EGroup_Clear(eg_temp) EGroup_AddEGroup(eg_temp, Player_GetEntities(World_GetPlayerAt(i))) EGroup_Filter(eg_temp, POINT.ENPLACEMENT_DEAD, FILTER_KEEP) -- Find the closest one. local dist = 99999 local pos = Enplacement_point local closest_point local getClosestPoint = function(gid, idx, eid) local eid_pos = Squad_GetPosition(eid) local eid_dist = World_DistancePointToPoint(pos, eid_pos) if eid_dist < dist then closest_point = eid dist = eid_dist end end EGroup_ForEach(eg_temp, getClosestPoint) -- Save its postion and destroy it. closest_point_pos = Entity_GetPosition(closest_point) EGroup_DestroyAllEntities(eg_temp) -- see if the closest one is right on top (or under) the enplacement pos. if World_DistancePointToPoint(closest_point_pos, Enplacement_point) <= 1 then -- varaiable that lets the truck leave the map. Truck_Leave = true end else Truck_Leave = true -- Spawn the Crew and make them unselectable to the owning player. sg_temp = SGroup_CreateIfNotFound("sg_temp") SGroup_Clear(sg_temp) Util_CreateSquadsAtMarkerFacing(World_GetPlayerAt(i), sg_temp, BP_GetSquadBlueprint("sbps/races/allies/vehicles/m2a1_105mm_howitzer_squad.lua"), Enplacement_point, Enplacement_point, 1) if pid == Player_GetID(Game_GetLocalPlayer()) - 999 then SGroup_SetSelectable(sg_temp, false) end -- Get the Crew's SID (Squad ID) local dist = 99999 local pos = Enplacement_point local __GetSID = function(gid, idx, sid) local sid_pos = Squad_GetPosition(sid) local sid_dist = World_DistancePointToPoint(pos, sid_pos) if sid_dist < dist then Crew_Squad = sid dist = sid_dist end end SGroup_ForEach(sg_temp, __GetSID) -- Clear and add the Enplacement entity eg_temp = EGroup_CreateIfNotFound("eg_temp") EGroup_Clear(eg_temp) EGroup_Add(eg_temp, enplacement_entity) -- Make the entity neutral via a custom ability. Cmd_Ability(eg_temp, BP_GetAbilityBlueprint("abilities/omg_make_neutral.lua")) -- see if the this is a fist time build or a move (a first time build will return nil -- in Find_TruckSGroup Truck_Group = Find_TruckSGroup(squadtruck, pid) if Truck_Group ~= nil then Table_Ref = SquadID -- check if the crew has lost a man. if Player[pid].EnplacementStats[Table_Ref].Crew_Count < 3 then -- split the crew if the crew are a man down. Squad_Split(Crew_Squad, Player[pid].EnplacementStats[Table_Ref].Crew_Count) -- Destroy the smaller squad(the SID always stays with the squad that is left over, i.e. you split a team of 3 -- by 2 then the SID will be with the team of 1. and vice versa. Squad_Destroy(Crew_Squad) -- redo all the finding closest squad again. SGroup_Clear(sg_temp) SGroup_AddGroup(sg_temp, Player_GetSquads(World_GetPlayerAt(i))) SGroup_Filter(sg_temp, OMG_ENPLACEMENT_SQUADS, FILTER_KEEP) SGroup_ForEach(sg_temp,__GetSID) end -- set the crew and gun HP. (need to make the numbers into a deciaml percentage between 0.0 and 1.0) local C_HP = (Player[pid].EnplacementStats[Table_Ref].Crew_Hp / Squad_GetHealthMax(Crew_Squad)) local E_HP = (Player[pid].EnplacementStats[Table_Ref].Gun_Hp / Entity_GetHealthMax(enplacement_entity)) Squad_SetHealth(Crew_Squad, C_HP) Entity_SetHealth(enplacement_entity, E_HP) end -- Put the crew in a fresh SGroup SGroup_Clear(sg_temp) SGroup_Single(sg_temp, Crew_Squad) -- Put the Gun entity in a fresh EGroup EGroup_Clear(eg_temp) EGroup_Single(eg_temp, enplacement_entity) -- Re-man the Gun. Cmd_CaptureTeamWeapon(sg_temp, eg_temp) -- if this happens too fast then the crew don't have time to recrew the emplacement, so pause by 2 seconds. Player[pid].DynamicFunctions.Pause_Code[func_ref] = function() -- Add the New Gun to the Tracking SGroup. SGroup_Clear(Player[pid].towable[SquadID][1]) SGroup_AddGroup(Player[pid].towable[SquadID][1], Player_GetSquads(World_GetPlayerAt(i))) SGroup_Filter(Player[pid].towable[SquadID][1], OMG_ENPLACEMENT_CAPTURE, FILTER_KEEP) if SGroup_Count(Player[pid].towable[SquadID][1]) > 1 then for k,v in pairs(Player[pid].towable) do if k ~= SquadID then SGroup_RemoveGroup(Player[pid].towable[SquadID][1], v[1]) end end end -- Add Vet to that Sgroup. if Truck_Group ~= nil then SGroup_IncreaseVeterancyExperience(Player[pid].towable[SquadID][1], Player[pid].EnplacementStats[Table_Ref].Exp) else SGroup_IncreaseVeterancyExperience(Player[pid].towable[SquadID][1], Player[pid].towable[SquadID][2], true, false) end -- Add the Upgrades local Upgrades if Truck_Group ~= nil then Upgrades = Player[pid].EnplacementStats[Table_Ref].Upgrades else Upgrades = Player[pid].towable[SquadID][3] end local SGroup = Player[pid].towable[SquadID][1] local Number = table.getn(Upgrades) if Number > 0 then for i = 1, Number do local Upgrade = Upgrades[i] Cmd_InstantUpgrade(SGroup, Upgrade, 1) end end end EGroup_Destroy(eg_temp) SGroup_Destroy(sg_temp) if Rule_Exists(Player[pid].DynamicFunctions.Pause_Code[func_ref]) then Rule_Remove(Player[pid].DynamicFunctions.Pause_Code[func_ref]) end Rule_AddOneShot(Player[pid].DynamicFunctions.Pause_Code[func_ref], 2) end -- checks if truck is allowed to leave map if Truck_Leave == true then -- Create a unique SGroup and add truck to it. Player[pid].trucks[SquadID] = SGroup_CreateIfNotFound("sg_trucks"..SquadID) SGroup_Clear(Player[pid].trucks[SquadID]) SGroup_Add(Player[pid].trucks[SquadID], squadtruck) if pid == Player_GetID(Game_GetLocalPlayer()) - 999 then SGroup_SetSelectable(Player[pid].trucks[SquadID], false) end -- give it the retreat upgrade and move it towards the map entry point Cmd_InstantUpgrade(Player[pid].trucks[SquadID], OMGUPG.RETREAT) Cmd_Move(Player[pid].trucks[SquadID], Player[pid].Map_Entry_Point) end else Rule_Remove(Player[pid].DynamicFunctions.Build_Check[func_ref]) Rule_AddOneShot(Player[pid].DynamicFunctions.Build_Check[func_ref], 1) end end if Rule_Exists(Player[pid].DynamicFunctions.Build_Check[func_ref]) then Rule_Remove(Player[pid].DynamicFunctions.Build_Check[func_ref]) end Rule_AddOneShot(Player[pid].DynamicFunctions.Build_Check[func_ref], 1)end