|
0 registered members (),
631
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Load External Model from Menu?
[Re: Stromausfall]
#368576
04/26/11 16:17
04/26/11 16:17
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
There's no need for a wait between loading the level and creating the model. If you only change the model at the same position, ent_morph should do the job. In difference to ent_create, with ent_morph you don't have to remove the other model, because it is simply replaced. You load the level and create the model once, and then change the model only with ent_morph. This is from my standard script for controling the look of a model (almost reduced to the things that you requested):
#include <acknex.h>
#include <default.c>
function show_model()
{
while(1)
{
if(key_1){ent_morph(me, "model1.mdl");}
if(key_2){ent_morph(me, "model2.mdl");}
wait(1);
}
}
function main()
{
level_load("small.hmp");
ent_create("model1.mdl", vector(100, 0, 0), show_model);
}
Last edited by Pappenheimer; 04/26/11 16:24.
|
|
|
Re: Load External Model from Menu?
[Re: Pappenheimer]
#368581
04/26/11 16:45
04/26/11 16:45
|
Joined: Oct 2010
Posts: 346 USA
RealSerious3D
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2010
Posts: 346
USA
|
Okay. I am easily confused.  I would appreciate a little more help. Here is the code I have thus far:
BMAP* model_1 = "model1.jpg";
BMAP* model_2 = "model2.jpg";
//Choose Model Buttons
void choose_model_button(var num) {
if(player){
switch(num){
case 1:
level_load(NULL);
wait(1);
ent_create("model1.mdl",vector(100,0,0),NULL); //load model 1
break;
case 2:
level_load(NULL);
wait(1);
ent_morph(me,"model2.mdl"); //load model 2
break;
}
}
}
//Panels
PANEL* buttons = {
button(100,10,model_1,model_1,model_1,choose_model_button,NULL,NULL);
button(220,10,model_2,model_2,model_2,choose_model_button,NULL,NULL);
layer = 1;
Flags = SHOW;
}
How can I use the above code to morph from one model to the next? I am using #include to include this code in the main script file. In and of itself, it does not work at all. However, in conjunction with another included script, it will load the models, though it does not work properly ... yet. I just realize that I don't know a lot about any of this and am starting to flounder here. Here is what I am looking to do: 1 - Display a menu (i.e. a panel or buttons) 2 - The end-user clicks a button to make his choice 3 - The selected model appears 4 - A click on another menu option removes the old model and brings in the new I believe that if I can get this functioning, then I can expand it to do what I need. And this is all helping me to learn scripting, too. I just don't always know WHERE to put the code. The manual seems vague on these matters. Ugh.
|
|
|
Re: Load External Model from Menu?
[Re: RealSerious3D]
#368590
04/26/11 17:28
04/26/11 17:28
|
Joined: Dec 2002
Posts: 616 Austria
Stromausfall
User
|
User
Joined: Dec 2002
Posts: 616
Austria
|
hmmm try this - i haven't tested it yet !
BMAP* model_1 = "model1.jpg";
BMAP* model_2 = "model2.jpg";
ENTITY *displayedEntity = NULL;
void displayModel(char *nameOfModel)
{
if(displayedEntity == NULL)
{
//if no entity was yet created ->
//create an entity
displayedEntity =
ent_create(nameOfModel,vector(100,0,0),NULL);
}
else
{
//an entity was already created !
//morph it to the new model!
ent_morph(displayedEntity,nameOfModel);
}
}
//Choose Model Buttons
void choose_model_button(var num) {
//player variable not necessary - i guess
//if(player){
switch(num){
case 1:
displayModel("model1.mdl");
break;
case 2:
displayModel("model2.mdl");
break;
}
//}
}
//Panels
PANEL* buttons = {
button(100,10,model_1,model_1,model_1,choose_model_button,NULL,NULL);
button(220,10,model_2,model_2,model_2,choose_model_button,NULL,NULL);
layer = 1;
Flags = SHOW;
}
Last edited by Stromausfall; 04/26/11 17:33.
|
|
|
Re: Load External Model from Menu?
[Re: RealSerious3D]
#368591
04/26/11 17:38
04/26/11 17:38
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
If you use ent_morph in the given case, the level should be loaded only once, means, only when the user hits one of the buttons for the first time. So, you have to know whether the level is already loaded or not. If the level is not already loaded, it has to be loaded and the chosen model has to be created. If the level is loaded, this step of loading it has to be skipped and the models only need to be morphed.
For this you add a variable before or in the function: var level_loaded;
Then you check whether the level is loaded. If level_load didn't get a 1, it isn't loaded if(level_loaded != 1) { level_load(NULL);//load the level ... //here create the model level_loaded = 1;//change the variable to 1, to know that the level is already loaded, when a button is clicked again later }else//when the level is already loaded, the morphing in the next brackets are going to happen { ... //here morph the model }
In this empty places "..." you fill in from your given code:
1. for creating the model: switch(num){ case 1: ent_create("model1.mdl",vector(100,0,0),NULL); //load model 1 break; case 2: ent_create("model1.mdl",vector(100,0,0),NULL); //load model 2 break; }
2. For morphing the model:
switch(num){ case 1: ent_morph(me, "model1.mdl"); //morph model 1 break; case 2: ent_morph(me, "model1.mdl"); //morph model 2 break; }
This is the principle. Didn't test it. I never used the switch statement before.
|
|
|
Re: Load External Model from Menu?
[Re: Pappenheimer]
#368594
04/26/11 17:51
04/26/11 17:51
|
Joined: Oct 2010
Posts: 346 USA
RealSerious3D
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2010
Posts: 346
USA
|
Okay. I will test these. In the mean time, some information that may help you all to help me. I have a main script that looks like this:
//Includes
#include <acknex.h>
#include <litec.h>
#include <default.c>
#include "pc_movement.c"
//#include "rotate_and_distance.c"
#include "panel_test.c"
//#include "follow_path_smooth.c"
#include "model_load_test.c"
//Defined Paths
#define PRAGMA_PATH "Sounds";
#define PRAGMA_PATH "Models";
#define PRAGMA_PATH "Images";
//Main Function for the Game (currently level load only)
function main()
{
level_load("test_level.wmb");
sky_color.red = 0;
sky_color.green = 0;
sky_color.blue = 0;
}
As you can see, it "includes" a script called "model_load_test.c". This script also loads a test level, the level that I want all the models to load into. It consists of a background panel (a panel with it's layer set to -1) and this panel information comes from another included script called "panel_test.c". I am testing using #include because I want to make reusable code ... code that I can plug into other things I create and modify if need be. Since the main script loads a level, I don't want the model_load_test.c script to have to load levels at all if I can help it. I just want to load a model into it and then unload a model for the next one or morph it into the next end-user selected model. Does this help?
|
|
|
Re: Load External Model from Menu?
[Re: Stromausfall]
#368597
04/26/11 18:08
04/26/11 18:08
|
Joined: Oct 2010
Posts: 346 USA
RealSerious3D
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2010
Posts: 346
USA
|
Thank you. Now I am running into another problem due to the way I am "including" scripts. The code I am using for swapping out models comes partially from another script I am using to rotate a model via the mouse and to snap it to face certain ways via clicking on buttons. This script is called "rotate_and_distance.c". If I disable the include (//#include "rotate_and_distance.c";) then the code Stronmausfall provided does not work. However, if I include it, then the code works fine. Therefore, I am guessing there is something in the rotate_and_distance.c script that I need to include in my model_load_test.c file. I am guessing that it has to do with the ACTION at the end of the script (yes, I am dumb when it comes to coding) which is attached to a model that is already loaded into the level at the start (a model that has nothing to do with the model_load_test.c script. If I remove this model, then the code to load models does not work. So, again, getting this to work has to do with something in that ACTION. Here's my complete code for the rotate_and_distance.c script:
//Rotate View Around Object Test
//View Object from Different Distances
//Images
BMAP* button_top_on = "button_top_on.tga";
//BMAP* button_top_click = "button_top_click.tga";
BMAP* button_top_off = "button_top_off.tga";
BMAP* button_bottom_on = "button_bottom_on.tga";
//BMAP* button_bottom_click = "button_bottom_click.tga";
BMAP* button_bottom_off = "button_bottom_off.tga";
BMAP* button_front_on = "button_front_on.tga";
//BMAP* button_front_click = "button_front_click.tga";
BMAP* button_front_off = "button_front_off.tga";
BMAP* button_back_on = "button_back_on.tga";
//BMAP* button_back_click = "button_back_click.tga";
BMAP* button_back_off = "button_back_off.tga";
BMAP* button_side_on = "button_side_on.tga";
//BMAP* button_side_click = "button_side_click.tga";
BMAP* button_side_off = "button_side_off.tga";
BMAP* button_distance0_on = "button_distance0_on.tga";
//BMAP* button_distance0_click = "button_distance0_click.tga";
BMAP* button_distance0_off = "button_distance0_off.tga";
BMAP* button_distance1_on = "button_distance1_on.tga";
//BMAP* button_distance1_click = "button_distance1_click.tga";
BMAP* button_distance1_off = "button_distance1_off.tga";
BMAP* button_distance2_on = "button_distance2_on.tga";
//BMAP* button_distance2_click = "button_distance2_click.tga";
BMAP* button_distance2_off = "button_distance2_off.tga";
BMAP* button_distance3_on = "button_distance3_on.tga";
//BMAP* button_distance3_click = "button_distance3_click.tga";
BMAP* button_distance3_off = "button_distance3_off.tga";
//View Button
void view_button(var num) {
if(player){
switch(num){
case 1:
vec_set(player.pan,vector(0,90,0)); //top view
break;
case 2:
vec_set(player.pan,vector(0,-90,0)); //bottom view
break;
case 3:
vec_set(player.pan,vector(180,0,0)); //front view
break;
case 4:
vec_set(player.pan,vector(0,0,0)); //back view
break;
case 5:
vec_set(player.pan,vector(90,0,0)); //side view
break;
case 6:
player.x = 50; //d1 view
break;
case 7:
player.x = 500; //d1 view
break;
case 8:
player.x = 1000; //d1 view
break;
case 9:
player.x = 2000; //d1 view
break;
}
}
}
//Panel
PANEL* buttons = {
button(10,10,button_top_off,button_top_off,button_top_on,view_button,NULL,NULL);
button(10,25,button_bottom_off,button_bottom_off,button_bottom_on,view_button,NULL,NULL);
button(10,40,button_front_off,button_front_off,button_front_on,view_button,NULL,NULL);
button(10,55,button_back_off,button_back_off,button_back_on,view_button,NULL,NULL);
button(10,70,button_side_off,button_side_off,button_side_on,view_button,NULL,NULL);
button(10,85,button_distance0_off,button_distance0_off,button_distance0_on,view_button,NULL,NULL);
button(10,100,button_distance1_off,button_distance1_off,button_distance1_on,view_button,NULL,NULL);
button(10,115,button_distance2_off,button_distance2_off,button_distance2_on,view_button,NULL,NULL);
button(10,130,button_distance3_off,button_distance3_off,button_distance3_on,view_button,NULL,NULL);
layer = 1;
Flags = SHOW;
}
//Rotate Action
action rotate_and_distance()
{
player = me;
mouse_mode = 1;
while(1)
{
if (mouse_left){
my.pan += mouse_force.x; // mouse movement changes PAN
//my.pan = clamp(my.pan,-189,189);
my.tilt += mouse_force.y; // mouse movement changes TILT
//my.tilt = clamp(my.tilt,-89,89);
}
vec_set(mouse_pos,mouse_cursor);
wait(1);
}
}
Now, I know I don't want to use an action ... or I am guessing I don't because a blank level (a level with no pre-loaded model in it) will not have an action associated with it. So can I make this a FUNCTION instead? Sorry if this is a dumb question.
|
|
|
|