Script help needed
by Infinitum3D · in Torque Game Engine · 05/29/2007 (3:31 pm) · 29 replies
I've made a file called NPC.cs
I've exec'ed it in game.cs.
In NPC.cs I'm using this script
SpawnNPC(%Name,%Script,%Portrait,%startQuestion,%location) for custom NPC spawning.
I don't understand how to 'define(?)' the parameters %Name, %location, etc.
I've tried
%Name = Joe;
%location = 200 -179 108;
but that gives me a parse error.
How do I define the parameters?
Thanks!
Tony
I've exec'ed it in game.cs.
In NPC.cs I'm using this script
SpawnNPC(%Name,%Script,%Portrait,%startQuestion,%location) for custom NPC spawning.
I don't understand how to 'define(?)' the parameters %Name, %location, etc.
I've tried
%Name = Joe;
%location = 200 -179 108;
but that gives me a parse error.
How do I define the parameters?
Thanks!
Tony
#22
I can spawn NPC's, but I don't know how to change the rotation.
This is my NPC.cs file
Can I add %rotation after %location? If so, what else do I need to use rotation as a variable?
I've tried this
and used this as spawn code
But it didn't work. I think I have to add the variable %rotation somewhere else. Maybe in RPGDialog.cs?
I see this function in RPGDialog.cs
If I add %rotation to the line %player = AIPlayer::spawn(%Name, %location); will that work?
Nope. Everything compiles, Jim is spawned, but his rotation does not change.
Maybe I have to go into AIPlayer.cs?
Nope, that doesn't work either.
Any help?
Thanks!
Tony
06/08/2007 (10:11 am)
Thanks mb! So you're saying I can comment out the function NPC::spawn and it will still work?I can spawn NPC's, but I don't know how to change the rotation.
This is my NPC.cs file
Quote:
datablock PlayerData(NPCDataBlock : PlayerBody)
{
category = "NPC";
aiPlayer = true;
};
function NPC::spawn(%Name, %Script, %Portrait, %startQuestion, %location)
{
%bot = new NPC() {
datablock = NPCDataBlock;
};
}
SpawnNPC("Jim", "Test", 0, 0, "373 375 222");
Can I add %rotation after %location? If so, what else do I need to use rotation as a variable?
I've tried this
Quote:
function NPC::spawn(%Name, %Script, %Portrait, %startQuestion, %location, %rotation)
and used this as spawn code
Quote:
SpawnNPC("Jim", "Test", 0, 0, "373 375 222", "0 0 1 90");
But it didn't work. I think I have to add the variable %rotation somewhere else. Maybe in RPGDialog.cs?
I see this function in RPGDialog.cs
Quote:
function SpawnNPC(%Name,%Script,%Portrait,%startQuestion,%location)
{
%player = AIPlayer::spawn(%Name,%location);
%player.RPGDialogScript = %Script;
%player.RPGDialogPortrait = %Portrait;
%player.RPGDialogStartQuestion = %startQuestion;
%player.RPGDialogBusy = false;
%player.RPGDialogBusyText = 'Sorry but I\'m busy talking to %1 right now.';
%player.RPGDialogTalkingTo = 0;
return %player;
}
If I add %rotation to the line %player = AIPlayer::spawn(%Name, %location); will that work?
Nope. Everything compiles, Jim is spawned, but his rotation does not change.
Maybe I have to go into AIPlayer.cs?
Quote:
function AIPlayer::spawn(%name,%spawnPoint, %rotation)
{
// Create the demo player object
%player = new AiPlayer() {
dataBlock = DemoPlayer;
path = "";
};
MissionCleanup.add(%player);
%player.setShapeName(%name);
%player.setTransform(%spawnPoint);
%player.setRotation(%rotation);
return %player;
}
Nope, that doesn't work either.
Any help?
Thanks!
Tony
#23
for instance:
%thisTransform = %obj.getTransform(); // will return a string with words (actually numbers).
So if you echo(%thisTransform); It will look like "101 201 392 0 0 0 0" ... ok not exactly like that but you get the picture..maybe more numbers, (I'm at work so I cant check for sure how many numbers it returns).
To change the numbers.. you use getWord to get what you want to change like so:
So now you have the X,Y,Z for the rotation.. You don't need all three if you just wanna change the X rotation, or the Y.. etc.. I just showed how to get all three.
Now to change the rotation you can either specify a number, or add using vectorAdd, or whatever you want.
To change the rotation using vectorAdd.
Then to set the transform of your object we'll get the transform then set the new rotation, then set the transform again.
Again you dont need all three unless you want to change x,y and z. Then finally you change the objects position.
Another way would be to just get the entire string like we did %thisTransform and just add the rotation.
I hope this wasn't too confusing. And I hope I got it all right. If not I'm sorry =)
06/08/2007 (11:23 am)
To change rotation you can use getTransform, and getWords, vectorAdd.for instance:
%thisTransform = %obj.getTransform(); // will return a string with words (actually numbers).
So if you echo(%thisTransform); It will look like "101 201 392 0 0 0 0" ... ok not exactly like that but you get the picture..maybe more numbers, (I'm at work so I cant check for sure how many numbers it returns).
Quote:
Numbers 0-2 are the position. (it starts at 0)
Numbers 3-5 are the rotation
Numbers 6 is the rotation Theta
To change the numbers.. you use getWord to get what you want to change like so:
%myRotationX = getWord(%thisTransform, 3); // this gets the 4th number in that string rotationX %myRotationY = getWord(%thisTransform, 4); %myRotationZ = getWord(%thisTransform, 5);
So now you have the X,Y,Z for the rotation.. You don't need all three if you just wanna change the X rotation, or the Y.. etc.. I just showed how to get all three.
Now to change the rotation you can either specify a number, or add using vectorAdd, or whatever you want.
To change the rotation using vectorAdd.
%newRotationX = vectorAdd(%myRotationX, "45"); // This adds "%myRotationX + 45". This also works: %myRotationX= vectorAdd(%myRotationX, "45"); // Same as above, just not using a new variable.
Then to set the transform of your object we'll get the transform then set the new rotation, then set the transform again.
%thisTransform = %obj.getTransform(); // get the transform (we already got it before so really we dont need this again) %thisTransform = setWord(%thisTransform , 3, %newRotationX); // set the rotation of X %thisTransform = setWord(%thisTransform , 4, %newRotationY); // set the rotation of y %thisTransform = setWord(%thisTransform , 5, %newRotationZ); // set the rotation of z
Again you dont need all three unless you want to change x,y and z. Then finally you change the objects position.
%obj.setTransform(%thisTransform);
Another way would be to just get the entire string like we did %thisTransform and just add the rotation.
%newRotation = vectorAdd(%thisTransform , "0 0 0 45 0 0 0"); %obj.setTransform(%newRotation); // This moves your object or in this case changes the rotation (in theory) :)
I hope this wasn't too confusing. And I hope I got it all right. If not I'm sorry =)
#24
Then call the function and include the rotation values:
06/08/2007 (12:25 pm)
Try this:function AIPlayer::spawn(%name,%spawnPoint, %rotationX, %rotationY, %rotationZ)
{
// Create the demo player object
%player = new AiPlayer() {
dataBlock = DemoPlayer;
path = "";
};
MissionCleanup.add(%player);
%player.setShapeName(%name);
%player.setTransform(%spawnPoint);
// get transform of AIPlayer you spawned
%thisTransform = %player.getTransform();
// set the rotation values
%thisTransform = setWord(%thisTransform , 3, %rotationX); // set the rotation of X
%thisTransform = setWord(%thisTransform , 4, %rotationY); // set the rotation of Y
%thisTransform = setWord(%thisTransform , 5, %rotationZ); // set the rotation of Z
// Change AIPlayers position
%player.setTransform(%thisTransform);
return %player;
}function SpawnNPC(%Name,%Script,%Portrait,%startQuestion,%location, %rotationX, %rotationY, %rotationZ)
{
%player = AIPlayer::spawn(%Name,%location, %rotationX, %rotationY, %rotationZ);
%player.RPGDialogScript = %Script;
%player.RPGDialogPortrait = %Portrait;
%player.RPGDialogStartQuestion = %startQuestion;
%player.RPGDialogBusy = false;
%player.RPGDialogBusyText = 'Sorry but I\'m busy talking to %1 right now.';
%player.RPGDialogTalkingTo = 0;
return %player;
}Then call the function and include the rotation values:
#25
My guess is I'm calling the function in RPGDialog.cs, since it's actually written SpawnNPC, while the AIPlayer function is written AIPlayer::spawn. Maybe RPGDialog.cs is then using the information from AIPlayer.cs?
Oh and for rotation, it's simple. Just add the rotation code to the location, ie, "373 375 222 0 0 1 180". So easy, and yet it took me so long to figure out.
I also removed the extraneous function, so my final NPC.cs file looks like this;
Hardcoding every NPC is going to take forever! I have to place a figure, get its coords and rotation, and then type it into my NPC.cs. That's a lot to do if I'm going to have 100 NPC's or more. Time to get started :)
thanks!
Tony
06/08/2007 (2:51 pm)
@mb - So my NPC.cs is just calling the spawn function from RPGDialog.cs??? or is it calling function AIPlayer::spawn? It looks like both files have a spawn AI function. My guess is I'm calling the function in RPGDialog.cs, since it's actually written SpawnNPC, while the AIPlayer function is written AIPlayer::spawn. Maybe RPGDialog.cs is then using the information from AIPlayer.cs?
Oh and for rotation, it's simple. Just add the rotation code to the location, ie, "373 375 222 0 0 1 180". So easy, and yet it took me so long to figure out.
I also removed the extraneous function, so my final NPC.cs file looks like this;
Quote:
datablock PlayerData(NPCDataBlock : PlayerBody)
{
category = "NPC";
aiPlayer = true;
};
SpawnNPC("Guard Frank", G1d, "tiger.png", 1, "182 -688 108.1 0 0 1 160");
//-- location is X coord., Y, Z, X-rotation boolean (0=false, 1=true), Y, Z, degrees rotation
SpawnNPC("Merchant Jim", Test, 0, 2, "174 -698.5 108.2");
SpawnNPC("Merchant Joe", G1d, 0, 0, "159 -698.5 108.2");
SpawnNPC("Big Willie", Test, 0, 2, "184 -695 108.2 0 0 1 148");
SpawnNPC("Little Moe", G1d, 0, 0, "169 -694.5 108.2 0 0 1 60");
SpawnNPC("Uncle Slim", Test, 0, 2, "194 -697.5 108.20 0 1 30");
SpawnNPC("Ugly Boy Nelson", G1d, 0, 0, "190 -690 108.2 0 0 1 135");
Hardcoding every NPC is going to take forever! I have to place a figure, get its coords and rotation, and then type it into my NPC.cs. That's a lot to do if I'm going to have 100 NPC's or more. Time to get started :)
thanks!
Tony
#26
06/09/2007 (12:51 pm)
Your NPC.cs is calling the function SpawnNPC in "server\scripts\rpgdialog.cs"which in turn calls AIPlayer::spawn.
#28
09/21/2008 (9:46 am)
I like the RPG dialog resource a lot and have it working in the game engine, but how can I use this like you would for the AI Guard and having an area in the shapes folder to place them into the level. I am not a programmer so the easier the better for me. Any help would be appreciated on this problem.
#29
Good question. I don't use AIguard (yet), but to put somethinmg in the Shapes folder, you just need to write a datablock for it.
I'll try to post something better when I have a better 'net connection. My cellphone doesn't like long osts of code :)
Tony
09/22/2008 (5:39 am)
Kevin,Good question. I don't use AIguard (yet), but to put somethinmg in the Shapes folder, you just need to write a datablock for it.
I'll try to post something better when I have a better 'net connection. My cellphone doesn't like long osts of code :)
Tony
Torque 3D Owner mb
So you don't need that function NPC::spawn that you made.
The %Script parameter actually refers to a script file not the datablock. From the readme:
Open test.dla to see an example of that.