2 registered members (Akow, tomaslolo),
1,536
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Serious User
|
Serious User
Joined: May 2004
Posts: 1,510
Denmark
|
Ah sorry, forgot you're using C-script instead of Lite-C First of all:
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: 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:
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:
if(ghostobject == NULL)
{
ghostobject = ent_create("crate.mdl",target,NULL);
}
else
{
vec_set(ghostobject.x,target);
}
You need to change it to this:
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
|
|
|
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
binsky33333
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2008
Posts: 56
|
Here is it:
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
Serious User
|
Serious User
Joined: May 2004
Posts: 1,510
Denmark
|
You need to set isplaceobject to 1 inside the function 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: binsky33333]
#283230
08/06/09 16:49
08/06/09 16:49
|
Joined: May 2004
Posts: 1,510 Denmark
Claus_N
Serious User
|
Serious User
Joined: May 2004
Posts: 1,510
Denmark
|
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:
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
binsky33333
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2008
Posts: 56
|
Here is my code once more.
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: Claus_N]
#283238
08/06/09 17:30
08/06/09 17:30
|
Joined: Dec 2008
Posts: 56
binsky33333
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2008
Posts: 56
|
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);
}
}
|
|
|
|