Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Spawn an object #147130
08/10/07 19:08
08/10/07 19:08
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Hey,

How can I use a function to spawn an object that will always have the same Z coord, but X and Y will always be at a given distance of an object (this object will be moving..) ?

Thanks
Mark


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Spawn an object [Re: Marky Mark] #147131
08/10/07 20:37
08/10/07 20:37
Joined: Apr 2005
Posts: 67
InnerSpace
dudeBot Offline
Junior Member
dudeBot  Offline
Junior Member

Joined: Apr 2005
Posts: 67
InnerSpace
Using ent_create, this script will spawn a new
entity from a model not currently in the 3D enviroment
and place it behind the target entity. The target can
be moving/rotating.

Code:


//set the model you will be using for the spawned entity
string spawnEntity = "yourModel.mdl";
//
//
//set the distance from the target entity you want to spawn to
var spawnDistance = 30;
//
//
function spawnTheThing()
{
//get outta here if there aint no target entity in the game
if(targetEntity == NULL)
{
return;
}

//set temp to the vector of the target entity
vec_set(temp.x, targetEntity);

//this is the same idea used in a 3rd Person Camera
//it will place the spawned entity behind the target entity
//taking the rotation of the target entity into account
temp.x = targetEntity.x - spawnDistance * cos(targetEntity.pan);
temp.y = targetEntity.y - spawnDistance * sin(targetEntity.pan);

//set spawnEntityAction to NULL if you do not want to asign it a function
ent_create(spawnEntity,temp.x,spawnEntityAction);
}



Just call the function, and you'll get a new entity every time!

Re: Spawn an object [Re: dudeBot] #147132
08/10/07 21:45
08/10/07 21:45
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
How do I set an entity to be the target entity?


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Spawn an object [Re: Marky Mark] #147133
08/11/07 18:04
08/11/07 18:04
Joined: Apr 2005
Posts: 67
InnerSpace
dudeBot Offline
Junior Member
dudeBot  Offline
Junior Member

Joined: Apr 2005
Posts: 67
InnerSpace
The "target entity" is just a name i used for the example code.

You would need to use the entity name you create in your own script
and use it as a point to spawn from.

Re: Spawn an object [Re: dudeBot] #147134
08/11/07 19:19
08/11/07 19:19
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
So let's say I want to spawn my object near another that already got a function, can I just use targetEntity = me ? What do I have to declare? thanks again.


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Spawn an object [Re: Marky Mark] #147135
08/13/07 14:44
08/13/07 14:44
Joined: Apr 2005
Posts: 67
InnerSpace
dudeBot Offline
Junior Member
dudeBot  Offline
Junior Member

Joined: Apr 2005
Posts: 67
InnerSpace
If you are going to spawn new entities based
off of the location of a single entity, like a player,
then you can just use that entity name in place of targetEntity.

If you are going to spawn new entities using mutliple
entites as spawn points, you could define
entity* targetEntity = NULL, and then like you
said, point targetEntity to the entity you want to use as
a vector to spawn to.

Re: Spawn an object [Re: dudeBot] #147136
08/16/07 01:18
08/16/07 01:18
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Thanks!


Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Spawn an object [Re: Marky Mark] #147137
08/19/07 05:42
08/19/07 05:42
Joined: Jul 2002
Posts: 857
Québec
Marky Mark Offline OP
User
Marky Mark  Offline OP
User

Joined: Jul 2002
Posts: 857
Québec
Ok so heres my code:

Code:

//set the model you will be using for the spawned entity
string spawnEntity = "tornado.mdl";
//
//
//set the distance from the target entity you want to spawn to
var spawnDistance = 30;
//
//

action funnel
{
my.invisible=on;
//MOVEMENT CODE OF THE MODEL
}

function spawnTheThing()
{
//get outta here if there aint no target entity in the game
if(funnelEntity == NULL)
{
return;
}

//set temp to the vector of the target entity
vec_set(temp.x, funnelEntity);

//this is the same idea used in a 3rd Person Camera
//it will place the spawned entity behind the target entity
//taking the rotation of the target entity into account
temp.x = funnelEntity.x - spawnDistance * cos(funnelEntity.pan);
temp.y = funnelEntity.y - spawnDistance * sin(funnelEntity.pan);

//set spawnEntityAction to NULL if you do not want to asign it a function
ent_create(spawnEntity,temp.x,tornado);
}



In WED, i place a little box model with the action "funnel" attached to it. In the properties box of the model, I also name it "funnelEntity".

I build, then run, then I get a lot of errors... and it crashes

thanks to help :S

Last edited by Marky Mark; 08/19/07 05:42.

Yeah! IE sucks, use Mozilla...
Marc Rémillard.
Re: Spawn an object [Re: Marky Mark] #147138
08/19/07 19:25
08/19/07 19:25
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
before 'my.invisible = on' put funnelEntity = me;
and before action funnel put 'entity* funnelEntity;'
And btw you should post your errors


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201

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