CP Capture message problem

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Jedi
User avatar
Posts: 1215
Joined: Mon Mar 21, 2011 8:12 pm
Location: STALKER!
Projects :: Star Wars Battlefront - Tides of War
Games I'm Playing :: SWBF2 RC EAW
xbox live or psn: I have ps4

CP Capture message problem

Postby ARCTroopaNate » Thu Mar 28, 2019 6:16 pm

viewtopic.php?p=140204#p140204

I've used this to add CP capture/lost messages for all the stock maps, but I run into a problem if more than once CP is getting neutralized at a time.

Code: Select all
OnBeginNeutralize(
   function(cPost)
      pTeam = GetCommandPostTeam(cPost)
end
)

OnFinishNeutralize(
   function(cPost)
      local pName = GetEntityName(cPost)      -- Gets the name of the post that was lost     
     
      if (pTeam == 1) then
         ShowMessageText("level.dea1." .. pName .. "_all_lost")      -- Show this string to all teams
      else
         ShowMessageText("level.dea1." .. pName .. "_imp_lost")      -- Show this string to all teams
        end
    end
)


Let's say rebels begin neutralizing CP 4, then the variable pTeam == 1. Let's say the Empire begins neutralizing CP 2 before the rebels finish neutralizing CP 4, then pTeam value changes to 2. Now the rebels finish neutralizing CP 4, but the message displays as "Rebels lost blah blah post" instead of reading Empire lost blah blah post.

Is there any way to fix this??

Thank you.

Recruit Womprat Killer
Posts: 6
Joined: Thu Jan 24, 2019 11:02 pm
Projects :: No Mod project currently.
Games I'm Playing :: I havenae listed any
xbox live or psn: No gamertag set

Re: CP Capture message problem

Postby Sporadia » Thu Mar 28, 2019 7:18 pm

Have you tried making pTeam an array so each cp's team is stored as a separate value? e.g.
Hidden/Spoiler:
Code: Select all
pTeam = {} -- Define array

OnBeginNeutralize(
   function(cPost)
      pTeam[cPost] = GetCommandPostTeam(cPost) -- Store team for specific command post in the array
end
)

OnFinishNeutralize(
   function(cPost)
      local pName = GetEntityName(cPost)      -- Gets the name of the post that was lost     
     
      if (pTeam[cPost] == 1) then -- Check team for specific command post in the array
         ShowMessageText("level.dea1." .. pName .. "_all_lost")      -- Show this string to all teams
      else
         ShowMessageText("level.dea1." .. pName .. "_imp_lost")      -- Show this string to all teams
        end
    end
)


If that doesn't work, you can set up the array more neatly e.g.
Hidden/Spoiler:
Code: Select all
pTeam = {} -- Define array
-- Fill array with 0s for addresses 1-6
for i = 1, 6 do
    pTeam[i] = 0
end

OnBeginNeutralize(
   function(cPost)
      pTeam[cPost] = GetCommandPostTeam(cPost) -- Store team for specific command post in the array
end
)

OnFinishNeutralize(
   function(cPost)
      local pName = GetEntityName(cPost)      -- Gets the name of the post that was lost     
     
      if (pTeam[cPost] == 1) then -- Check team for specific command post in the array
         ShowMessageText("level.dea1." .. pName .. "_all_lost")      -- Show this string to all teams
      else
         ShowMessageText("level.dea1." .. pName .. "_imp_lost")      -- Show this string to all teams
        end
    end
)


In both these examples I've assumed cPost is a number, if that's wrong it may need some tweaking.
Edit: Corrected a syntax error (accidental comma in 2nd example)

Jedi
User avatar
Posts: 1215
Joined: Mon Mar 21, 2011 8:12 pm
Location: STALKER!
Projects :: Star Wars Battlefront - Tides of War
Games I'm Playing :: SWBF2 RC EAW
xbox live or psn: I have ps4

Re: CP Capture message problem

Postby ARCTroopaNate » Sat May 25, 2019 10:20 am

