First of all, event triggers such as EVENT_CLICK are used for clicking on entities and stuff, not for mouseclicking in general. So upon calling the function creat(), the engine will never read the part within the if statement.
Second, you want to create an entity when you click the mouse, but your while statement will never be executed when you don't click the mouse first, and thus never wait for your input.
Third, when you create a view model, you should use ent_createlayer (I assume you want a view entity instead of a world entity as you define an entity as ENTITY*). Plus you place your model directly on the camera.z axis, you wont see it as your camera is now in the model.
So, time for the solution:
Code:
function main()
{
level_load("ent_.wmb");
wait(2);
creat();
mouse_mode = 2;
while(1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
wait (1);
}
}
function creat()
{
while (1) //we will always check for user input, every frame
{
if (mouse_left) //left mouse has clicked!
{
you = ent_create("earth.mdl", 0, 10); //create earth.mdl view entity, no flags, on layer 10
you.x = mouse_pos.x;
you.y = mouse_pos.y;
you.z = 40; //40 quants in front of the camera
}
wait(1);
}
}
If you wanted a world entity instead, you need some more code for letting it follow the mouse. I'll help you on it if this is the case.
Ciao