|
0 registered members (),
631
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Load External Model from Menu?
#368558
04/26/11 14:11
04/26/11 14:11
|
Joined: Oct 2010
Posts: 346 USA
RealSerious3D
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2010
Posts: 346
USA
|
I am new to programming/scripting, but learning and having fun. Thanks for all the help from various members here. I am wondering if it is possible to load a MDL from an external folder via a menu within a running game? For example, what if I have a folder with 10 MDL models in it and I want to give the end-user the ability to click a panel element, see a list of names, click a name and load the appropriate model. Currently I have code to allow the end-user to rotate and view a model from any angle, including buttons to quickly go to various views. Now I want to give them the ability to load any MDL in a particular folder and do the same. Any help would be appreciated. Thanks! 
|
|
|
Re: Load External Model from Menu?
[Re: RealSerious3D]
#368560
04/26/11 14:37
04/26/11 14:37
|
Joined: Nov 2006
Posts: 497 Ohio
xbox
Senior Member
|
Senior Member
Joined: Nov 2006
Posts: 497
Ohio
|
I am still using C-Script and all you have to do is "ent_create" when they click on the specific button. Ex: ent_create("model1.mdl", vector(x,y,z), ent_action); However, I don't use Lite-C but I am sure its quite similar.
if you need a specific folder, i think its something like: ent_create("\models\model1.mdl"...); where the "models" folder is located in the same directory as the main.exe
Last edited by xbox; 04/26/11 14:39. Reason: forgot additional path
|
|
|
Re: Load External Model from Menu?
[Re: RealSerious3D]
#368562
04/26/11 15:02
04/26/11 15:02
|
Joined: Oct 2007
Posts: 5,209 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
if name of models are unknown/variable at the time of coding, you -obviously- can't hardcode filenames. You can either use winapi functions get list of filenames in a folder, or if your app runs in windowed mode you can use native windows file open dialogs.
3333333333
|
|
|
Re: Load External Model from Menu?
[Re: Quad]
#368563
04/26/11 15:07
04/26/11 15:07
|
Joined: Dec 2002
Posts: 616 Austria
Stromausfall
User
|
User
Joined: Dec 2002
Posts: 616
Austria
|
it should definitely be possible, I've create a small example that works pretty good, it uses absolute paths, but you should use relative paths ! I only used absolute paths because this example displays the files in the acknex/samples folder, thus you need to modify the two char* values : path and pathPlusPattern to match with the samples folder of your gamestudio installation !
#include <acknex.h>
TEXT* FilesInDir =
{
layer = 1;
pos_x = 320;
pos_y = 300;
strings = 5;
flags = CENTER_X | TRANSLUCENT | SHOW;
}
int main()
{
//load an empty level
level_load(NULL);
//limit fps
fps_max = 60;
//could also be a relative path, not an absolute one (absolute is bad afaik!)
char *path = "K:\\samples";
char *pathPlusPattern = "K:\\samples\\*.mdl";
//read 5 files at most (because the TEXT has 5 strings)
int numberOfMatchingFiles =
txt_for_dir(FilesInDir, pathPlusPattern);
printf("%i .mdl files were found!", numberOfMatchingFiles);
//add the folder
add_folder(path);
//wait a second
wait(-1);
printf("enter number of model to load (0 - %i)", (numberOfMatchingFiles - 1));
int inputValue = -1;
int i;
int modelLoaded = 0;
while(modelLoaded == 0)
{
//get int value from the entered char
inputValue =
inchar(NULL) - (int)'0';
for(i = 0; i < numberOfMatchingFiles; i++)
{
if(inputValue == i)
{
//create the entity
ent_create((FilesInDir.pstring)[i], vector(200, 0, 0), NULL);
//remove TEXT
ptr_remove(FilesInDir);
//we don't need the while loop anymore
modelLoaded = 1;
break;
}
}
wait(1);
}
}
Last edited by Stromausfall; 04/26/11 15:10.
|
|
|
Re: Load External Model from Menu?
[Re: Stromausfall]
#368566
04/26/11 15:35
04/26/11 15:35
|
Joined: Oct 2010
Posts: 346 USA
RealSerious3D
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2010
Posts: 346
USA
|
Thanks, Stromausfall. I'll play with that code. Here is what I set up for testing:
BMAP* model_1 = "model1.jpg";
BMAP* model_2 = "model2.jpg";
void choose_model_button(var num){
if(player){
switch(num){
case 1:
ent_create("model1.mdl",vector(0,0,0),NULL);
break:
case 2:
ent_create("model2.mdl",vector(0,0,0),NULL);
break:
}
}
}
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;
]
This works. However, how can I get it to unload the previously loaded model? In other words, if I click the model_1 button and load model1.mdl, then when I click the model_2 button, how can I get model1.mdl to go away? Thanks! Oh, by the way, I don't want to display the model names from out of a directory to the end user. I would prefer to give them easily readable names. For example, an aircraft model might be called a4.mdl, but the end-user should see A-4 Skyhawk. The end-user does not need to know what an "mdl" is, for example. And this is why I was using buttons to load each selected model.
|
|
|
Re: Load External Model from Menu?
[Re: RealSerious3D]
#368570
04/26/11 15:48
04/26/11 15:48
|
Joined: Dec 2002
Posts: 616 Austria
Stromausfall
User
|
User
Joined: Dec 2002
Posts: 616
Austria
|
you could of course always store the currently loaded entity in a global variable and thus you would always know which entity is currently loaded !
But the easier way, if you only place the entity in the 'level' would be to simply call level_load(NULL), thus loading a new empty level !
Last edited by Stromausfall; 04/26/11 15:50. Reason: typo
|
|
|
Re: Load External Model from Menu?
[Re: Stromausfall]
#368571
04/26/11 15:57
04/26/11 15:57
|
Joined: Oct 2010
Posts: 346 USA
RealSerious3D
OP
Senior Member
|
OP
Senior Member
Joined: Oct 2010
Posts: 346
USA
|
Again, thanks for all your help. Given the code I am using above (with buttons, etc), how do I implement the level_load(NULL)? For example, if my code looks like this:
void choose_model_button(var num) {
if(player){
switch(num){
case 1:
level_load(NULL);
ent_create("model1.mdl",vector(100,0,0),NULL); //load model 1
break;
case 2:
level_load(NULL);
ent_create("model2.mdl",vector(100,0,0),NULL); //load model 2
break;
}
}
}
Then it loads an empty level. However, it does not load the model.
|
|
|
|