CP Message Code (FAQ)

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

Old School Staff
User avatar
Posts: 2059
Joined: Wed Feb 23, 2005 9:54 am

RE: CP Message Code

Postby Qdin » Wed Dec 06, 2006 12:28 pm

what's a Post Virual Syndrom? >.> is it a medical joke? :roll:

Isn't that done through the Localization? :) or maybe you can active a String in the .LUA* (you probably can - lol - but where would the string be displayed?)

Major
User avatar
Posts: 501
Joined: Mon Apr 17, 2006 1:44 pm

RE: CP Message Code

Postby MasterSkywalker » Wed Dec 06, 2006 12:30 pm

Maybe it is in the SWBF1 lua's? I should check those dude. But would the string be something like DisplayCommandPostName?

Soul

EDIT: There are is a infomsg into the Localization keys, that has a lost and captured key (like Penguin already said). Maybe we should use this too find out how to make the CP texts display again.

EDIT2: There are loads of commands in the GT wiki (donnu if its back up). Check those out, I'm pretty sure the command you need will be in the list.

EDIT3: I might have found it :D
Code: Select all
   assert(cp.name, "WARNING: no name supplied for the command post")
   cp.name = string.lower(cp.name)
         
   self.commandPosts[cp.name] = cp


Hidden/Spoiler:
Code: Select all
   --=======================================
   -- Event responses
   --=======================================
   -- command post captures
   OnFinishCapture(
      function (postPtr)
         if self.isComplete then   return end
         if not self.commandPosts[GetEntityName(postPtr)] then return end
                  
         UpdatePostMapMarker(postPtr)
         UpdateState()
      end
      )
      
   -- command post neutralize
   OnFinishNeutralize(
      function (postPtr)            
         if self.isComplete then   return end
         if not self.commandPosts[GetEntityName(postPtr)] then return end
         
         UpdatePostMapMarker(postPtr)
         UpdateState()
      end
      )
      
   -- command post spawn
   OnCommandPostRespawn(
      function (postPtr)            
         if self.isComplete then   return end
         if not self.commandPosts[GetEntityName(postPtr)] then return end
         
         UpdatePostMapMarker(postPtr)         
         UpdateState()
      end
      )
   
   -- command post kill
   OnCommandPostKill(
      function (postPtr)
         if self.isComplete then   return end
         if not self.commandPosts[GetEntityName(postPtr)] then return end
         
         if not self.multiplayerRules then
            MapRemoveEntityMarker(postPtr, self.teamATT)
         end
         
         UpdateState()
      end
      )   
end

Jedi Admin
User avatar
Posts: 11087
Joined: Wed Sep 07, 2005 11:42 pm
Location: Indiana
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set

RE: CP Message Code

Postby Teancum » Wed Dec 06, 2006 2:35 pm

The OnFinishCapture( ) function is what you want. From there you can get it to print a string.

Are you wanting this to be like it was in SWBF1 where text pops up when a CP is captured?

Major
User avatar
Posts: 501
Joined: Mon Apr 17, 2006 1:44 pm

RE: CP Message Code

Postby MasterSkywalker » Wed Dec 06, 2006 2:41 pm

Won't you also need the other codes, since you also get a message when you lost a CP in SWBF1 too.

Soul

Jedi Admin
User avatar
Posts: 11087
Joined: Wed Sep 07, 2005 11:42 pm
Location: Indiana
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set

RE: CP Message Code

Postby Teancum » Wed Dec 06, 2006 2:46 pm

True. Hadn't thought of that.

Major
User avatar
Posts: 501
Joined: Mon Apr 17, 2006 1:44 pm

RE: CP Message Code

Postby MasterSkywalker » Wed Dec 06, 2006 2:55 pm

I've tried all of the functions. None of them worked, but that probably was because I didn't setup any localization for my cp's. Gonna try out in a few secs with correct localization keys.

Soul

Jedi Admin
User avatar
Posts: 2544
Joined: Sun Mar 05, 2006 12:00 am
Location: Australia

RE: CP Message Code

Postby Penguin » Wed Dec 06, 2006 7:10 pm

have a feeling that I'm doing this the long/or wrong way

