Not logged inOpenClonk Forum
Up Topic Development / Scenario & Object Development / [QUESTION]How to set Clonk respawn depending on team id?
- - By Sayned [kz] Date 2013-02-17 05:44 Edited 2013-02-17 16:30
I need to make clonks from team with id1 spawn on [125, 100],[125, 210],[125, 320],[125, 430] when clonks from team with id2 will spawn on [675, 100],[675, 210],[675, 320],[675, 430]
I have tried different ways to make it, but it wasn't working, so I have removed this useless code. Can anybody help me?

Update 1:
Here is my code:

protected func InitializePlayer(int plr)
{
  return RelaunchPlayer(plr);
}

protected func RelaunchPlayer(int plr)
{
  var clonk = GetCrew(plr);
  clonk->DoEnergy(1000);
  var pos = [[125, 100],[125, 210],[125, 320],[125, 430],[675, 100],[675, 210],[675, 320],[675, 430]];
  var random=Random(GetLength(pos));
  var x = pos[random][0], y = pos[random][1];
  var relaunch = CreateObject(RelaunchContainer, x, y, clonk->GetOwner());
  relaunch->StartRelaunch(clonk);
  return;
}

func KillsToRelaunch() { return 0; }
func RelaunchWeaponList() { return [TeleGlove, JarOfWinds]; }

You may ignore Weapon List because maybe I will make every clonk get Jar of Winds on spawn.
Gamemode is Last Man Standing, first team(id1) spawns on left side, second team(id2) - on right. And as you can see, I don't use JoinPlayer.
Parent - By Caesar [de] Date 2013-02-17 10:41
Well, the best thing would be if you showed us your code...
Parent - - By Armin [de] Date 2013-02-17 12:29 Edited 2013-02-17 12:32
func RelaunchPlayer(int iPlr)
{
  var clonk = CreateObject(Clonk, 10,10, iPlr);
  clonk->MakeCrewMember(iPlr);
  SetCursor(iPlr, clonk);
  var y1 = [100, 210, 320, 430];
  var y2 = [100, 210, 320, 430];
  var rnd = Random(4);
  if (GetTeamByIndex(iPlr) == 0)
    clonk->SetPosition(125, y1[rnd]);
  else
    clonk->SetPosition(675, y2[rnd]);
  Log("Clonk from team %d spawned on X: %d Y: %d.", GetTeamByIndex(iPlr)+1, clonk->GetX(), clonk->GetY());
}

IDK whether you want the positions beeing randomly choosen like that. Otherwise you need to describe it more.
Parent - - By Sayned [kz] Date 2013-02-17 16:28
Thank you for answering. But it doesn't work... Next time I should show my code and describe map. So here is my code:

protected func InitializePlayer(int plr)
{
  return RelaunchPlayer(plr);
}

protected func RelaunchPlayer(int plr)
{
  var clonk = GetCrew(plr);
  clonk->DoEnergy(1000);
  var pos = [[125, 100],[125, 210],[125, 320],[125, 430],[675, 100],[675, 210],[675, 320],[675, 430]];
  var random=Random(GetLength(pos));
  var x = pos[random][0], y = pos[random][1];
  var relaunch = CreateObject(RelaunchContainer, x, y, clonk->GetOwner());
  relaunch->StartRelaunch(clonk);
  return;
}

func KillsToRelaunch() { return 0; }
func RelaunchWeaponList() { return [TeleGlove, JarOfWinds]; }

You may ignore Weapon List because maybe I will make every clonk get Jar of Winds on spawn.
Gamemode is Last Man Standing, first team(id1) spawns on left side, second team(id2) - on right. And as you can see, I don't use JoinPlayer.
I hope this information will be enough, if not, ask me ;)
Parent - - By Caesar [de] Date 2013-02-17 17:09
Mh. I can't find anything that strikes my eye. Does the Log report errors? Also, does something happen at all?
Parent - - By Sayned [kz] Date 2013-02-17 17:58
Nothing strikes my eye too. Log doesn't report anything just say " 0 warnings, 2 errors" when I use Armin's code. And when clonk spawn it spawn on right place but it don't get any items. So I think to solve the problem, I will need to make "JoinPlayer" function and add Armin's "Relaunch Player". What do you think?
Parent - - By Sven2 [de] Date 2013-02-17 18:07

