Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Quad, VoroneTZ, 1 invisible), 852 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Slightly complicated ent_create #238178
11/25/08 12:20
11/25/08 12:20
Joined: Oct 2008
Posts: 22
S
SamstaUK Offline OP
Newbie
SamstaUK  Offline OP
Newbie
S

Joined: Oct 2008
Posts: 22
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.

Re: Slightly complicated ent_create [Re: SamstaUK] #238188
11/25/08 13:52
11/25/08 13:52
Joined: Jul 2007
Posts: 48
M
MattyTheG Offline
Newbie
MattyTheG  Offline
Newbie
M

Joined: Jul 2007
Posts: 48
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.

Re: Slightly complicated ent_create [Re: MattyTheG] #238192
11/25/08 14:14
11/25/08 14:14
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Online
Senior Expert
Quad  Online
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
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.


3333333333
Re: Slightly complicated ent_create [Re: Quad] #238194
11/25/08 14:33
11/25/08 14:33
Joined: Jul 2007
Posts: 48
M
MattyTheG Offline
Newbie
MattyTheG  Offline
Newbie
M

Joined: Jul 2007
Posts: 48
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.

Re: Slightly complicated ent_create [Re: MattyTheG] #238207
11/25/08 16:44
11/25/08 16:44
Joined: Oct 2008
Posts: 22
S
SamstaUK Offline OP
Newbie
SamstaUK  Offline OP
Newbie
S

Joined: Oct 2008
Posts: 22
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?

Re: Slightly complicated ent_create [Re: MattyTheG] #238208
11/25/08 17:16
11/25/08 17:16
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
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);
}


Re: Slightly complicated ent_create [Re: testDummy] #238212
11/25/08 17:30
11/25/08 17:30
Joined: Oct 2008
Posts: 22
S
SamstaUK Offline OP
Newbie
SamstaUK  Offline OP
Newbie
S

Joined: Oct 2008
Posts: 22
var behind_v[3] = {0,0,0};

Causes parameter unknown errors.

Re: Slightly complicated ent_create [Re: SamstaUK] #238259
11/25/08 23:39
11/25/08 23:39
Joined: Jul 2007
Posts: 48
M
MattyTheG Offline
Newbie
MattyTheG  Offline
Newbie
M

Joined: Jul 2007
Posts: 48
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.


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