Hiya guys!
I got a bit of a problem here. My create-at-mousepoint doesn't work, and I can't seem to find the cause of the problem!
This is what I want to happen:
1. player clicks 'build unit'.
2. panel shows up saying "right click on the GROUND to place entity".
3. When player clicks on ground, entity will be created at mousepoint.
That's basically it. But let's dwelve deeper in number 2. "click on the GROUND". ..So I do a c_trace here and check the tex_name if it is equal to my ground texture name. (here comes the problem!) However, even if I click at some points where there is no "ground" (just a big invisible collision block), it still creates an entity there(on top of the collision block)! I just want to create an entity IF the mousepoint is on the ground. Hope I made sense here.
Here's the c_trace code.
Code:
function createAtMousePoint()
{
while(metro_created == 0)
{
// Trace starting point
temp.x = mouse_pos.x;
temp.y = mouse_pos.y;
temp.z = 0;
// Trace target
target.x = mouse_pos.x;
target.y = mouse_pos.y;
target.z = mouse_range;
// Convert 2D -> 3D
vec_for_screen(temp,camera);
vec_for_screen(target,camera);
// Do a trace to find the point where the mouse-ray hits non-passable level geometry
c_trace(camera.x,target,ignore_models|ignore_me|scan_texture);
// Now the predefined target vector holds the coordinates of the hitpoint
if(str_cmpi("Concrete01",tex_name))//CHECKS IF MOUSE IS ON THE GROUND
{
main_hint.visible = off;
close_hint();
ent_create("metroaide_final.mdl",target,metroaide);
metro_created = 1;
metro_wait = 0;
}
wait(1);
}
}
Here's the button function code:
Code:
panel metro_pan
{
bmap = metro_bmp;
pos_x = 8; pos_y = 416; layer = 15;
button = 0,0, metro_bmp, metro_bmp, metro_bmp2, create_metroaide,touch_null,touch_metro;
}
function create_metroaide(button_number)
{
if(tutorial_check == 0)
{
if(money >= 350)&&(metro_wait == 0) //if player still has money
{
metro_wait = 1;
snd_play(switch2_snd,20,0);
money -= 350; //Used
money_used += 350; //same as above but multiplied by 100
main_hint.string = metro_create;
open_hint();
on_mouse_right = createAtMousePoint;
metro_created = 0; //reset back to 0.
}
if(money < 350) //show NO MORE MONEY panel
{
snd_play(error_snd,100,0);
hint_nomoney.visible = on; hint_nomoney.alpha = 100; wait(-2);
while(hint_nomoney.alpha > 0){hint_nomoney.alpha -= 5 * time; wait(1);}
hint_nomoney.visible = off;
}
}
}
I'm pretty sure the problem lies in the code. I tried a couple of things in WED but it still didn't work. Hope someone can answer this. my DEADLINE is nearing....
Thank you in advance.