Page 2 of 3
Re: Lua question
Posted: Fri Jan 04, 2008 6:47 am
by Eagle Eye
I used this script and it doesn't work!

I just respawn on the normal way and not anymore in the vehicle...
Code: Select all
OnCharacterSpawn(
function(player)
if GetCharacterTeam(player) == 2 and IsCharacterInRegion(player, "forcevehiclereg") then
ActivateRegion("forcevehiclereg")
EnterVehicle(player, "Vehspawn1")
end
end
)
EDIT: after placed the region in ZE, do i need to update a file or is just saving fine?
Re: Lua question
Posted: Fri Jan 04, 2008 6:53 am
by Maveritchell
Does the BF2log spit out anything about either of those callbacks being bad?
Re: Lua question
Posted: Fri Jan 04, 2008 7:10 am
by Eagle Eye
yes here is my whole BF2log:
I had to switch the team because of autoassign in multiplay (don't know how to change it to player select in the bat file)
so here is my new script: (and also i replaced the forcevehiclereg region from the one team to the other team's cp)
Code: Select all
OnCharacterSpawn(
function(player)
if GetCharacterTeam(player) == 1 and IsCharacterInRegion(player, "forcevehiclereg") then
ActivateRegion("forcevehiclereg")
EnterVehicle(player, "Vehspawn4")
end
end
)
Re: Lua question
Posted: Fri Jan 04, 2008 9:42 am
by Teancum
I'd put ActivateRegion() in the scriptPostLoad() section of your mode lua, but that's just me. You're activating it after looking for it.
Re: Lua question
Posted: Mon Jan 07, 2008 12:27 pm
by Eagle Eye
Thanks teancum,
this is the working script based on: if you enter region (i placed region at the cp spawn point) then you enter a vehicle. When the vehicle is used by an other player, you enter the next vehicle (example: vehspawn2) etc...
so i finaly find out how to fix my problem, thanks everyone for help!
Code: Select all
ActivateRegion("forcevehiclereg")
testfunction = OnEnterRegion(
function(region, player)
if IsCharacterInRegion(player, "forcevehiclereg") then
EnterVehicle(player, "Vehspawn1")
elseif VehspawnNum == 1 then
EnterVehicle(player, "Vehspawn2")
elseif VehspawnNum == 2 then
EnterVehicle(player, "Vehspawn3")
VehspawnNum = VehspawnNum + 1
end
end,
"forcevehiclereg"
)
maybe this is usefull information for ppl who are looking for my question. And i hope ppl can use this.
Re: Lua question
Posted: Mon Jan 07, 2008 1:33 pm
by Teancum
Eagle Eye wrote:
maybe this is usefull information for ppl who are looking for my question. And i hope ppl can use this.
It's super-useful. I'm going to bring back VH (Vehicle Only) mode with this!
Re: Lua question
Posted: Mon Jan 07, 2008 1:37 pm
by Maveritchell
Unfortunately, it doesn't look like it has any sort of answer for what happens when you run out of vehiclespawns. You need to set up another conditional statement that backs you back to the first vehiclespawn if you get to your last one. Also, I think you can condense that code if you're going to use more vehiclespawns from:
Code: Select all
if IsCharacterInRegion(player, "forcevehiclereg") then
EnterVehicle(player, "Vehspawn1")
elseif VehspawnNum == 1 then
EnterVehicle(player, "Vehspawn2")
elseif VehspawnNum == 2 then
EnterVehicle(player, "Vehspawn3")
VehspawnNum = VehspawnNum + 1
to simply:
Code: Select all
if IsCharacterInRegion(player, "forcevehiclereg") then
EnterVehicle(player, "Vehspawn" .. (VehspawnNum + 1))
VehspawnNum = VehspawnNum + 1
That last code will make it so you don't have to set up a different condition for every different vehiclespawn, provided you keep using the naming convention "Vehspawn#" for your vehicle spawns.
Re: Lua question
Posted: Mon Jan 07, 2008 1:57 pm
by Eagle Eye
Thanks Maveritchell!

i thought my code worked, but i realise it doesn't work properly...
Re: Lua question
Posted: Mon Jan 07, 2008 2:19 pm
by [RDH]Zerted
Yes, I have some questions about your code.
Should you make sure the vehicle is really spawned and that no one is already in it? What does EnterVehicle() do under those conditions?
Shouldn't the vehicle be moved back to its starting location?
Do you want everyone to enter the vehicle or just the team members of the CP?
Also, OnEnterRegion and IsCharacterInRegion is redundant.
I think it should be more:
OnCharacterSpawn
If IsCharacterInRegion
Then force a vehicle spawn and force the new unit into the new vehicle
Additional step for VH mode: Disable manually entering vehicles and kill unit+vehicle on vehicle exit
Re: Lua question
Posted: Mon Jan 07, 2008 4:54 pm
by Eagle Eye
Um well i tested ur new code, but is doesn't work... Is there something wrong in the code?
The vehicles i use are named Vehspawn1; Vehspawn2; Vehspawn3 ecl...
When i respawn i just respawn on the normal way and not in the vehicle.
Re: Lua question
Posted: Mon Jan 07, 2008 5:28 pm
by Teancum
VehspawnNum is never defined before the if statement, so the game doesn't know what the initial value is.
Re: Lua question
Posted: Wed Jan 09, 2008 8:00 am
by Eagle Eye
You mean something like this?
This doesnt work, can someone tell me the right script to define the initial value?
Re: Lua question
Posted: Wed Jan 09, 2008 6:05 pm
by [RDH]Zerted
This code should work. I'm not sure if you want the
if num > maxNum then part or not.
Code: Select all
ActivateRegion("forcevehiclereg")
local VehspawnNum = 1
local VehspawnMaxNum = 4
testfunction = OnEnterRegionName(
function(region, player)
EnterVehicle(player, "Vehspawn" .. VehspawnNum)
VehspawnNum = VehspawnNum + 1
if VehspawnNum > VehspawnMaxNum then
VehspawnNum = 1
end
end,"forcevehiclereg"
)
Re: Lua question
Posted: Thu Jan 10, 2008 1:52 pm
by Eagle Eye
Thanks [RDH]Zerted
But i had to change your script cause when i tryed ur script, it doesn't work...(problem = no units and didn't respawn in vehicle)
So i changed ur script to this: ( i know its against ur principes to use the OnEnterRegion and IscharacterInRegion but it works)
Code: Select all
ActivateRegion("forcevehiclereg")
local VehspawnNum = 1
testfunction = OnEnterRegion(
function(region, player)
if IsCharacterInRegion(player, "forcevehiclereg") then
EnterVehicle(player, "Vehspawn" .. VehspawnNum)
VehspawnNum = VehspawnNum + 1
end
end,"forcevehiclereg"
)
So now i respawn into a vehicle, and also the droids, whats not realy a problem (= i want that the droids respawn also in the vehicles like the players)
But the problem is when all vehicles used (by respawned droids and players), and a droid want to respawn, he cant respawn in a vehicle and the game crash.
So i used the VehspawnMaxNum:
Code: Select all
ActivateRegion("forcevehiclereg")
local VehspawnNum = 1
local VehspawnMaxNum = 11
testfunction = OnEnterRegion(
function(region, player)
if IsCharacterInRegion(player, "forcevehiclereg") then
EnterVehicle(player, "Vehspawn" .. VehspawnNum)
VehspawnNum = VehspawnNum + 1
if VehspawnNum > VehspawnMaxNum then
VehspawnNum = 1
end
end,"forcevehiclereg"
)
If the VehspawnNum gets higher then the VehspawnMaxNum, (so all 11 vehicles are used), the script say u to respawn into Vehspawn1 (if VehspawnNum > VehspawnMaxNum then VehspawnNum = 1). But if the Vehspawn1 already used (all vehicles are taken) the script cant find the vehicle for the droid wich want to spawn and result = crash.
So my question is now: is it possible to chance this line:
to something else, so if the VehspawnMaxNum reached, the droid, when he respawn, just wacht for a vehicle that will spawn soon and enter it by walking.
Also the 'Name' in OnEnterRegionName( not works and has to be OnEnterRegion(
I almost found it!
Thanks in advance
Re: Lua question
Posted: Thu Jan 10, 2008 2:42 pm
by [RDH]Zerted
So when it reaches the max number, you want it to forever stop forcing players into vehicles?
Sorry about the OnEnterRegionName, I keep forgetting about that.
Re: Lua question
Posted: Thu Jan 10, 2008 4:29 pm
by Eagle Eye
Yes, but not forever. Only untill a new vehicle appears
EDIT: Ok im a step farther:
Code: Select all
ActivateRegion("forcevehiclereg")
local VehspawnNum = 1
local VehspawnMaxNum = 11
testfunction = OnEnterRegion(
function(region, player)
if IsCharacterInRegion(player, "forcevehiclereg") and VehspawnNum <= VehspawnMaxNum then
EnterVehicle(player, "Vehspawn" .. VehspawnNum)
VehspawnNum = VehspawnNum + 1
end
end,"forcevehiclereg"
)
Its not 100% good, sometimes he crash...
The only strange thing left is that also AI respawns in the vehicles...
Re: Lua question
Posted: Thu Jan 10, 2008 6:03 pm
by [RDH]Zerted
If you don't want the AI to be forced into vehicles, thats easy. Its
Re: Lua question
Posted: Fri Jan 11, 2008 2:56 pm
by Eagle Eye
Thanks Zerted
What can be wrong in this script? i realy cant find out why the game crash
sometimes..
Code: Select all
ActivateRegion("forcevehiclereg")
local VehspawnNum = 1
local VehspawnMaxNum = 11
testfunction = OnEnterRegion(
function(region, player)
if IsCharacterInRegion(player, "forcevehiclereg") and VehspawnNum <= VehspawnMaxNum then
EnterVehicle(player, "Vehspawn" .. VehspawnNum)
VehspawnNum = VehspawnNum + 1
end
end,"forcevehiclereg"
)
Look i found a problem:
I spawned a few times into a vehicle and died. After like 3 times, i spawn on the normal way when there are no vehicles anymore(= normal) So i wacht for a vehicle and when i saw one i repawned myself and tryed to spawn again into a vehicle but it doesn't works anymore (also not for the droids).
So when the VehspawnMaxNum reached (all 11 vehicles) i cant spawn into a vehicle anymore
By the way, the script stay adding numbers, also higher then 11 (also when the vehspawnmaxnum reached):
VehspawnNum = VehspawnNum
+ 1
So there must be a way, when the VehspawnMaxNum reached that the script repeat again to 1 (and not +1) only if there are new vehicles, if there not, you have to spawn on the normal way.
Soz for the bad english

Re: Lua question
Posted: Mon Jan 14, 2008 7:52 pm
by Maveritchell
You could save the work of having to make sure there was a vehicle available by using CreateEntity:
Code: Select all
CreateEntity(ODFname, optionalMatrix, optionalNameForVehicle)
You'd just use:
Code: Select all
EnterVehicle(player, CreateEntity("veh_walk_veh", "vehiclespawnnode"))
Not sure if that's the right way to call that matrix, but you get the gist.
Re: Lua question
Posted: Fri Jan 18, 2008 1:57 pm
by Eagle Eye
I dont now... I think i just should give up my project, i searched to long for this
This is my script now: i know the problem in game but dont now how to fix it in script