>  just say " 0 warnings, 2 errors"


Check your Clonk.log to see the error messages.
Parent - By Zapper [de] Date 2013-02-17 18:16
It's named OpenClonk.log now :)
Parent - - By Sayned [kz] Date 2013-02-17 18:36
Seems like my Clonk.log doesn't update...
C:\Users\*MyUserName*\AppData\Roaming\OpenClonk\Clonk.log shows me logs, that were last time editen in 2011(probably first time when I was playing OpenClonk with my friend)
Anyway, I have realised, that it doesn't show any errors when I place Armin's code to my map, but it spawn 2 clonks(1 on right place, another on random place) and then I have fixed it and got 2 unknown for me errors. As I remeber, when I fixed it, everything was ok except of 2 mystic errors and that clonks were spawning without menu where they can choose a weapon

P.S. Sorry if my english is bad
Parent - By Sven2 [de] Date 2013-02-17 18:40
There should be a log somewhere. Just search for OpenClonk.log using the regular Windows file search.
Parent - By Caesar [de] Date 2013-02-17 22:49
The relaunch creates a clonk. Armins code unconditionally creates a clonk and places it according to the positions. You may want to do something like Zapper did and check GetCrew first.
Parent - - By Zapper [de] Date 2013-02-17 17:37
You might need to create a new Clonk when the player relaunches.

var clonk = GetCrew(plr);
if (!clonk)
{
    clonk = CreateObject(Clonk, 0, 0, plr);
    clonk->MakeCrewMember(plr);
}
Parent - By Sayned [kz] Date 2013-02-18 12:30 Edited 2013-02-18 15:15
Thank you! Now it works!

Update: LOL actually it doesn't work. I need to test everything careful.
Parent - - By Sayned [kz] Date 2013-02-18 15:13 Edited 2013-02-18 15:15
Lol. We with my friend started testing it and clonk started spawning on same side of map :\
Seems like next time I need to test everything more careful...
So I think that we need to make something like that:
protected func RelaunchPlayer(int plr)
{
var clonk = GetCrew(plr);
if (!clonk)
{
    clonk = CreateObject(Clonk, 0, 0, plr);
    clonk->MakeCrewMember(plr);
}
  SetCursor(plr, clonk);
  var y = [100, 210, 320, 430];
  var rnd = Random(4);
  if (GetTeamByIndex(plr) == 0)
    clonk->SetPosition(685, y[rnd]);
  else
    clonk->SetPosition(125, y[rnd]);
  Log("Clonk from team %d spawned on X: %d Y: %d.", GetTeamByIndex(plr)+1, clonk->GetX(), clonk->GetY());
clonk->CreateContents(JarOfWinds);
}
And as I understand if game gets team by index, it spawn clonk on 125.

So we need to add something to use index, maybe something like that:

GetTeamByIndex == 1;
if (TeamByIndex(plr) == 2)
    clonk->SetPosition(685, y[rnd]);
  else
    clonk->SetPosition(125, y[rnd]);

But the game don't know "TeamByIndex"...
Parent - - By Zapper [de] Date 2013-02-18 15:26
GetTeamByIndex would be the wrong choice.
You can get the team of a player with GetPlayerTeam.
So something like

if (GetPlayerTeam(plr) == 1)
    clonk->SetPosition(685, ...);
else
    clonk->SetPosition(125, ...);

should work
Parent - By Sayned [kz] Date 2013-02-18 15:34
Tested it, no errors, clonks spawn on right places. Now we will test map with my friend. Thank you!
Up Topic Development / Scenario & Object Development / [QUESTION]How to set Clonk respawn depending on team id?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill