CP Capture message problem
Moderator: Moderators
9 posts
• Page 1 of 1
- ARCTroopaNate
-
- Posts: 1216
- 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
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.
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.
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.
- Sporadia
- Recruit Womprat Killer
- Posts: 11
- 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
Have you tried making pTeam an array so each cp's team is stored as a separate value? e.g.
If that doesn't work, you can set up the array more neatly e.g.
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)
Hidden/Spoiler:
If that doesn't work, you can set up the array more neatly e.g.
Hidden/Spoiler:
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)
- ARCTroopaNate
-
- Posts: 1216
- 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
It didn't work. I'm not sure if cPost is a number (i.e. 6) or (CP6)
- Sporadia
- Recruit Womprat Killer
- Posts: 11
- 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
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:
- ARCTroopaNate
-
- Posts: 1216
- 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
It does return a name (cp6). I tried the code and didn’t work, how would I go about testing to see whqt the issue is? I’m not very familiar with coding for battlefront
- Sporadia
- Recruit Womprat Killer
- Posts: 11
- 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
Sorry my suggestion hasn't worked. The best way to debug code is to shove the print() command in smart places. With print, you put text inside of "", eg print("this is text") and it will show up in the log when you test a map. To read values of things then put them outside of the "" eg print("What is cPost" cPost) will show you something like What is cPost cp6. The .. is a way of removing some of the spacing but it only works for numbers or strings, if cPost contained userdata for example it would cause a crash with print("text "..cPost).
So what I'd suggest doing is putting things like print("UpdateCPIndex called successfully") under function UpdateCPIndex(postname, posteam) to check in the log every time the function UpdateCPIndex runs, and then throwing print commands everywhere where a number is changing or being used to check they're all doing what they're supposed to be. That kind of thing. And then you can remove them all later when you don't need them. As for specifically what code I posted, setting up a matrix in lua is easy to look up online. Making functions is something I've picked up from looking at Zerted's user script docs that come with the patch and playing around with them. There are examples of looking up values in matrices and using indexes in some of the mission scripts for campaign levels. Like look at how they spawn Greivous in the Utapau level. And so I would have thought that putting a matrix together for all the cPost names to be stored next to their team values should be step 1. Learning how to make a function is step 2. Figuring out how to get those functions to fill in and read from the matrix correctly is step three (this uses a lot of for commands which is probably where the mistake is). And that as a method ought to work. I suspect I've just made a slight mistake somewhere, but I can't help you there because I don't have any way of testing this stuff as I was writing it.
Edit: If you don't use .. but you're testing 2 numbers/strings/userdata, you need to use a comma. Eg
print("text" num) will work but have a big space between the text and the number
print("text "..num) will remove the spacing (num must be a number or a string or .. will crash)
print("text" num "text") will work
print("text "..num.." text") will work (num must be a number or a string or .. will crash)
print(num1 num2) will crash
print(num1, num2) will work but have a big space between the 2 numbers
print(num1.." "..num2) will put a single space between the 2 numbers (num must be a number or a string or .. will crash)
print(num1 "text" num2) will crash
print(num1, "text", num2) will work but have big spaces
So what I'd suggest doing is putting things like print("UpdateCPIndex called successfully") under function UpdateCPIndex(postname, posteam) to check in the log every time the function UpdateCPIndex runs, and then throwing print commands everywhere where a number is changing or being used to check they're all doing what they're supposed to be. That kind of thing. And then you can remove them all later when you don't need them. As for specifically what code I posted, setting up a matrix in lua is easy to look up online. Making functions is something I've picked up from looking at Zerted's user script docs that come with the patch and playing around with them. There are examples of looking up values in matrices and using indexes in some of the mission scripts for campaign levels. Like look at how they spawn Greivous in the Utapau level. And so I would have thought that putting a matrix together for all the cPost names to be stored next to their team values should be step 1. Learning how to make a function is step 2. Figuring out how to get those functions to fill in and read from the matrix correctly is step three (this uses a lot of for commands which is probably where the mistake is). And that as a method ought to work. I suspect I've just made a slight mistake somewhere, but I can't help you there because I don't have any way of testing this stuff as I was writing it.
Edit: If you don't use .. but you're testing 2 numbers/strings/userdata, you need to use a comma. Eg
print("text" num) will work but have a big space between the text and the number
print("text "..num) will remove the spacing (num must be a number or a string or .. will crash)
print("text" num "text") will work
print("text "..num.." text") will work (num must be a number or a string or .. will crash)
print(num1 num2) will crash
print(num1, num2) will work but have a big space between the 2 numbers
print(num1.." "..num2) will put a single space between the 2 numbers (num must be a number or a string or .. will crash)
print(num1 "text" num2) will crash
print(num1, "text", num2) will work but have big spaces
Last edited by Sporadia on Thu Jun 27, 2019 4:32 pm, edited 2 times in total.
- Marth8880
- Resistance Leader
-
- Posts: 5266
- Joined: Tue Feb 09, 2010 8:43 pm
- Location: Edinburgh, UK
- Projects :: EVERYWHERE + Project Infiltrator
- Games I'm Playing :: Jedi Fallen Order
- xbox live or psn: Marth8880
Re: CP Capture message problem
Why do you need to get pTeam in OnBeginNeutralize? Why not just get the CP's team in OnFinishNeutralize?
If the execution order is off and the team is always 0 in OnFinishNeutralize, you can make pTeam into a string-indexed table. It would look something like this:
If the execution order is off and the team is always 0 in OnFinishNeutralize, you can make pTeam into a string-indexed table. It would look something like this:
- Code: Select all
local pTeams = {}
OnBeginNeutralize(
function(cPost)
pTeams[GetEntityName(cPost)] = GetCommandPostTeam(cPost)
end
)
OnFinishNeutralize(
function(cPost)
local pName = GetEntityName(cPost)
print("OnFinishNeutralize: "..pName.." (team "..pTeams[pName]..")")
-- Which team lost the CP? (Need to account for other teams too!)
if (pTeams[pName] == ALL) then
ShowMessageText("level.dea1." .. pName .. "_all_lost") -- Show this string to all teams
elseif (pTeams[pName] == IMP) then
ShowMessageText("level.dea1." .. pName .. "_imp_lost") -- Show this string to all teams
end
-- Cleanup
pTeams[pName] = 0
end
)
- Sporadia
- Recruit Womprat Killer
- Posts: 11
- 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
Yeah Marth's suggestion is more elegant than what I was trying. When you have if pTeams[cPost] == 1 do causing a problem because cPost is a string not a number then there are 2 approaches. One is to just go "oh ok, replace the 1 with ALL." The other is to forget strings can index tables in lua and try to put a matrix together that you have to continuously search through. I actually tried modding kamino today to test this problem and got it working with a matrix too if the string indexed table method doesn't work. Btw pTeams[cPost] would work just as well as pTeams[GetEntityName(cPost)] and pTeams[pName] if you want to simplify it even more.
Edit: Oh wait no, I'm definitely wrong here. Because ALL is just the same as 1.
Edit edit: The problem isn't that pTeam is 0 on OnFinishNeutralize, the problem was that pTeam would be overwritten when two command posts were being neutralized at the same time, so the first CP was taking the team of the 2nd CP. Still solved with a string indexed table if string indexed tables work. But if pTeam[cPost] didn't work in my first suggestion, and print(cPost) was giving a string like CP6 then why does pTeam[GetEntityName(cPost)] work any better? cPost and GetEntityName(cPost) are both strings aren't they? Am ready with a solution to this based on matrices but I don't want to post it if I'm missing something and Marth's way works. Because my way is almost the same as before which is like 3 times as big as Marth's and I'll probably explain it step by step this time so you know how to debug it if you have to.
Edit: Oh wait no, I'm definitely wrong here. Because ALL is just the same as 1.
Edit edit: The problem isn't that pTeam is 0 on OnFinishNeutralize, the problem was that pTeam would be overwritten when two command posts were being neutralized at the same time, so the first CP was taking the team of the 2nd CP. Still solved with a string indexed table if string indexed tables work. But if pTeam[cPost] didn't work in my first suggestion, and print(cPost) was giving a string like CP6 then why does pTeam[GetEntityName(cPost)] work any better? cPost and GetEntityName(cPost) are both strings aren't they? Am ready with a solution to this based on matrices but I don't want to post it if I'm missing something and Marth's way works. Because my way is almost the same as before which is like 3 times as big as Marth's and I'll probably explain it step by step this time so you know how to debug it if you have to.
Last edited by Sporadia on Thu Jun 27, 2019 4:02 pm, edited 1 time in total.
- Sporadia
- Recruit Womprat Killer
- Posts: 11
- 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
I've tested Marth's code with print() in OnBeginNeutralize and OnFinishNeutralize to check everything that was happening (because I haven't set up ShowMessageText). Completely worked. I then did print(cPost) and print(GetEntityName(cPost)) in OnBeginNeutralize. Both printed the same thing on Kamino (I think GetEntityName(cPost) might give you the in game names on maps which have them, if that line does anything at all. But for Kamino I saw cp1, cp2 etc). Then I went and tested the first response I posted where I was using pTeam[cPost] instead of pTeam[GetEntityName(cPost)] and pTeam[(pName)]. Totally worked for me too. No idea why it didn't when you tried it (maybe there's a typo, I typed it out again). I would take Marth's idea of using elseif pTeam[cPost] == 2 instead of else in the OnFinishNeutralize though; sometimes maps have natives and extra teams. The 2nd thing I posted (matrix method) is completely unnecessary, string indexed arrays do work.
Edit: This is the exact code I put at the end of ScriptPostLoad() on Kamino. I have checked the log to make sure it directs to the right ShowMessage every time since they just appear as [NULL] to me. So I can confirm this is working code for me.
Edit edit: Have you been using pTeam anywhere else in your code? Because I've been assuming that you haven't but that might break the line pTeam = {}, in which case you should try local pTeam = {} (also in Marth's version) or rename pTeam to something else for this bit.
Edit: This is the exact code I put at the end of ScriptPostLoad() on Kamino. I have checked the log to make sure it directs to the right ShowMessage every time since they just appear as [NULL] to me. So I can confirm this is working code for me.
Hidden/Spoiler:
Edit edit: Have you been using pTeam anywhere else in your code? Because I've been assuming that you haven't but that might break the line pTeam = {}, in which case you should try local pTeam = {} (also in Marth's version) or rename pTeam to something else for this bit.
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 2 guests