Login

russian armor

Neutral minefield (SCAR problem)

23 Feb 2019, 18:45 PM
#1
avatar of Bullaman

Posts: 3

FIFIHello

So i had a map in COH 1 that had a neutral minefield. That the mines didnt have a player assigned so the enemy doesnt get points when someone dies on the mine.
I wanted to apply this to COH 2 but couldnt make it work. I only had some SCAR code in my email because the forum had been deleted. So i dont know if its all there, or is it still relevant or outdated.

Basicly i have mines in the map and i made an entity group called (eg_mines).

Then there is the code that i thought was the final version of the working one in COH 1.
Hope someone here could help me i still dont know anything about SCAR basicly so someone helped me the last time i did this too.

import("ScarUtil.scar")

function custom_CheckMines()
local AllSquads = {} -- we need a blank helper table to store all the player squads

-- first check if the list of mines is still actual, removing all no more existing mines
if EGroup_CountAlive(eg_mines) < EGroup_Count(eg_mines) then
local tmp_mineslist = {}
local MinesList = function(egroupid, itemindex, entityID)
if Entity_IsAlive(entityID) then
table.insert(tmp_mineslist, entityID)
end
end
EGroup_ForEach(eg_mines, MinesList)
eg_mines = tmp_mineslist
end

for i = 1, table.getn(eg_mines) do
local entityID = eg_mines
local entityPos = Entity_GetPosition(entityID) -- now you have the actual position of each mine in your table

-- this is a loop through all existing players onto the map
for n = 1, World_GetPlayerCount() do
local PlayerID = World_GetPlayerAt(n) -- that's the actual plyer we check

-- now we need all squads of the actual player
local PlayerSquads = function(sgroupid, itemindex, squadID)
table.insert(AllSquads, squadID) -- adding a new squad to our squad list
end

Player_GetAll(PlayerID) -- this function creates a list of all objects assigned to a player
SGroup_ForEach(sg_allsquads, PlayerSquads) -- we only need the squads, these are stored in sg_allsquads by the function above
-- with this list we are calling now the subfunction PlayerSquads above (foreach)
end

-- now we have all existing player squads for each player in our helper table AllSquads

-- we have to check now, which squad is nearby and the closest one to each of our mines
local dist -- it's a helper variable which should store our distance value
local closest = 99999 -- it's a helper variable which should help us to identify the closest squad
local ClosestSquad -- it's a helper variable which should store the actual closest squad (ID)

for x = 1, table.getn(AllSquads) do
local AllSquadsPos = Util_GetPosition(AllSquads) -- getting the position of the actual squad from the list of squads
dist = World_DistancePointToPoint(entityPos, AllSquadsPos) -- getting the distance between our actual mine and the actual squad
if dist < closest then
closest = dist -- the actual lowest distance will be stored here
ClosestSquad = AllSquads -- the actual closest squad (ID) will be stored here
end
end

-- now we know, which squad is the closest one to this mine
local SquadOwner_PlayerID = Squad_GetPlayerOwner(ClosestSquad) -- getting the PlayerID of the owner of the closest squad
local Enemy_PlayerID = Player_FindFirstEnemyPlayer(SquadOwner_PlayerID) -- getting the PlayerID of any enemy of this player

-- second check if the actual mine still exist, before we perform any action on it
if Entity_IsAlive(entityID) then
Entity_SetPlayerOwner(entityID, Enemy_PlayerID) -- setting the mine to be owned by an enemy player
end

end
end

Rule_AddInterval(custom_CheckMines, 1)


THANK YOU
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

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