Lua question (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

Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 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: Lua question

Post by Ace_Azzameen_5 »

Your second 'If' has a capital I, it needs to be 'if'.

You should download and use a LUA Id that will check for those errors, like LUA edit.

But back up your stuff first, LUA edit has a nasty habit of deleting all the files in the folder of the file it is workinh on when you close it.
User avatar
Eagle Eye
First Lance Corporal
First Lance Corporal
Posts: 129
Joined: Thu Nov 01, 2007 12: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
Location: Belgium
Contact:

Re: Lua question

Post by Eagle Eye »

ok i did what u said, i changed the "If" to "if" but when i play the game my unit stay respawns in the vehicle at both cp's of the same team. i have to respawn in the vehicle at 1 command post and not with both...

So there must be something wrong with this line:
if GetCommandPostTeam("tfa-cp2") == 2 then
or do i have just need to put another function in it?
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: Lua question

Post by Teancum »

Wait, do we know how to force players into vehicles for sure now? If we do I'm soooo bringing back VH mode.
User avatar
Eagle Eye
First Lance Corporal
First Lance Corporal
Posts: 129
Joined: Thu Nov 01, 2007 12: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
Location: Belgium
Contact:

Re: Lua question

Post by Eagle Eye »

yes, for forcing a player into a vehicle by respawning u need this script:

Code: Select all

OnCharacterSpawn(
function(player)
if GetObjectTeam(GetCharacterUnit(player)) == 2 then
EnterVehicle(player, "Vehspawn1")
end
end
end
)
But what i want is that u can only respawn in the vehicle from 1 cp and not from all cp's in the default team (team 2 in this case)
EDIT: I need to add some kind of commandpost function so i can give the name of the commandpost in the script
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: Lua question

Post by Teancum »

What is "Vehspawn1", the actual vehicle spawn odf from ZeroEdit?
User avatar
Eagle Eye
First Lance Corporal
First Lance Corporal
Posts: 129
Joined: Thu Nov 01, 2007 12: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
Location: Belgium
Contact:

Re: Lua question

Post by Eagle Eye »

EDIT: the "Vehspawn1" is the name of my vehicle
I just renamed the odf in ZE yes
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: Lua question

Post by Teancum »

I'm just making sure I'm following you:

1-You placed the vehicle spawn in ZE
2-You renamed that spawn to Vehspawn1 (the property and not the actual name of the odf)
3-You went from there...
User avatar
Eagle Eye
First Lance Corporal
First Lance Corporal
Posts: 129
Joined: Thu Nov 01, 2007 12: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
Location: Belgium
Contact:

Re: Lua question

Post by Eagle Eye »

yes like u said
(I placed the com_item_vehicle_spawn, and renamed it to Vehspawn1 at the 'name' inputfield under 'odf file:' in ZE)

the vehicle name is not realy the problem... i can respawn in the vehicle..
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: Lua question

Post by Teancum »

Nesting functions in this case might work, but its probably better to put them together as one conditional statement:

Code: Select all

If GetObjectTeam(GetCharacterUnit(player)) ==  2 && GetCommandPost(GetCharacterUnit(player)) == "tfa-cp2" then
EnterVehicle(player, "Vehspawn1")
end
That's not 100% correct code, but you get the idea. The && is saying if both conditions are true then do what's listed below. Now I'm not sure of the usage of && in lua, but that should be correct. I'm also not sure if GetCommandPost() is a real function, but I used it as an example.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Lua question

Post by Maveritchell »

Teancum wrote:Nesting functions in this case might work, but its probably better to put them together as one conditional statement:

Code: Select all

If GetObjectTeam(GetCharacterUnit(player)) ==  2 && GetCommandPost(GetCharacterUnit(player)) == "tfa-cp2" then
EnterVehicle(player, "Vehspawn1")
end
That's not 100% correct code, but you get the idea. The && is saying if both conditions are true then do what's listed below. Now I'm not sure of the usage of && in lua, but that should be correct. I'm also not sure if GetCommandPost() is a real function, but I used it as an example.
&& in .lua is simply "and." I don't know the function you're talking about off the top of my head, I'll look it up later. To check in the meantime, try psych0fred's LUA callback guide or the scripting_system.doc.
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: Lua question

Post by Teancum »

Code: Select all

If GetObjectTeam(GetCharacterUnit(player)) ==  2 and GetCommandPostTeam("tfa-cp2") == 2 then
EnterVehicle(player, "Vehspawn1")
end
Hmm, GetCommandPost() indeed isn't a valid function. That's as close to your code as I can get, but the problem with GetCommandPostTeam() is that it's going to check to see if that CP belongs to team 2, but necessarily whether you're spawning from it.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Lua question

Post by Maveritchell »

You might be able to nest an OnEnterRegion event inside the OnCharacterSpawn event. I'm pretty sure that works; I've nested timer functions inside enterregion functions before.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Lua question

Post by [RDH]Zerted »

I don't know of a way to determine which CP a unit spawns at, however you can get around it.

Make the CP spawn units to a location in the map where it is impossible to get to (maybe under the ground). Put a region at that location. Now whenever anyone enters that region (which they do when they spawn), force them into the vehicle. It shouldn't matter that the vehicle is not near where their unit is.

Edit: I never thought about nesting event callbacks. I don't know it that works or not. The reason you can't just use OnEnterRegion is that it would put anyone trying to capture the CP into the vehicles too.
Last edited by [RDH]Zerted on Thu Jan 03, 2008 4:12 pm, edited 1 time in total.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Lua question

Post by Maveritchell »

[RDH]Zerted wrote:Make the CP spawn units to a location in the map where it is impossible to get to (maybe under the ground). Put a region at that location. Now whenever anyone enters that region (which they do when they spawn), force them into the vehicle. It shouldn't matter that the vehicle is not near where their unit is.
I believe that doing that is unnecessary. Simply having a region at a command post that is only triggered when someone spawns at the command post should be all that is required. Respawning at a command post is all that is necessary to make someone "enter" the region, and as long as the OnEnterRegion is nested within the OnCharacterSpawn or OnCharacterChangeClass, it shouldn't be triggered by someone just walking up.
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: Lua question

Post by Teancum »

*takes notes*

Yeah, VH mode is definitely gonna make a comeback.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Lua question

Post by Maveritchell »

Maveritchell wrote:
[RDH]Zerted wrote:Make the CP spawn units to a location in the map where it is impossible to get to (maybe under the ground). Put a region at that location. Now whenever anyone enters that region (which they do when they spawn), force them into the vehicle. It shouldn't matter that the vehicle is not near where their unit is.
I believe that doing that is unnecessary. Simply having a region at a command post that is only triggered when someone spawns at the command post should be all that is required. Respawning at a command post is all that is necessary to make someone "enter" the region, and as long as the OnEnterRegion is nested within the OnCharacterSpawn or OnCharacterChangeClass, it shouldn't be triggered by someone just walking up.
Aha! I knew I'd seen this somewhere. I couldn't find it and assumed it didn't exist (it still might not work) since I didn't see it in the LUA callback doc. However, the scripting system doc mentions it in passing:

Code: Select all

IsCharacterInRegion(player, “regionName”)
If that does what it should, you could use that instead of nesting OnEnterRegion inside OnCharacterSpawn by making it check to see whether the unit is spawning inside of a region placed over the CP.
User avatar
Eagle Eye
First Lance Corporal
First Lance Corporal
Posts: 129
Joined: Thu Nov 01, 2007 12: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
Location: Belgium
Contact:

Re: Lua question

Post by Eagle Eye »

Teancum wrote:

Code: Select all

If GetObjectTeam(GetCharacterUnit(player)) ==  2 && GetCommandPost(GetCharacterUnit(player)) == "tfa-cp2" then
EnterVehicle(player, "Vehspawn1")
end
Teancum wrote:

Code: Select all

If GetObjectTeam(GetCharacterUnit(player)) ==  2 and GetCommandPostTeam("tfa-cp2") == 2 then
EnterVehicle(player, "Vehspawn1")
end
I tryed both codes with no results (also changed the "If" to "if" and the end to double end at the last code (error in munge))
Maveritchell wrote:Simply having a region at a command post that is only triggered when someone spawns at the command post should be all that is required.
Do i simply need to add a new region (over the spawn nodes and cp) in ZE and name it like "Region0" at the region ID and class properties?
I'm not good in lua, so can someone give me an example script of the OnEnterRegion idea?
I got already this:

Code: Select all

OnCharacterSpawn(
function(player)
OnEnterRegion: function (IsCharacterInRegion(player, "Region0")), name or region
EnterVehicle(player, "Vehspawn1")
end
end
)
Thanks already for helping!
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Lua question

Post by Maveritchell »

You don't need the OnEnterRegion event I believe, that's what I was just saying. You'd want to make a region that encircled the command post (only needs to be as big as the 'entry region' for the CP is, setting it to radii of 3 or 4 should be fine). We'll call that region "forcevehiclereg." Your code might look something like this:

Code: Select all

If GetCharacterTeam(player) ==  2 and IsCharacterInRegion(player, “forcevehiclereg”) then
EnterVehicle(player, "Vehspawn1")
end
User avatar
Eagle Eye
First Lance Corporal
First Lance Corporal
Posts: 129
Joined: Thu Nov 01, 2007 12: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
Location: Belgium
Contact:

Re: Lua question

Post by Eagle Eye »

ok i did what u said... In ZE i maked a region circle around the cp and named forcevehiclereg and then i saved ZE
like u can see on the image:
Image

then i added your script, munge and when i respawn, i respawn normal and not anymore in the vehicle, also with both cp's
i think i need to activate the region with
ActivateRegion("forcevehiclereg") or something (not sure)
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Lua question

Post by Maveritchell »

Yeah, if you're going to be using a region in a .lua, it's best to put ActivateRegion("regionname") in there. Sorry that I didn't mention that.
Post Reply