these lines are all for 1 cp. Haven't tested it yet >.< I've put them under
function ScriptInit()
Code: Select all
    OnFinishCaptureTeam(function (ShowMessageText("level.VNV.cp2c_r", ATT, DEF) (cp2) ... end, 1)
    OnFinishCaptureTeam(function (ShowMessageText("level.VNV.cp2c_c", ATT, DEF) (cp2) ... end, 2)
    OnFinishNeutralizeTeam(function (ShowMessageText("level.VNV.cp2l_r", DEF, ATT) (cp2) ... end, 1)
    OnFinishNeutralizeTeam(function (ShowMessageText("level.VNV.cp2l_c", DEF, ATT) (cp2) ... end, 2)

Jedi Admin
User avatar
Posts: 11087
Joined: Wed Sep 07, 2005 11:42 pm
Location: Indiana
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set

RE: CP Message Code

Postby Teancum » Wed Dec 06, 2006 7:41 pm

It's probably going to have to go under PostLoad() ScriptInit() is ran while the level is loading to get all the assets ready.

Old School Staff
User avatar
Posts: 2059
Joined: Wed Feb 23, 2005 9:54 am

RE: CP Message Code

Postby Qdin » Thu Dec 07, 2006 4:28 am

that's in the .LUA then :lol: I'm pretty sure I've seen something alike when i Localized.

Jedi Admin
User avatar
Posts: 2544
Joined: Sun Mar 05, 2006 12:00 am
Location: Australia

RE: CP Message Code

Postby Penguin » Thu Dec 07, 2006 5:01 am

they still got the BF1 localiztion.

still no help. I'm complety stuck. Maybe an expert coder could help me with this simple code?

Old School Staff
User avatar
Posts: 2059
Joined: Wed Feb 23, 2005 9:54 am

Postby Qdin » Thu Dec 07, 2006 9:54 am

But where do we FIND such 'Experts'...? :shock:

Jedi Admin
User avatar
Posts: 11087
Joined: Wed Sep 07, 2005 11:42 pm
Location: Indiana
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set

Postby Teancum » Thu Dec 07, 2006 12:41 pm

Oh duh lolz--- it probably needs to be in ObjectiveConquest.lua

archer01

Postby archer01 » Thu Dec 07, 2006 1:53 pm

OFF-TOPIC (sort of)

Teancum wrote:Oh duh lolz--- it probably needs to be in ObjectiveConquest.lua


Nah, all Lua scripts are treated the same way by the game engine. The only "special" situation is where a script is called by the exe: in that case only the name of the script file and the functions it contains have to have the correct names, and must do what is expected of them (mostly interface stuff). Any scripts read in by ScriptCB_DoFile() are not called by the exe 'directly', but by the Lua interface/engine instead. The only time you need to edit those scripts is when you are using them yourself, but they are doing something "unwanted".


ON-TOPIC

Here's a "grunt-work" way of doing it...

Code: Select all
-- This would go into ScriptPostLoad()
-- and you would have one for each team capturing CPs

OnFinishCaptureTeam(
   function(cPost)
      local pName = GetEntityName(cPost)      -- Gets the name of the post that was captured
      
      ShowMessageText("level.VNV." .. pName .. "_r")      -- Show this string to all teams
   end,
   teamNumber -- Team number for the strings
)

-- the ".." is Lua's concatenate, ie connecting two strings together
-- If the post's name was "cp1" then the line above should create "level.VNV.cp1_r"
-- Just make sure you have a localized string for each side and CP otherwise it will show as "NULL"


Now there "should" be a better way of doing this; like having a delimited string that is filled in with other localized strings at runtime. However, I have only seen the exe do stuff like that, and haven't seen any evidence of a way to do it through the Lua interface. Mind you, all because I haven't seen any evidence, doesn't mean there isn't a way; only that it was never done in the scripts I've looked through.

P.S.
I wrote the code up quickly and haven't tested it. If there is a syntax error or something, just message me about it.

Major
User avatar
Posts: 501
Joined: Mon Apr 17, 2006 1:44 pm

Postby MasterSkywalker » Thu Dec 07, 2006 4:04 pm

I'm gonna test it out for you guys. Gonna let you know if it works.

Soul

EDIT: No errors in the LUA so far...
EDIT2: Nope, didn't work. This is my code:
Hidden/Spoiler:
function ScriptPostLoad()

-- This would go into ScriptPostLoad()
-- and you would have one for each team capturing CPs

OnFinishCaptureTeam(
function(cPost)
local pName = GetEntityName(cPost) -- Gets the name of the post that was captured

ShowMessageText("level.MF3.CP1_r") -- Show this string to all teams
ShowMessageText("level.MF3.CP2_r")
ShowMessageText("level.MF3.CP3_r")
end,
teamNumber -- Team number for the strings
)

OnFinishNeutralize(
function(cPost)
local pName = GetEntityName(cPost) -- Gets the name of the post that was captured

ShowMessageText("level.MF3.CP1_r") -- Show this string to all teams
ShowMessageText("level.MF3.CP2_r")
ShowMessageText("level.MF3.CP3_r")
end,
teamNumber -- Team number for the strings
)

-- the ".." is Lua's concatenate, ie connecting two strings together
-- If the post's name was "cp1" then the line above should create "level.VNV.cp1_r"
-- Just make sure you have a localized string for each side and CP otherwise it will show as "NULL"

--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "cp1"}
cp2 = CommandPost:New{name = "cp2"}
cp3 = CommandPost:New{name = "cp3"}

--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF,
textATT = "game.modes.con",
textDEF = "game.modes.con2",
multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)

conquest:Start()

EnableSPHeroRules()

end

Jedi Admin
User avatar
Posts: 11087
Joined: Wed Sep 07, 2005 11:42 pm
Location: Indiana
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set

Postby Teancum » Thu Dec 07, 2006 4:21 pm

ShowMessageText("level.MF3.CP1_r")

is not equal to

ShowMessageText("level.VNV." .. pName .. "_r")



ShowMessageText("level.MF3." .. pName .. "_r") would be what you need, and only one time, not 3.

archer01

Postby archer01 » Thu Dec 07, 2006 5:12 pm

Teancum's correct. The concatenated string (which works in a "semi-automatic" fashion) is a cleaner way of doing it, instead of having a bunch of "if" and "elseif" statements strung together (in my opinion anyway). Also, don't forget to change the teamNumber to the team the listener (the "On" call) is for.

Here's how that function works (step-by-step):
1- CP "cp2" is captured by team 1
2- The function pointed to by OnFinishCaptureTeam() that was watching for team 1 captures is called. The pointer to the CP is also passed to the function. Note: I use the term "pointers", but really they are just reference numbers used by the exe in the background.
3- "local pName = GetEntityName(cPost)" creates a temporary variable called pName and sets it to the name of the CP that was captured. So now pName = "cp2".
4- ShowMessageText("level.VNV." .. pName .. "_r") is executed by the Lua engine in a two-step process. First it concatenates the string inside the brackests. So it takes the first string "level.VNV." combines it with pName then combines that combo with "_r". In this case it would create: "level.VNV.cp2_r".
5- ShowMessageText() is now called using the new string. So it acts like a ShowMessageText("level.VNV.cp2_r") call.
6- ShowMessageText() goes to the localization database, grabs the localizer string "level.VNV.cp2_r", then spits it out onto the screen.
7- Game execution continues...

It may seem a little confusing, but read it over a few times. I tried to be as clear as I could, but I'm often terrible at explaining things like this.


Here's the code again since this post is on a different page:
Code: Select all
-- This would go into ScriptPostLoad()
-- and you would have one for each team capturing CPs

OnFinishCaptureTeam(
   function(cPost)
      local pName = GetEntityName(cPost)      -- Gets the name of the post that was captured
     
      ShowMessageText("level.VNV." .. pName .. "_r")      -- Show this string to all teams
   end,
   teamNumber -- Team number for the strings (don't forget to change me)
)

-- the ".." is Lua's concatenate, ie connecting two strings together
-- If the post's name was "cp1" then the line above should create "level.VNV.cp1_r"
-- Just make sure you have a localized string for each side and CP otherwise it will show as "NULL"

Jedi Admin
User avatar
Posts: 2544
Joined: Sun Mar 05, 2006 12:00 am
Location: Australia

Postby Penguin » Thu Dec 07, 2006 6:24 pm

Okay, thanks. I should be able to do the rest of the coding now :p ((losing CPS, etc))

Thanks all who helped!

Major
User avatar
Posts: 501
Joined: Mon Apr 17, 2006 1:44 pm

Postby MasterSkywalker » Fri Dec 08, 2006 2:07 pm

@Teancum and archer01:Thanks dudes. :D
I'm also gonna test it for other modders out there that could use this function ^^

Soul -- Merry X-mas!!

Return to SWBF2 Modding

Who is online

Users browsing this forum: MileHighGuy and 2 guests