ItsMods

Full Version: Team code bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

For some time I make a mod on black ops. but I have a problem with this script.

Code:
Team()
{
else if (self.team == allies)
{
self takeallweapons();
self giveWeapon("ray_gun_zm");
self giveWeapon("molotov_sp");
}

else if(self.team == axis)
{
self takeallweapons();
self giveWeapon("freezegun_zm");
}
}

If someone could tell me where the problem is. (after the console is a problem with else if (self.team == allies))

Thanks,

Elite killer
Hello,

else if (self.team == allies)

Why it starts with "else if()" and not with "if (...)" ?

Maybe that is the error.

***********
Usualy, conditions are as follow:
CSHARP Code
  1. if ("monday" == day)
  2. {
  3. // some code
  4. }
  5. else if ("tuesday" == day)
  6. {
  7. // some code
  8. }
  9. else if ("wednersday" == day)
  10. {
  11. // some code
  12. }
  13. else
  14. {
  15. // some code
  16. }
Indeed as the above person posted, there has to be an if statement first, before you can have an else if statement. Try:

COD Code
  1. Team()
  2. {
  3. if (self.team == "allies")
  4. {
  5. self takeallweapons();
  6. self giveWeapon("ray_gun_zm");
  7. self giveWeapon("molotov_sp");
  8. }
  9.  
  10. else if(self.team == "axis")
  11. {
  12. self takeallweapons();
  13. self giveWeapon("freezegun_zm");
  14. }
  15.  
  16. else
  17. {
  18. return;
  19. }
  20. }


I put "" around axis and allies because they should be there, the else statement is probably not needed because there are no other teams than allies or axis, but just to be sure.[/php]
then
now it works in the code onPlayerSpawned ()

Here is my code :

Code:
onPlayerSpawned()
{
    self endon("disconnect");
    for(;;)
    {
        self waittill("spawned_player");
                self thread Team();
(10-03-2012, 16:11)Madnesslink5 Wrote: [ -> ]Indeed as the above person posted, there has to be an if statement first, before you can have an else if statement. Try:

COD Code
  1. Team()
  2. {
  3. if (self.team == "allies")
  4. {
  5. self takeallweapons();
  6. self giveWeapon("ray_gun_zm");
  7. self giveWeapon("molotov_sp");
  8. }
  9.  
  10. else if(self.team == "axis")
  11. {
  12. self takeallweapons();
  13. self giveWeapon("freezegun_zm");
  14. }
  15.  
  16. else
  17. {
  18. return;
  19. }
  20. }


I put "" around axis and allies because they should be there, the else statement is probably not needed because there are no other teams than allies or axis, but just to be sure.[/php]


Why 'return;' ?
Just use "switch(self.team)", its better;
Thx, but where i place this code ?
He says that you can replace:
CSHARP Code
  1. Team()
  2. {
  3. if (self.team == "allies")
  4. {
  5. self takeallweapons();
  6. self giveWeapon("ray_gun_zm");
  7. self giveWeapon("molotov_sp");
  8. }
  9.  
  10. else if(self.team == "axis")
  11. {
  12. self takeallweapons();
  13. self giveWeapon("freezegun_zm");
  14. }
  15.  
  16. else
  17. {
  18. return;
  19. }
  20. }


By something like:
CSHARP Code
  1. Team()
  2. {
  3. switch(self.team)
  4. {
  5. case "allies":
  6. self takeallweapons();
  7. self giveWeapon("ray_gun_zm");
  8. self giveWeapon("molotov_sp");
  9. break;
  10. case "axis":
  11. self takeallweapons();
  12. self giveWeapon("freezegun_zm");
  13. break;
  14. default:
  15. break;
  16. }
  17. }


But why a switch for only 2 cases...? Discussion opened lol
As it's gsc it doesn't really matter which one you use. But generally for 2 cases the best is if statement.
(10-06-2012, 19:29)zxz0O0 Wrote: [ -> ]As it's gsc it doesn't really matter which one you use. But generally for 2 cases the best is if statement.

Well, cases looks better than if statements lol....