It didn't work. I'm not sure if cPost is a number (i.e. 6) or (CP6)

Recruit Womprat Killer
Posts: 6
Joined: Thu Jan 24, 2019 11:02 pm
Projects :: No Mod project currently.
Games I'm Playing :: I havenae listed any
xbox live or psn: No gamertag set

Re: CP Capture message problem

Postby Sporadia » Tue Jun 18, 2019 1:22 am

You might be right. The first thing you should do is add print("Checking the format of cPost: "..cPost) into OnBeginNeutralise. Then you can see if cPost is a number or a string in the log. Assuming cPost does give you a name (eg CP6) then I've updated the code below. I've put this together using techniques that I've got working in user scripts of my own before. But I haven't actually tested this exact code so I'm hoping there aren't any mistakes (and it all fits together fine). The overall idea of putting together a CP index/matrix and making functions to use it should work regardless, even if my suggested code gets something wrong. Hope this helps.
Hidden/Spoiler:
Code: Select all
CPTotal = 10 -- this should be bigger than the number of command posts on the map

-- Create an index/matrix for storing command post names and their teams
pTeam = {} -- Define matrix
for i = 1, CPTotal do
    pTeam[i] = {}
   for j = 1, 2 do -- CP names in row 1, teams in row 2
       pTeam[i][j] = 0
   end
end

-- Making a new function UpdateCPIndex
-- To add and update command posts in the index
-- Argument postname is the name of the command post eg CP6
-- Argument postteam is the team value for that command post
if UpdateCPIndex then -- Error check
    print("Warning: UpdateCPIndex already exists as a function")
else
    function UpdateCPIndex(postname, postteam)
       -- Update the team of a command post already in the matrix
      -- Look for the command post's name in the index first
      local j = 0 -- don't confuse this j with the one above
      for i = 1, CPTotal do
          if (pTeam[i][1] == postname) then
             pTeam[i][2] = postteam -- found CP in index so update team
            j = 1
         end
      end
      if (j == 0) then -- This j is 0 when CP hasn't been found in index already
          -- Add command post name to the index
         local k = 0
         for i = 1, CPTotal do
             if (k == 0) then
                -- Find first available slot
                if (pTeam[i][1] == 0) then -- look for a 0 in the name column
                    -- Add CP info to the index
                    pTeam[i][1] = postname
                   pTeam[i][2] = postteam
                   k = 1 -- stops the rest of the index from being filled accidentally
               end
            end
         end
         -- Error check
         if (k == 0) then
             print("Warning: Unable to add command post to index, increase CPTotal")
            return nil
         end
      end
   end
end

-- Making a new function ReadCPIndex
-- To find teams in the index using the command post name
-- This function only has one argument, postname
-- It returns the team number for that CP
-- If the function can't find a command post in the index, it returns nil
if ReadCPIndex then -- Error check
    print("Warning: ReadCPIndex already exists as a function")
else
    function ReadCPIndex(postname)
      local postteam = nil
      -- Look for the command post's name in the index
      for i = 1, CPTotal do
          if (pTeam[i][1] == postname) then
             postteam = pTeam[i][2]
         end
      end
      return postteam
   end
end

OnBeginNeutralize(
    function(cPost)
       print("Checking the format of cPost: "..cPost) -- Check this in the log to find out if cPost is a number
        UpdateCPIndex(cPost, GetCommandPostTeam(cPost)) -- Store team for specific command post in the array
end
)

OnFinishNeutralize(
    function(cPost)
        local pName = GetEntityName(cPost)      -- Gets the name of the post that was lost     
     
        if (ReadCPIndex(cPost) == 1) then -- Check team for specific command post in the array
            ShowMessageText("level.dea1." .. pName .. "_all_lost")      -- Show this string to all teams
        else
            ShowMessageText("level.dea1." .. pName .. "_imp_lost")      -- Show this string to all teams
        end
    end
)

Return to SWBF2 Modding

Who is online

Users browsing this forum: No registered users and 1 guest