Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 533 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: C-trace, click to place an object [Re: binsky33333] #283126
08/05/09 20:34
08/05/09 20:34
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline
Serious User
Claus_N  Offline
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Ah sorry, forgot you're using C-script instead of Lite-C smile

First of all:
Code:
entity ghostobject
{
	flags = TRANSLUCENT;
	alpha = 30;
}


This creates a view entity, but you want a "normal" entity , not a view entity, so replace that code with this:
Code:
entity* ghostobject;


Change the while condition ( "while(isplaceobject == NULL)" ) to "while(isplaceobject != 0)", as it's a variable, not a pointer, and set this variable to something else than 0 before entering the while loop - this way you can always cancel the loop by setting the global variable to 0 anywhere in your code.

In this code:
Code:
if(mouse_left)
		{
			ent_create("crate.mdl",target,null);
			if(ghostobject == NULL)
			{
				ent_remove(ghostobject);
				isplaceobject = 0;
			}
			
		}


You need to change the nested if-condition to "ghostobject != NULL".

And now a very important part:
Code:
if(ghostobject == NULL)
		{
			ghostobject = ent_create("crate.mdl",target,NULL);
		}
		else
		{
			vec_set(ghostobject.x,target);
		}


You need to change it to this:
Code:
if(ghostobject == NULL)
		{
			ghostobject = ent_create("crate.mdl",target,NULL);
			ghostobject.transparent = on;
			ghostobject.passable = on;
			ghostobject.alpha = 30;
		}
		else
		{
			vec_set(ghostobject.x,target);
		}


You really need to make it passable in order to let the trace ignore the ghostobject.

Tell me if it's still not working smile

Re: C-trace, click to place an object [Re: Claus_N] #283151
08/06/09 04:15
08/06/09 04:15
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Wooo its works... though there is 1 tiny problem, you can only do it once. It only spawns 1 ghost and can only spawn 1 crate, and then you can never spawn anything else...

Re: C-trace, click to place an object [Re: binsky33333] #283181
08/06/09 09:24
08/06/09 09:24
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline
Serious User
Claus_N  Offline
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Maybe you just forgot to set 'isplaceobject' to something else than 0 when you want to create a new object? Otherwise please post your full code again smile

Re: C-trace, click to place an object [Re: Claus_N] #283223
08/06/09 16:15
08/06/09 16:15
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Here is it:
Code:
entity* ghostobject;
var isplaceobject = 1;
function spawn()
{
	while(isplaceobject != 0)
	{
	temp.x = mouse_pos.x;
	temp.y = mouse_pos.y;
	temp.z = 0;
	
	vec_set(target,temp);
	target.z = 10000;
	
	vec_for_screen(temp,view_build);
	vec_for_screen(target,view_build);
	
	if(c_trace(temp,target,IGNORE_ME | IGNORE_PASSABLE) > 0)
	{
		if(mouse_left)
		{
			ent_create("crate.mdl",target,null);
			if(ghostobject != NULL)
			{
				ent_remove(ghostobject);
				isplaceobject = 0;
			}	
		}
		if(ghostobject == NULL)
		{
			ghostobject = ent_create("crate.mdl",target,NULL);
			ghostobject.transparent = on;
			ghostobject.passable = on;
			ghostobject.alpha = 30;
		}
		else
		{
			vec_set(ghostobject.x,target);
		}
		wait(1);
	}	

	}
	

}



That only works once... then the ghost disappears and you cant spawn another crate.

Re: C-trace, click to place an object [Re: binsky33333] #283224
08/06/09 16:28
08/06/09 16:28
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline
Serious User
Claus_N  Offline
Serious User

Joined: May 2004
Posts: 1,510
Denmark
You need to set isplaceobject to 1 inside the function smile

Otherwise it will remain 0, and the code in the loop will never be reached anymore, as the while-condition will then be false.

