help here if n else

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 641
help here if n else
«  »Last edited
suppose i have a code

Code: [Select]
function onPlayerSpawn( player )
{

if ( player.World != 24) {
player.World = 1;
}
else
{
if(something == something) { player.Pos = Vector(  -1734.98,-1725.85,14.868 ); player.Colour = RGB(255, 0, 0); player.Skin = 73; }
else if (something == something) { player.Pos = Vector(-1099.68,1393.21,8.73682); player.Colour = RGB(0, 0, 255); player.Skin = 95; }
return;
}

 if ( player.World != 27 ) {
player.World = 1;
}

else {
if (something == something) { player.Pos = Vector( 605.065,-745.095,11.0712 ); player.Colour = RGB(255, 0,255);player.Skin = 90; }
else if (something == something) { player.Pos = Vector(600.586,-937.486,11.972);player.Colour = RGB(0, 255, 255);player.Skin = 145; }
return;
}
}

these both codes are same just world are different

am i using the statements correctly?
bcz they r not working as expected, for example if a player dies in world 24 he should spawn in same world and 27 world player should spawn in 27 but they dont

DraGone

  • Newbie
  • Posts: 2
Re: help here if n else
« Reply #1,  »Last edited
I'm not sure what you are trying to achieve, but here it is..
Code: [Select]
function onPlayerSpawn( player )
{
if ( player.World == 24 )
{
/* If player is in world 24, server will run the code below */
if(something == something) {
player.Pos = Vector(  -1734.98,-1725.85,14.868 );
player.Colour = RGB(255, 0, 0);
player.Skin = 73;
}
else if (something == something) {
player.Pos = Vector(-1099.68,1393.21,8.73682);
player.Colour = RGB(0, 0, 255);
player.Skin = 95;
}
}
else if ( player.World == 27 )
{
/* If player is in world 27, server will run the code below */
if (something == something) {
player.Pos = Vector( 605.065,-745.095,11.0712 );
player.Colour = RGB(255, 0,255);
player.Skin = 90;
}
else if (something == something) {
player.Pos = Vector(600.586,-937.486,11.972);
player.Colour = RGB(0, 255, 255);
player.Skin = 145;
}
}
else
{
/* If player is not in world ID 24 nor 27, server will run the code below */
player.World = 1;
}
}

Link below should give you some clue about how if, else if and else works
https://www.tutorialspoint.com/cplusplus/cpp_if_else_statement.htm

MEGAMIND

  • Hero Member
  • Developer of "Web-Net" search engine
  • Posts: 641