Questions to nested if-else statements, how to realise that? Read..
#1

Ahoy friends..

This command is part of my latest release Last Bed Standing, but i want to improve something.

Thats the command to /blow an enemies bed up, a bed of another team.
The problem is: You can even blow up the bed of your own team but now i want to avoid that, but unfortunately i dont know how because its a complicated situation.

Код:
if(strcmp(cmdtext, "/blowup", true) == 0)
	{
		for(new i = 0; i < sizeof(beds[]); i++)
		{
			new Float:health;
			GetPlayerHealth(playerid,health);

			if(running !=1 && IsPlayerInRangeOfPoint(playerid,10.0,beds[i][0],beds[i][1],beds[i][2]) && health > 0 && !IsPlayerInAnyVehicle(playerid)) // In this script we deal with players only
			{
				running = 1;


				if(i == 0 && bedstateviolet !=-1 )
				{
					bedstateviolet=-1;
					SendClientMessage(playerid, COLOR_WHITE, "SERVER: You are blowing up the bed of Team {610D96}VIOLET");
				}
				if(i == 1 && bedstatebrown !=-1 )
				{
					bedstatebrown=-1;
					SendClientMessage(playerid, COLOR_WHITE, "SERVER: You are blowing up the bed of Team {8B4513}BROWN");
				}
				if(i == 2 && bedstateyellow !=-1 )
				{
					bedstateyellow=-1;
					SendClientMessage(playerid, COLOR_WHITE, "SERVER: You are blowing up the bed of Team {FFFF00}YELLOW");
				}
				
					SendClientMessage(playerid, COLOR_WHITE, "SERVER: Planted Bomb Successfully. Lets Blow This Bed Up!");
					SetPlayerScore(playerid, GetPlayerScore(playerid) + 1);
					SendClientMessage(playerid, COLOR_WHITE, "SERVER: Keep Running! Bed Will Blow Up In 5 seconds!");
					GetPlayerPos(playerid, x1, y1, z1);
					ApplyAnimation(playerid, "BOMBER", "BOM_Plant_Loop", 4.0, 1, 0, 0, 1, 1);
					for(new k = 0; k < MAX_PLAYERS; k++)
					{
						PlayerPlaySound(k,7416,x1,y1,z1);
					}
					SetTimer("BlowUpThisBed", bombtimer, false);
					CountDownTimer = SetTimer("CountDown", 1000, true);
					new Float:dist = GetDistance(beds[i][0],beds[i][1],beds[i][2],x1,y1,z1);
					printf("Distance to closest bed: %f, Index: %d", dist, i);
				
				

				return 1;

			}



		}
		return 0;

	}
The player team is set with gPlayerTeamSelection[playerid] = TEAM_EXAMPLE
So the player should be able to blow up a bed if the bed doesnt belong to its team.


There are 3 Teams.
TEAM_VIOLET, TEAM_YELLOW TEAM_BROWN
The array which is necessary to locate the closest bed for this command

Код:
new const Float:beds[][3] = {
	{-2340.7637,-2024.7919,270.5094},//VIOLET
	{-2812.6035,-1515.9814,140.8438},//Brown
	{-2326.8735,-1356.4872,300.2661}//Yellow
};
i == 0 // Bed of TEAM_VIOLET
i == 1 // Bed of TEAM_BROWN
i == 2 // Bed of TEAM_YELLOW

So im searching for some help because i dont know how to realise that without changing absolutely everything!
Reply
#2

https://sampwiki.blast.hk/wiki/Control_Structures#else_if

Did you even try looking at wiki?
Reply
#3

Quote:
Originally Posted by Unte99
Посмотреть сообщение
How rude I think he already knows what that means... he created something with that knowledge already.

Now to the question...

Assuming that you have also set the beds to its own teams you can just setthat if the current team member is in the current team bed he can't use such command..

i.e
PHP код:
if(IsPlayerInRangeOfPoint(playeridbed positions xyzwhich is their beds location since I don't know what variable you are using for teaming the bed.
 blow up bed.
else
you are not on your bed. 
it should look something like that.
Reply
#4

You can do it like this :
PHP код:
if(running !=&& IsPlayerInRangeOfPoint(playerid,10.0,beds[i][0],beds[i][1],beds[i][2]) && health && !IsPlayerInAnyVehicle(playerid)) // In this script we deal with players only
{
    
//insert the below two line in your code :
    
if((== &&  gPlayerTeamSelection[playerid] == TEAM_VIOLET) || (== &&  gPlayerTeamSelection[playerid] == TEAM_BROWN) || (== &&  gPlayerTeamSelection[playerid] == TEAM_YELLOW))
        return 
SendClientMessage(playerid, -1"You cannot blow your own team bed!"); 
Reply
#5

Thanks it works! Thanks for your help
Reply
#6

Quote:
Originally Posted by JesterlJoker
Посмотреть сообщение
How rude I think he already knows what that means... he created something with that knowledge already.
How rude of me giving him a link to what he wanted when he could have found it himself easily? No wonder you have "Joker" in your username. He wasn't even using if else checks. What the hell are you even talking about?
Reply
#7

I have no reason to go against you or anything but you didn't consider this..

number one. He created a gamemode.

number two. He already finished the gamemode and posted it on the gamemode thread.

and lastly he asked how to it. He approached us with a code on what to do, He doesn't need to read the basics coz basically he is already advance at what you presented.

You did the right thing if you were presenting it on a newbie who exactly doesn't know anything... But downright here on this thread you are wrong, because the guy you presented that link is not a beginner anymore...

Sorry for messing on this thread...
Reply
#8

Quote:
Originally Posted by JesterlJoker
Посмотреть сообщение
I have no reason to go against you or anything but you didn't consider this..

number one. He created a gamemode.

number two. He already finished the gamemode and posted it on the gamemode thread.

and lastly he asked how to it. He approached us with a code on what to do, He doesn't need to read the basics coz basically he is already advance at what you presented.

You did the right thing if you were presenting it on a newbie who exactly doesn't know anything... But downright here on this thread you are wrong, because the guy you presented that link is not a beginner anymore...

Sorry for messing on this thread...
1) So by your logic if I create a gamemode (doesn't matter what kind of, even a broken one) I magically become an expert? I don't think that's how it works.

2) What does releasing a gamemode has to do with this topic...?

3)
Quote:

He doesn't need to read the basics coz basically he is already advance at what you presented.

He is advanced but he doesn't know how to do it...?

Reply
#9

Then I'll just end your post into a hanging question.. I won't answer because I know you will just go on and on and on and on and on and sometime soon repeat a question you have made on a later post... Let's just end it here...

Like I said you are not wrong for pointing out the basics, but I a too am not wrong for giving him a direction, a guide, an example on what to do... The case on this side of the forum is for scripting help only not for our arguments to get big...

There are times that people get confused that's why he ran for help... That's just it... I don't want to argue anymore... The problem was solved and the point was we made an effort to help... and also because I started this I apologize for the rude opening... I just didn't think of what to say...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)