Re: C-trace, click to place an object [Re: Claus_N] #283225
08/06/09 16:32
08/06/09 16:32
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Ok so i actually put. var isplaceobject = 1; inside the actual function. Ok now the crate will stay a ghost forever, and the ghost never disappears. But now instead of placing just 1 crate when i click it places a huge line of like 50 crates coming up all the way towards the camera, not just 1 like its supposed to be doing.

Re: C-trace, click to place an object [Re: binsky33333] #283230
08/06/09 16:49
08/06/09 16:49
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline
Serious User
Claus_N  Offline
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Code:
var isplaceobject;
function spawn()
{
	isplaceobject = 1;

	while(...)
	{
		... // other code



You also need to move the "wait(1);" outside the if-branching, as it will otherwise produce a crash if the trace hits nothing or hits an object from the inside.

I don't know why you're getting more than 1 cubes, maybe you're calling the function more than once at the same time?

Also add a break; or return; here:
Code:
if(ghostobject != NULL)
			{
				ent_remove(ghostobject);
				isplaceobject = 0;
				return;
			}



Re: C-trace, click to place an object [Re: Claus_N] #283236
08/06/09 17:23
08/06/09 17:23
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Here is my code once more.
Code:
entity* ghostobject;
var isplaceobject;
function spawn()
{
   isplaceobject = 1;
	while(isplaceobject != 0)
	{
	temp.x = mouse_pos.x;
	temp.y = mouse_pos.y;
	temp.z = 0;
	
	vec_set(target,temp);
	target.z = 10000;
	
	vec_for_screen(temp,view_build);
	vec_for_screen(target,view_build);
	
	if(c_trace(temp,target,IGNORE_ME | IGNORE_PASSABLE) > 0)
	{
		if(mouse_left)
		{
			ent_create("crate.mdl",target,null);
			if(ghostobject != NULL)
			{
				ent_remove(ghostobject);
				isplaceobject = 0;
				return;
			}	
		}
		if(ghostobject == NULL)
		{
			ghostobject = ent_create("crate.mdl",target,NULL);
			ghostobject.transparent = on;
			ghostobject.passable = on;
			ghostobject.alpha = 30;
		}
		else
		{
			vec_set(ghostobject.x,target);
		}
		
	}	
		wait(1);
	}
	

}



The problem is coming from when i hold down the left mouse buttons they just keep spawning in a huge line all the way up to the camera, then the engine crashes due to too many entities. Is there a way where even if i hold the left mouse button down it will only run that if statement once? Also im running the function by putting spawn(); in another function.

Last edited by binsky33333; 08/06/09 17:26.
Re: C-trace, click to place an object [Re: binsky33333] #283237
08/06/09 17:28
08/06/09 17:28
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline
Serious User
Claus_N  Offline
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Can you show me the function which calls spawn? smile

Re: C-trace, click to place an object [Re: Claus_N] #283238
08/06/09 17:30
08/06/09 17:30
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Code:
function build_mode()
{
	mouse();
	camera.visible = off;
	view_build.size_x = screen_size.x;
	view_build.size_y = screen_size.y;
	view_build.visible = on;
	player = me;
	view_build.x = -144;
	view_build.y = -144;
	view_build.z = 50;
	view_build.tilt = -30;

	while(1)
	{
		if (mouse_pos.x > screen_size.x - 40 || key_cur == 1 ) 
		{ 
			view_build.y -= 20 * time_step; 
		}
		if (mouse_pos.x < screen_size.x - 740 || key_cul == 1) 
		{ 
			view_build.y += 20 * time_step; 
		}
		if(mouse_pos.y > screen_size.y - 40 || key_cud == 1)
		{
			view_build.x -= 20 * time_step;
		}
		if(mouse_pos.y < screen_size.y - 540 || key_cuu == 1)
		{
			view_build.x += 20 * time_step;
		}
		
	   
		spawn();
		wait(1);
	}
	
}



Page 2 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