Slightly complicated ent_create

Posted By: SamstaUK

Slightly complicated ent_create - 11/25/08 12:20

I want to use a simple script which creates an object behind the player when they press a key. For example you press enter then a cube appears behind you, I'm hoping this isn't too complicated.
Posted By: MattyTheG

Re: Slightly complicated ent_create - 11/25/08 13:52

This should be a pretty simple use of the ent_create() function.
In your player's action you should have a while loop that waits for the player to press enter, when it does call the ent_create. I will give you a quick example of how I would do it, though I'm pretty new myself.

Code:
action cube_fall()
{
   //Put random physics code or whatever you want the cube to do in here, this will be the cube's behavior.
}

action control_player() // Behavior assigned to the player
{
   while(1)
   {
     if (key_enter == 1)
     {
       ent_create("cube.mdl", vector(my.x - 50, my.y, my.z), cube_fall); // creates the cube 50 quants behind the player and assigns its behavior.
       wait(200); // keeps the player from making a bunch of them at once.
     }
     wait(1);
}


Hope you could understand that, I tried to comment it well enough. If I was you I would have a variable that keeps track of the number of cubes so that the player doesn't make a bunch and slow down/crash the game.
Posted By: Quad

Re: Slightly complicated ent_create - 11/25/08 14:14

while(key_enter ==1) wait(1);

instead of

wait(200); // keeps the player from making a bunch of them at once.

will create only one entity everytime user presses enter.
Posted By: MattyTheG

Re: Slightly complicated ent_create - 11/25/08 14:33

Awesome, I was looking for some way to do that but the only way I could figure out was to just put a long delay in there.
Posted By: SamstaUK

Re: Slightly complicated ent_create - 11/25/08 16:44

Thanks for the code! But now I'm getting an "Empty Pointer in Main" error which points to the ent_create() function. How can I stop it happening?
Posted By: testDummy

Re: Slightly complicated ent_create - 11/25/08 17:16

Code:
// on error = my.x - 50 != behind pos
// example only: This code SHOULD NOT work.
var behind_v[3] = {0,0,0};   // reusable

action cube_fall() {
   //Put random physics code or whatever you want the cube to do in here, this will be the cube's behavior.
}

action player_a() {// Behavior assigned to the player
	var kin_create; kin_create = 0;
	while(1) {
		if (key_enter == 1 && kin_create == 0) { //& not pressed last frame
			vec_for_angle(behind_v, vector(ang(my.pan - 180), 0, 0));
			vec_scale(behind_v, 50);
			ent_create("cube.mdl", behind_v, cube_fall); // creates the cube 50 quants behind the player and assigns its behavior.
		}
	}
	kin_create = key_enter;	// key_enter pressed last frame?
	wait(1);
}

Posted By: SamstaUK

Re: Slightly complicated ent_create - 11/25/08 17:30

var behind_v[3] = {0,0,0};

Causes parameter unknown errors.
Posted By: MattyTheG

Re: Slightly complicated ent_create - 11/25/08 23:39

Sorry about the pointer error, I unknowingly assumed that the action was already assigned to the entity in WED.

To fix that var behind_v[3] = {0,0,0} error you should be able to use: var behind_v = vector(0, 0, 0); with the same results, I think.
© 2024 lite-C Forums