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

Post Reply
Qdin
Old School Staff
Posts: 2059
Joined: Wed Feb 23, 2005 9:54 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: CP Message Code

Post by Qdin »

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?)
MasterSkywalker
Major
Major
Posts: 501
Joined: Mon Apr 17, 2006 1:44 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: CP Message Code

Post by MasterSkywalker »

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] --=======================================
-- 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[/code][/size]
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11079
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

RE: CP Message Code

Post by Teancum »

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?
MasterSkywalker
Major
Major
Posts: 501
Joined: Mon Apr 17, 2006 1:44 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: CP Message Code

Post by MasterSkywalker »

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

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

RE: CP Message Code

Post by Teancum »

True. Hadn't thought of that.
MasterSkywalker
Major
Major
Posts: 501
Joined: Mon Apr 17, 2006 1:44 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: CP Message Code

Post by MasterSkywalker »

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
Penguin
Jedi Admin
Jedi Admin
Posts: 2541
Joined: Sun Mar 05, 2006 12:00 am
Location: Australia

RE: CP Message Code

Post by Penguin »

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)
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11079
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

RE: CP Message Code

Post by Teancum »

It's probably going to have to go under PostLoad() ScriptInit() is ran while the level is loading to get all the assets ready.
Qdin
Old School Staff
Posts: 2059
Joined: Wed Feb 23, 2005 9:54 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: CP Message Code

Post by Qdin »

that's in the .LUA then :lol: I'm pretty sure I've seen something alike when i Localized.
Penguin
Jedi Admin
Jedi Admin
Posts: 2541
Joined: Sun Mar 05, 2006 12:00 am
Location: Australia

RE: CP Message Code

Post by Penguin »

they still got the BF1 localiztion.

still no help. I'm complety stuck. Maybe an expert coder could help me with this simple code?
Qdin
Old School Staff
Posts: 2059
Joined: Wed Feb 23, 2005 9:54 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Post by Qdin »

But where do we FIND such 'Experts'...? :shock:
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11079
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

Post by Teancum »

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

Post by archer01 »

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.
MasterSkywalker
Major
Major
Posts: 501
Joined: Mon Apr 17, 2006 1:44 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Post by MasterSkywalker »

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
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11079
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

Post by Teancum »

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

Post by archer01 »

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"
Penguin
Jedi Admin
Jedi Admin
Posts: 2541
Joined: Sun Mar 05, 2006 12:00 am
Location: Australia

Post by Penguin »

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

Thanks all who helped!
MasterSkywalker
Major
Major
Posts: 501
Joined: Mon Apr 17, 2006 1:44 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Post by MasterSkywalker »

@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!!
Post Reply