Doing things using one command instead of two.
#1

Hello everyone,

Before I start, I did have some trouble search for this on the forums, I didn't know what words to us in the server. Anyways, I come back in search of some support in my little problem that I wish I could solve on my own, but failed. The problem that I am having is making to different commands work as one. For example, I have a Door that separates the Lobby and the office space of the Los Santos Police Department and you have to use two different commands to operate the door. I would and many others find it easy to use just one command. So instead of using /lspdopen and /lspdclose, all they would have to use to either open/close the door would be /lspd. I have tried different ways of getting this to work without Pawno messing up on me. I did get to a point where Pawno was saying that there was no problem with the code, but when I tried it, the door would not open or close.

Here is the coding for my little Door.

Код:
	// LSPD Lobby open / close
	if (strcmp(cmdtext, "/lspdclose", true) == 0)
	{
		if (!IsACop(playerid))
		{
			SendClientMessage(playerid, COLOR_GREY, "Access Denied: You are not a Law Enforcement official!");
			return 1;
		}
		MoveObject(lspddoor, 245.64070, 72.57476, 1002.65979, 1);
		return 1;
	}
	if (strcmp(cmdtext, "/lspdopen", true) == 0)
	{
		if (!IsACop(playerid))
		{
			SendClientMessage(playerid, COLOR_GREY, "Access Denied: You are not a Law Enforcement official!");
			return 1;
		}
		MoveObject(lspddoor, 247.27613, 72.55864, 1002.65979, 1);
		return 1;
	}
I apologize for any bad indentation of this code. Hope that won't be a problem for any of you. xD
Reply
#2

I think it will work.

Top of your script:
pawn Код:
new LSPDDoor = true;
pawn Код:
if (strcmp(cmdtext, "/lspd", true) == 0)
    {
        if (!IsACop(playerid))
        {
            SendClientMessage(playerid, COLOR_GREY, "Access Denied: You are not a Law Enforcement official!");
            return 1;
        }
        if(LSPDDoor) {
            MoveObject(lspddoor, 245.64070, 72.57476, 1002.65979, 1);
            LSPDDoor = false;
            SendClientMessage(playerid, COLOR_GREY, "You've opened the door.");
            return 1;
        } else {
            MoveObject(lspddoor, 247.27613, 72.55864, 1002.65979, 1);
            LSPDDoor = true;
            SendClientMessage(playerid, COLOR_GREY, "You've closed the door.");
            return 1;
        }
        return 1;
    }
Reply
#3

P3t1, to set a bool to some value, it has to be created as a bool, e.g:
pawn Код:
new bool:LSPDDoor = true;
Reply
#4

It almost did, then I get a Unreachable Warning for some reason. "\\Cpu-test1\samp servers\SAMRP\GAMEMO~1\samrp.pwn(31742) : warning 225: unreachable code" Right at the point where the command is closing off, right at the last return.

MoveObject(lspddoor, 247.27613, 72.55864, 1002.65979, 1);
LSPDDoor = true;
SendClientMessage(playerid, COLOR_GREY, "You've closed the door.");
return 1;
return 1;
}

Quote:
Originally Posted by P3t1
I think it will work.

Top of your script:
pawn Код:
new LSPDDoor = true;
pawn Код:
if (strcmp(cmdtext, "/lspd", true) == 0)
    {
        if (!IsACop(playerid))
        {
            SendClientMessage(playerid, COLOR_GREY, "Access Denied: You are not a Law Enforcement official!");
            return 1;
        }
        if(LSPDDoor) {
            MoveObject(lspddoor, 245.64070, 72.57476, 1002.65979, 1);
            LSPDDoor = false;
            SendClientMessage(playerid, COLOR_GREY, "You've opened the door.");
            return 1;
        } else {
            MoveObject(lspddoor, 247.27613, 72.55864, 1002.65979, 1);
            LSPDDoor = true;
            SendClientMessage(playerid, COLOR_GREY, "You've closed the door.");
            return 1;
        }
        return 1;
    }
Reply
#5

Quote:
Originally Posted by jbtech
It almost did, then I get a Unreachable Warning for some reason. "\\Cpu-test1\samp servers\SAMRP\GAMEMO~1\samrp.pwn(31742) : warning 225: unreachable code" Right at the point where the command is closing off, right at the last return.

MoveObject(lspddoor, 247.27613, 72.55864, 1002.65979, 1);
LSPDDoor = true;
SendClientMessage(playerid, COLOR_GREY, "You've closed the door.");
return 1;
return 1;
Remove that last return statement. Pawn is complaining because every code branch will return a value. It's not possible for the code to ever reach that return statement.
Reply
#6

There we go! Thank you to everyone that assisted in getting this command to work. Much appreciated, take care people!

[quote=samgreen ]
Quote:
Originally Posted by jbtech
It almost did, then I get a Unreachable Warning for some reason. "\\Cpu-test1\samp servers\SAMRP\GAMEMO~1\samrp.pwn(31742) : warning 225: unreachable code" Right at the point where the command is closing off, right at the last return.

MoveObject(lspddoor, 247.27613, 72.55864, 1002.65979, 1);
LSPDDoor = true;
SendClientMessage(playerid, COLOR_GREY, "You've closed the door.");
return 1;
return 1;

Remove that last return statement. Pawn is complaining because every code branch will return a value. It's not possible for the code to ever reach that return statement.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)