Changing the player shape
by Jermaine Morgan · in Torque Game Engine · 06/11/2008 (8:38 pm) · 7 replies
I been searching but i cant seem to find anything.
What i'm trying to accomplish is when the player presses a button the shape file changes.
My character presses the "a" key and turns in a rat or something.
I read that there is no way to change the shapefile I would have to change the datablock. My question is how do i do this?
I found this code while searching but i just cant figure out how to use it.
%player.setDataBlock(mydatablockhere);
I tried placing that in a trigger so that when the player runs into the trigger he will change the data block but it wont work.
can someone help me with this?
What i'm trying to accomplish is when the player presses a button the shape file changes.
My character presses the "a" key and turns in a rat or something.
I read that there is no way to change the shapefile I would have to change the datablock. My question is how do i do this?
I found this code while searching but i just cant figure out how to use it.
%player.setDataBlock(mydatablockhere);
I tried placing that in a trigger so that when the player runs into the trigger he will change the data block but it wont work.
can someone help me with this?
About the author
#2
in client/scripts/default.bind.cs - add the following:
Next to add the server side of things to swap player datablocks.
Edit server/scripts/commands.cs and add at the bottom
Hopefully that should work for you, if not drop a post back here and I'll see what I did wrong. Although I've written this to swap using a keypress you can just as easily call that function from a trigger in your game, do remember that it will swap the player instantly.. I prefer to code some effect using particles to hide the player for a second while it swaps over.
06/12/2008 (10:04 am)
Jermaine - you're on the right path with using %player.setDatablock() but it all depends how you're working out what %player points at? this should be executed on the server side, I've no idea if this will work as I haven't tested it but try the following:in client/scripts/default.bind.cs - add the following:
// this adds a function and keymap to send the server a message that you want to swap players between
// two different models... A and B.
function changePlayer(%val)
{
if (%val)
{
if ($currentModel $= "A"
{
$currentModel = "B";
commandToServer('changePlayer',"B");
}
else {
$currentModel = "A";
commandToServer('changePlayer',"A");
}
}
}
// Map the "C" on the keyboard to our player
moveMap.bind( keyboard, C, showPlayerList );Next to add the server side of things to swap player datablocks.
Edit server/scripts/commands.cs and add at the bottom
function serverCmdChangePlayer(%client, %model)
{
if (%model $= "A")
{
%client.player.setDatablock(myDatablockA);
}
else {
%client.player.setDatablock(myDatablockB);
}
}Hopefully that should work for you, if not drop a post back here and I'll see what I did wrong. Although I've written this to swap using a keypress you can just as easily call that function from a trigger in your game, do remember that it will swap the player instantly.. I prefer to code some effect using particles to hide the player for a second while it swaps over.
#3
Thanks I will try that now.
I notice a little bug
One thing I assuming that the keybind you made in the first code block
"moveMap.bind( keyboard, C, showPlayerList );"
should be
moveMap.bind( keyboard, C, changePlayer );"
thanks again I will be trying this.
06/12/2008 (10:34 am)
@Andy RollinsThanks I will try that now.
I notice a little bug
One thing I assuming that the keybind you made in the first code block
"moveMap.bind( keyboard, C, showPlayerList );"
should be
moveMap.bind( keyboard, C, changePlayer );"
thanks again I will be trying this.
#4
Basically I'm just playing with fps starter kit
This is my console log
My default.bind.cs code is the same as the fps. starter kit except i just added the code to the bottom.
06/12/2008 (11:27 am)
Ok this is strange when i add this code its like all my keybind are gone. The camera wont move and character wont move. when i press f11 it goes into free look but still i cant move the camera.Basically I'm just playing with fps starter kit
This is my console log
Compiling testfps/client/scripts/default.bind.cs...
testfps/client/scripts/default.bind.cs Line: 365 - parse error
>>> Advanced script error report. Line 365.
>>> Some error context, with ## on sides of error halt:
GlobalActionMap.bindCmd(keyboard, "alt enter", "", "toggleFullScreen();");
GlobalActionMap.bindCmd(keyboard, "F1", "", "contextHelp();");
moveMap.bindCmd(keyboard, "n", "NetGraph::toggleNetGraph();", "");
// two different models... A and B.
function changePlayer(%val)
{
if (%val)
{
if ($currentModel $= "A"
{
## ##$currentModel = "B";
commandToServer('changePlayer',"B");
}
else {
$currentModel = "A";
commandToServer('changePlayer',"A");
}
}
}
// Map the "C" on the keyboard to our player
moveMap.bind( keyboard, b, changePlayer );
>>> Error report complete.
Compiling testfps/client/config.cs...
Loading compiled script testfps/client/config.cs.
Binding server port to default IP
UDP initialized on port 0
*** Initial Control Object
Activating DirectInput...
keyboard0 input device acquired.
Mapping string: Kork to index: 13
yaw: Unknown command.
pitch: Unknown command.
yaw: Unknown command.
pitch: Unknown command.
yaw: Unknown command.
pitch: Unknown command.
yaw: Unknown command.
pitch: Unknown command.
yaw: Unknown command.
pitch: Unknown command.
yaw: Unknown command.
pitch: Unknown command.
yaw: Unknown command.
pitch: Unknown command.
Loading compiled script creator/editor/cursors.cs.
Loading compiled script creator/editor/editor.bind.cs.
Loading compiled script creator/editor/ObjectBuilderGui.gui.
Loading compiled script creator/editor/EditorGui.gui.
Loading compiled script creator/editor/EditorGui.cs.
Loading compiled script creator/editor/WorldEditorSettingsDlg.gui.
Loading compiled script creator/editor/TerrainEditorVSettingsGui.gui.
keyboard0 input device unacquired.
DirectInput deactivated.My default.bind.cs code is the same as the fps. starter kit except i just added the code to the bottom.
#5
Sorry I made a mistake in the default.bind.cs which is why you've lost the key bindings and have an error.
06/12/2008 (1:57 pm)
Jermaine,Sorry I made a mistake in the default.bind.cs which is why you've lost the key bindings and have an error.
// this adds a function and keymap to send the server a message that you want to swap players between
// two different models... A and B.
function changePlayer(%val)
{
if (%val)
{
if ($currentModel $= "A")
{
$currentModel = "B";
commandToServer('changePlayer',"B");
}
else {
$currentModel = "A";
commandToServer('changePlayer',"A");
}
}
}
// Map the "C" on the keyboard to our player
moveMap.bind( keyboard, C, changePlayer );
#6
06/15/2008 (4:27 am)
Did that work Jermaine?
#7
nope it didnt work. The errors were fixed but the player never changed.
It didnt give me any errors.
o well i probably going to have to omit this from the project till i figure it out.
thanks anyway
06/15/2008 (9:52 am)
O sorry for not responding.nope it didnt work. The errors were fixed but the player never changed.
It didnt give me any errors.
o well i probably going to have to omit this from the project till i figure it out.
thanks anyway
Torque Owner Cinder Games
would require you to create the new object first, then put that object where the player is, set control to that object, delete original player object.