Page 1 of 3

Re: Lua question

Posted: Thu Jan 03, 2008 11:59 am
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.

Re: Lua question

Posted: Thu Jan 03, 2008 12:30 pm
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?

Re: Lua question

Posted: Thu Jan 03, 2008 1:30 pm
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.

Re: Lua question

Posted: Thu Jan 03, 2008 1:41 pm
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

Re: Lua question

Posted: Thu Jan 03, 2008 1:53 pm
by Teancum
What is "Vehspawn1", the actual vehicle spawn odf from ZeroEdit?

Re: Lua question

Posted: Thu Jan 03, 2008 1:57 pm
by Eagle Eye
EDIT: the "Vehspawn1" is the name of my vehicle
I just renamed the odf in ZE yes

Re: Lua question

Posted: Thu Jan 03, 2008 1:58 pm
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...

Re: Lua question

Posted: Thu Jan 03, 2008 2:02 pm
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..

Re: Lua question

Posted: Thu Jan 03, 2008 2:35 pm
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.

Re: Lua question

Posted: Thu Jan 03, 2008 2:56 pm
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.

Re: Lua question

Posted: Thu Jan 03, 2008 3:05 pm
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.

Re: Lua question

Posted: Thu Jan 03, 2008 3:52 pm
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.

Re: Lua question

Posted: Thu Jan 03, 2008 4:02 pm
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.

Re: Lua question

Posted: Thu Jan 03, 2008 4:08 pm
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.

Re: Lua question

Posted: Thu Jan 03, 2008 4:10 pm
by Teancum
*takes notes*

Yeah, VH mode is definitely gonna make a comeback.

Re: Lua question

Posted: Thu Jan 03, 2008 11:02 pm
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.

Re: Lua question

Posted: Fri Jan 04, 2008 5:50 am
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!

Re: Lua question

Posted: Fri Jan 04, 2008 6:03 am
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

Re: Lua question

Posted: Fri Jan 04, 2008 6:24 am
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)

Re: Lua question

Posted: Fri Jan 04, 2008 6:41 am
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.