Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
1 registered members (Grant), 999 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Players respawn [splitscreen] #349272
12/05/10 17:02
12/05/10 17:02
Joined: May 2009
Posts: 5,365
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,365
Caucasus
I'm trying to change AUM's splitscreen shooter example, so when some of the players die, they don't need to restart whole level, dead player will just randomly respawn on some of predefined places on the level and an other one will keep playing.
So here are two questions:
1 --> How can I define places for players to respawn, so when one of the players die, he will respawn on the most far place from the second player.
2 --> How can I respawn (recreate) players? Do I need to remove them completely with their pointers (player1 and player2)?
Any ideas will be great (and some code examples will be just excellent).


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Players respawn [splitscreen] [Re: 3run] #349276
12/05/10 17:37
12/05/10 17:37
Joined: Feb 2010
Posts: 886
Random Offline
User
Random  Offline
User

Joined: Feb 2010
Posts: 886
Try it like this;

ent_create(Model_mdl,vector(random(200),random(200),0),move);

Orange;
Create youre model

Purple;
The Vector

Red;
The randomly setting

Blue;
The function.



Re: Players respawn [splitscreen] [Re: 3run] #349277
12/05/10 17:49
12/05/10 17:49
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline
User
hopfel  Offline
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
1. The easiest way, you do define a position like:

var random_var = random(360);
my.x = cos(random_var) * distance_to_player;
my.y = sin(random_var) * distance_to_player;

And then make a scan on that point, if there isn't something in the way, create the player there, if not, try again.


2. I would make a function without global pointers you can create players with.
It's a bunch of work, but the most comfortable solution, because
you don't have to take attention, when you have to create and remove the player.
(something like that is the best way to create enemies too)


Hilf mir, dir zu helfen!
Re: Players respawn [splitscreen] [Re: Random] #349278
12/05/10 17:54
12/05/10 17:54
Joined: Feb 2005
Posts: 3,687
Hessen, Germany
T
Tempelbauer Offline
Expert
Tempelbauer  Offline
Expert
T

Joined: Feb 2005
Posts: 3,687
Hessen, Germany
Quote:
1 --> How can I define places for players to respawn, so when one of the players die, he will respawn on the most far place from the second player.

this is quite simple:
1.) define an array of respawn-points (vectors of the xyz-coordinates)
2.) take the position of player 2 and calculate the distance to all respawn-coordinates (using vec_dist, look in the manual)
3.) choose the respawn-point with the highest distance

Re: Players respawn [splitscreen] [Re: Tempelbauer] #349291
12/05/10 19:33
12/05/10 19:33
Joined: May 2009
Posts: 5,365
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,365
Caucasus
Random grin dude, but that will create player randomly for 200 quants from the nullvector))) But thank you for such detailed explanation laugh I appreciate it.

hopfel I got your idea with 'no pointers', that a good and simple solution, why I didn't even think about it myself? grin
But what you think about weapons and cameras (weapon 1 and weapon2 and as well camera1 and camera2)?

Tempelbauer, I thought about using 'vec_dist' too, but I've faced problem with choosing the highest result... Any ideas how can I do that?


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Players respawn [splitscreen] [Re: 3run] #349293
12/05/10 19:46
12/05/10 19:46
Joined: Feb 2010
Posts: 886
Random Offline
User
Random  Offline
User

Joined: Feb 2010
Posts: 886
Maby like this;

function respawn()
{
var i=integer(random(3));
switch(i)
{
case 0:
ent_create(Model_mdl,vector(200,200,0),move));
case 1:
ent_create(Model_mdl,vector(400,400,0),move));
case 2:
ent_create(Model_mdl,vector(800,800,0),move));
}
wait(1);
}


So when a player dies should it respaw in one of those two cases.
Of course you can make more cases.

And again randomly grin



Re: Players respawn [splitscreen] [Re: 3run] #349294
12/05/10 19:56
12/05/10 19:56
Joined: Feb 2005
Posts: 3,687
Hessen, Germany
T
Tempelbauer Offline
Expert
Tempelbauer  Offline
Expert
T

Joined: Feb 2005
Posts: 3,687
Hessen, Germany
you could use 2 vars for the result to determine the target:


var index=-1, highest = 0

for(iterate throu respawnpoints-array)
{
if(vec_dist(player2.x, respawnpoints[i])>highest)
{
index = i
highest = vec_dist(player2.x, respawnpoints[i])
}
}

if(index>=0)
{
most_far_respawnpoint = respawnpoints[index]
}


hopfels idea is good if you dont want to have fixed respawn points.
after calculating the respawn point, you can re-create or re-translate the player to this position and adjust the camera using the player´s coordinates.
but beware: if you have a non planar bottom or a more complex level (like a multi-floor building) you should calculate also the z-coordinate (by using c_trace from the random-generated-z-value to the ground). but i would use (many) fixed respawn points instead a free random position, because if you choose the random-values wrong, your player could respawn at a bad position (like outside the level)

Quote:

So when a player dies should it respaw in one of those two cases.

disagree. he will respawn everytime at vector(800,800,0) and sometimes on more places

Last edited by Tempelbauer; 12/05/10 20:08.
Re: Players respawn [splitscreen] [Re: Tempelbauer] #349297
12/05/10 20:37
12/05/10 20:37
Joined: May 2009
Posts: 5,365
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,365
Caucasus
Quote:
because if you choose the random-values wrong, your player could respawn at a bad position (like outside the level)

I know. That's why I need fixed respawn points laugh

Tell me more about recreating, cause I defined health, and while loop (for each of players) determinate itself when players health under zero, I can't just re-translate player to new position, cause he is dead grin Do I need to set dead player's pointer to NULL and then recreate it again and define pointer to it again?

Tell me more about this part in your script:
Code:
for(iterate throu respawnpoints-array)
{
///
}

Cause I never used to work with 'FOR'...

Random, dude, as I see, function 'random()' is one of your favorites grin


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Players respawn [splitscreen] [Re: 3run] #349298
12/05/10 20:54
12/05/10 20:54
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline
Serious User
darkinferno  Offline
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
you dont need to REMOVE a player when you kill him, just play a death animation and remove player controls, that way you can still move him wherever by coide

Re: Players respawn [splitscreen] [Re: 3run] #349299
12/05/10 20:55
12/05/10 20:55
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline
User
hopfel  Offline
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
Quote:
But what you think about weapons and cameras (weapon 1 and weapon2 and as well camera1 and camera2)?


You can set a var on the Entitypointer in his function, then you can access your playerentity with another function.
Something like:

Code:
var player1;

function player()
{
ENTITY* my_ent = ent_create(...);
if(*I'm player one*)
player1 = my_ent;
...
}


function main()
{
...
if(((ENTITY*)player1))
camera.z = ((ENTITY*)player1).z;
...
}



Oh, and I would put the weapencode in the playerfunction too.
Or like:

Code:
function weapon(ENTITY* my_ent)
{
...
}

function player()
{
ENTITY* my_ent = ent_create(...);
player1 = my_ent;
weapon(my_ent);
...

}




Then you dont have to worry about health etc. because they're away too, just remove the entity and terminate all his functions. ^^


Hilf mir, dir zu helfen!

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