Choose vehicle...
by Justin Morris · in Torque Game Engine · 01/21/2005 (12:05 am) · 17 replies
Ok ive searched this and i saw some info about it in other posts... but i cant get it working properly...
ok i have a GUI that allows the player to choose 1 of 2 vehicles. this value is then saved to $Vehicle
i then changed:
%conn.setConnectArgs($pref::Player::Name);
to:
%conn.setConnectArgs($pref::Player::Name, $Vehicle);
then in common/server/scripts/clientconnection.cs
i have:
function GameConnection::onConnect( %client, %name, %vehe )
{
if(%vehe)
{
%client.armor = %vehe;
}
else
{
%client.armor = "Baja";
}
.
.
.
}
now for some reason, $Vehicle is not making it to "GameConnection::onConnect" because the player will always spawn as baha... i know this because if i change the above to:
function GameConnection::onConnect( %client, %name, %vehe )
{
if($Vehicle)
{
%client.armor = $Vehicle;
}
else
{
%client.armor = "Baja";
}
.
.
.
}
everything is fine and dandy... until you go multiplayer, then everyone has the same vehicle as the person running the server. i dont see why this is not working, unless ofcourse i am overlooking something over and over again.
ok i have a GUI that allows the player to choose 1 of 2 vehicles. this value is then saved to $Vehicle
i then changed:
%conn.setConnectArgs($pref::Player::Name);
to:
%conn.setConnectArgs($pref::Player::Name, $Vehicle);
then in common/server/scripts/clientconnection.cs
i have:
function GameConnection::onConnect( %client, %name, %vehe )
{
if(%vehe)
{
%client.armor = %vehe;
}
else
{
%client.armor = "Baja";
}
.
.
.
}
now for some reason, $Vehicle is not making it to "GameConnection::onConnect" because the player will always spawn as baha... i know this because if i change the above to:
function GameConnection::onConnect( %client, %name, %vehe )
{
if($Vehicle)
{
%client.armor = $Vehicle;
}
else
{
%client.armor = "Baja";
}
.
.
.
}
everything is fine and dandy... until you go multiplayer, then everyone has the same vehicle as the person running the server. i dont see why this is not working, unless ofcourse i am overlooking something over and over again.
About the author
#2
Basically the way you have it set up armor is decided based on the status of vehicle is true or not. If it is true then armor is vehe if it is false then it is baja.
So basically, I guess what I am saying is that when selecting a vehicle from your gui the $vehicle need to be true or false or in this case 1 or 0
01/21/2005 (1:00 am)
Looking at that, I don't think I was to clear. Basically the way you have it set up armor is decided based on the status of vehicle is true or not. If it is true then armor is vehe if it is false then it is baja.
So basically, I guess what I am saying is that when selecting a vehicle from your gui the $vehicle need to be true or false or in this case 1 or 0
#3
the actual command called from the button is $Vehicle = "Baja"; the editor made it $Vehicle = \"Baja\";
does it need to be single qutes maybe? like $Vehicle = 'Baja'; ?
01/21/2005 (1:04 am)
My gui is quite simple, so far its 2 buttons for 2 possible vehicles at this time, when one of the buttons is clicked it sets $Vehicle to a string corresponding to the vehicle "Baja" etc.the actual command called from the button is $Vehicle = "Baja"; the editor made it $Vehicle = \"Baja\";
does it need to be single qutes maybe? like $Vehicle = 'Baja'; ?
#4
01/21/2005 (1:06 am)
With "if($Vehicle)" im just trying to determine if they clicked a button or not, if $Vehicle has no value it goes to else and sets them up with the default vehicle.
#5
edit** Just noticed an error in the log...
Error: cannot change namespace parent linkage for baja from GuiButtonCtrl to WheeledVehicleData.
and also i verified that $Vehicle is not being sent to onConnect with the following echoes...
echo("Entering onConnect!!!");
echo("Vehe is being set if you see it below!");
echo(%vehe);
and i get...
----
Entering onConnect!!!
Vehe is being set if you see it below!
----
01/21/2005 (1:08 am)
I also forgot to add that i had also tried commenting out the if/else and just tried setting %client.armor regardless of results with %vehe and that did not work.edit** Just noticed an error in the log...
Error: cannot change namespace parent linkage for baja from GuiButtonCtrl to WheeledVehicleData.
and also i verified that $Vehicle is not being sent to onConnect with the following echoes...
echo("Entering onConnect!!!");
echo("Vehe is being set if you see it below!");
echo(%vehe);
and i get...
----
Entering onConnect!!!
Vehe is being set if you see it below!
----
#6
Sometime today, I will try to do this myself to see how I can go about getting a person to switch between 2 different vehicles.
Without seeing all of your code, it's hard for me to understand exactly what the issue is. If you can,please send me the script files and I can take a better look at them. I don't need the gui or the models. just the scripts that you made changes too. My address is on file.
EDIT: I probably Don't even need you to send the code. Just answer this.
I know it's a network game but what I need to know is if they have the car when they start the game or the gui is for them to switch cars while in game. If its the first then the answer would be pretty simple
01/21/2005 (6:02 am)
Ok.Sometime today, I will try to do this myself to see how I can go about getting a person to switch between 2 different vehicles.
Without seeing all of your code, it's hard for me to understand exactly what the issue is. If you can,please send me the script files and I can take a better look at them. I don't need the gui or the models. just the scripts that you made changes too. My address is on file.
EDIT: I probably Don't even need you to send the code. Just answer this.
I know it's a network game but what I need to know is if they have the car when they start the game or the gui is for them to switch cars while in game. If its the first then the answer would be pretty simple
#7
Going by the car racing demo the first thing I did was create a fake variable name $vehicle and added the line $vehicle=car1 to the standard start game gui, since I didn't want to create a gui.
The second thing I did was go to C:\Torque\SDK\example\starter.racing\server\scripts\car.cs and found the
Code to create the car:
I replaced DefaultCar with Car1
The second thing I did was create another wheeled vehicle data(since theres 2 cars and named that Car2
Ok so now we have 2 cars and a variable $vehicle thats either going to be car1 or car2 depending on how your Gui selects which car.
Next i went to C:\Torque\SDK\example\starter.racing\server\scripts\game.cs and found this code:
And thats it. When you start the game and pick your car it will start you with the car that you selected with the gui. This is of course only good if you selected the car before you started the mission.
I hope that helps somewhat
01/21/2005 (7:32 am)
So here is what I did. Going by the car racing demo the first thing I did was create a fake variable name $vehicle and added the line $vehicle=car1 to the standard start game gui, since I didn't want to create a gui.
The second thing I did was go to C:\Torque\SDK\example\starter.racing\server\scripts\car.cs and found the
Code to create the car:
datablock WheeledVehicleData(DefaultCar)
{
category = "Vehicles";
shapeFile = "~/data/shapes/buggy/buggy.dts";
....snip.....I replaced DefaultCar with Car1
The second thing I did was create another wheeled vehicle data(since theres 2 cars and named that Car2
datablock WheeledVehicleData(Car2)
{
category = "Vehicles";
shapeFile = "~/data/shapes/buggy/buggy.dts";
....snip.....Ok so now we have 2 cars and a variable $vehicle thats either going to be car1 or car2 depending on how your Gui selects which car.
Next i went to C:\Torque\SDK\example\starter.racing\server\scripts\game.cs and found this code:
// Create the player object
%car = new WheeledVehicle() {
dataBlock = DefaultCar;
client = %this;From there I just added a if statement:// Create the player object
If(vehicle="car1") {
%car = new WheeledVehicle() {
dataBlock = car1;}
}
Else
{
%car = new WheeledVehicle() {
dataBlock = car2;}
}
client = %this;And thats it. When you start the game and pick your car it will start you with the car that you selected with the gui. This is of course only good if you selected the car before you started the mission.
I hope that helps somewhat
#8
01/21/2005 (11:47 am)
Thats similar to what i have, but if im not mistaken, using the global variable "$vehicle" to determine the players car will give them whatever the server selected. some how the $vehicel needs to be passed to the client connections to make it a local client variable. but the problem i ran into is that its not being passed to the connection arguments.
#9
01/22/2005 (2:24 am)
I just wanted to let it be known, that i got vehicle selection working, and man did i feel dumb.... i was forgetting to add in the vehicle type variable for the connection args in the start game function, i only had them in joinserver, so naturally when i tested it would not work for me seems how i was running the server not joining it. anyways.... thanks for any help.
#10
Is there by any chance a working example with vehicle selection gui's about ? if not any chance of setting 1 demo up maybe ? I'd really appreciate any help. Thx
03/17/2005 (4:34 pm)
Hello Justin and Charlie, ive recently purchased the TGE SDK and now looking into these things and come across this thread on "vehicle selection".Is there by any chance a working example with vehicle selection gui's about ? if not any chance of setting 1 demo up maybe ? I'd really appreciate any help. Thx
#12
03/18/2005 (12:09 am)
My vehicle selection GUI was really really simple and low class since this was just an experimental game to play with my friends... basically all i did was add 2 buttons to the menu screen GUI and have them set the vehicle type variable when clicked. if they didnt click either button (left the variable unset) it would choose for them... i have since deleted the experimental project so i cant give any actual code i had =/ sorry.
#14
When you run in single player mode, yes, the server $vehicle will override the client $vehicle and vice-versa, depending on which one was defined first.
But, when the server and the client are in different machines, the server $vechicle will be different than the clients' $vehicles. Global variables don't proagate across the network automagically. That's why commandToServer and commandToClient exists.
So, to get something that works both in single and multi, try to name globals that will affect both client and server code differently, like $Client::vehicle and $Server::vehicle.
03/18/2005 (6:48 am)
Quote:Thats similar to what i have, but if im not mistaken, using the global variable "$vehicle" to determine the players car will give them whatever the server selected. some how the $vehicel needs to be passed to the client connections to make it a local client variable. but the problem i ran into is that its not being passed to the connection arguments.
When you run in single player mode, yes, the server $vehicle will override the client $vehicle and vice-versa, depending on which one was defined first.
But, when the server and the client are in different machines, the server $vechicle will be different than the clients' $vehicles. Global variables don't proagate across the network automagically. That's why commandToServer and commandToClient exists.
So, to get something that works both in single and multi, try to name globals that will affect both client and server code differently, like $Client::vehicle and $Server::vehicle.
#15
What I want to do is use only one car.cs file but allow players to create their own car meshes and specs and load them in the game. I'm thinking I can have different directories with the car data and reference the directory name to load each car.
For example, under the data/cars directory, i want to have a directory called hotrod that contains the files chasis.dts, skin.png and specs.cs. Each car follows the same directory/file format so in theory, to load each car, i just have to reference the correct car directory.
Anyone have any suggestions?
Thank you.
09/10/2005 (12:08 pm)
Hello all. This solution will work for my projects but limits the number of vehicles the game can have to only the preset datablocks in cars.cs.What I want to do is use only one car.cs file but allow players to create their own car meshes and specs and load them in the game. I'm thinking I can have different directories with the car data and reference the directory name to load each car.
For example, under the data/cars directory, i want to have a directory called hotrod that contains the files chasis.dts, skin.png and specs.cs. Each car follows the same directory/file format so in theory, to load each car, i just have to reference the correct car directory.
Anyone have any suggestions?
Thank you.
#16
Thanks!
09/10/2005 (12:47 pm)
I'm looking at the same idea except I'm loading my data off of my LAMP server with the car data in mysql. If you find out how to do your technique, let me know what you found out because I could probably apply it to my situation :)Thanks!
#17
Or write a CarConfigManager and use a NetEvent to propagate new car configs on the fly.
09/11/2005 (7:27 pm)
Move all the variables you want to tweak into the main object rather than using datablocks?Or write a CarConfigManager and use a NetEvent to propagate new car configs on the fly.
Torque Owner Charlie Malbaurn