Lua question (FAQ)
Moderator: Moderators
-
- Jedi
- Posts: 1119
- Joined: Sat Apr 23, 2005 8:52 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
Re: Lua question
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.
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.
- Eagle Eye
- First Lance Corporal
- Posts: 129
- Joined: Thu Nov 01, 2007 12:44 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Belgium
- Contact:
Re: Lua question
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?
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?
- Teancum
- Jedi Admin
- Posts: 11080
- Joined: Wed Sep 07, 2005 11:42 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Indiana
Re: Lua question
Wait, do we know how to force players into vehicles for sure now? If we do I'm soooo bringing back VH mode.
- Eagle Eye
- First Lance Corporal
- Posts: 129
- Joined: Thu Nov 01, 2007 12:44 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Belgium
- Contact:
Re: Lua question
yes, for forcing a player into a vehicle by respawning u need this script:
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
Code: Select all
OnCharacterSpawn(
function(player)
if GetObjectTeam(GetCharacterUnit(player)) == 2 then
EnterVehicle(player, "Vehspawn1")
end
end
end
)
EDIT: I need to add some kind of commandpost function so i can give the name of the commandpost in the script
- Teancum
- Jedi Admin
- Posts: 11080
- Joined: Wed Sep 07, 2005 11:42 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Indiana
Re: Lua question
What is "Vehspawn1", the actual vehicle spawn odf from ZeroEdit?
- Eagle Eye
- First Lance Corporal
- Posts: 129
- Joined: Thu Nov 01, 2007 12:44 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Belgium
- Contact:
Re: Lua question
I just renamed the odf in ZE yesEDIT: the "Vehspawn1" is the name of my vehicle
- Teancum
- Jedi Admin
- Posts: 11080
- Joined: Wed Sep 07, 2005 11:42 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Indiana
Re: Lua question
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...
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...
- Eagle Eye
- First Lance Corporal
- Posts: 129
- Joined: Thu Nov 01, 2007 12:44 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Belgium
- Contact:
Re: Lua question
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..
(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..
- Teancum
- Jedi Admin
- Posts: 11080
- Joined: Wed Sep 07, 2005 11:42 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Indiana
Re: Lua question
Nesting functions in this case might work, but its probably better to put them together as one conditional statement:
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.
Code: Select all
If GetObjectTeam(GetCharacterUnit(player)) == 2 && GetCommandPost(GetCharacterUnit(player)) == "tfa-cp2" then
EnterVehicle(player, "Vehspawn1")
end
- Maveritchell
- Jedi Admin
- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: Lua question
&& 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.Teancum wrote:Nesting functions in this case might work, but its probably better to put them together as one conditional statement:
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.Code: Select all
If GetObjectTeam(GetCharacterUnit(player)) == 2 && GetCommandPost(GetCharacterUnit(player)) == "tfa-cp2" then EnterVehicle(player, "Vehspawn1") end
- Teancum
- Jedi Admin
- Posts: 11080
- Joined: Wed Sep 07, 2005 11:42 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Indiana
Re: Lua question
Code: Select all
If GetObjectTeam(GetCharacterUnit(player)) == 2 and GetCommandPostTeam("tfa-cp2") == 2 then
EnterVehicle(player, "Vehspawn1")
end
- Maveritchell
- Jedi Admin
- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: Lua question
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.
- [RDH]Zerted
- Gametoast Staff
- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: Lua question
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.
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.
- Maveritchell
- Jedi Admin
- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: Lua question
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.[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.
- Teancum
- Jedi Admin
- Posts: 11080
- Joined: Wed Sep 07, 2005 11:42 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Indiana
Re: Lua question
*takes notes*
Yeah, VH mode is definitely gonna make a comeback.
Yeah, VH mode is definitely gonna make a comeback.
- Maveritchell
- Jedi Admin
- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: Lua question
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:Maveritchell wrote: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.[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.
Code: Select all
IsCharacterInRegion(player, “regionName”)
- Eagle Eye
- First Lance Corporal
- Posts: 129
- Joined: Thu Nov 01, 2007 12:44 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Belgium
- Contact:
Re: Lua question
Teancum wrote:Code: Select all
If GetObjectTeam(GetCharacterUnit(player)) == 2 && GetCommandPost(GetCharacterUnit(player)) == "tfa-cp2" 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))Teancum wrote:Code: Select all
If GetObjectTeam(GetCharacterUnit(player)) == 2 and GetCommandPostTeam("tfa-cp2") == 2 then EnterVehicle(player, "Vehspawn1") end
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?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.
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
)
- Maveritchell
- Jedi Admin
- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: Lua question
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
- Eagle Eye
- First Lance Corporal
- Posts: 129
- Joined: Thu Nov 01, 2007 12:44 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Belgium
- Contact:
Re: Lua question
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:

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)
like u can see on the 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)
- Maveritchell
- Jedi Admin
- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: Lua question
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.