Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
0 registered members (), 631 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Load External Model from Menu? #368558
04/26/11 14:11
04/26/11 14:11
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline 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! laugh

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 Offline
Senior Member
xbox  Offline
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: xbox] #368561
04/26/11 14:45
04/26/11 14:45
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
Thanks. I will play with that. laugh

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 Offline
Senior Expert
Quad  Offline
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 Offline
User
Stromausfall  Offline
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 !

Code:
#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.

get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
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 Offline OP
Senior Member
RealSerious3D  Offline 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:

Code:
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] #368568
04/26/11 15:39
04/26/11 15:39
Joined: Dec 2002
Posts: 616
Austria
Stromausfall Offline
User
Stromausfall  Offline
User

Joined: Dec 2002
Posts: 616
Austria
you remove an entity with ptr_remove(theEntityToRemove)
to your second point, the problem is - WHERE is the information stored that the random model called a4.mdl is called "A-4 Skyhawk" - such information can't be saved in the .mdl file afaik!


get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
Re: Load External Model from Menu? [Re: Stromausfall] #368569
04/26/11 15:45
04/26/11 15:45
Joined: Oct 2010
Posts: 346
USA
RealSerious3D Offline OP
Senior Member
RealSerious3D  Offline OP
Senior Member

Joined: Oct 2010
Posts: 346
USA
Hello Stromausfall.

I am not loading a random model at all. I am going to offer the end-user a selection of models via a menu. The end-user will then click that menu item and that model will load. Therefore, the button (panel element) graphic will read "A-4 Skyhawk" but will load the a4.mdl model.

After a model is loaded, clicking another button will unload the previously loaded model and load the new one. Since the end-user could select any model, then the previous model needs to be purged, no matter which one was loaded. Since only one model will be loaded at a time, is there a generic way to unload any model at all (not by name)?

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 Offline
User
Stromausfall  Offline
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

get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
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 Offline OP
Senior Member
RealSerious3D  Offline 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:

Code:
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.

Page 1 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1