Simple /enter command problem
#1

So I have this code for my server I'm working on, I want to make it to where you type /enter to enter a building, and /exit to leave the building. Here is the code:

Code:
	if (strcmp("/enter", cmdtext, true, 6) == 1)
	{
		if (PlayerToPoint(playerid, Float:10, Float:2104.8997, Float:-1806.4668, Float:14.1484) == 0)
		{
			SetPlayerInterior(playerid, 5);
			SetPlayerPos(playerid, Float:372.3520, Float:-131.6543, Float:1001.4922);
			SendClientMessage(playerid, 0xffffffff, "Welcome to the Pizza Parlor");
			SetPlayerFacingAngle(playerid, Float:0.0);
			return 1;
		}
		else if (PlayerToPoint(playerid, Float:10, Float:1554.9174, Float:-1675.5553, Float:15.5010) == 0)
		{
		  SetPlayerInterior(playerid, 6);
		  SetPlayerPos(playerid, Float:246.7840, Float:63.9002, Float:1003.6406);
		  SendClientMessage(playerid, 0xffffffff, "Welcome to the Police Department");
		  return 1;
 		}
 		else
 		{
 		  SendClientMessage(playerid, 0xff0000AA, "ERROR: You can't enter here!");
		}
The command works when the "If" lines all have the final parameter " == 0)" but then the command will teleport you to the Pizzaria, regardless of your location. When the "If" lines are set to == 1, I get the message "SERVER: Unknown Command". It's probably something simple that I'm missing, and I'm still new with "if". Please help, and thanks in advance.

P.S. I have a feeling that it is failing due to the "If" lines.
Reply
#2

pawn Code:
if (strcmp("/enter", cmdtext, true, 6) == 0)
{
    if (PlayerToPoint(playerid, 10, 2104.8997, -1806.4668, 14.1484))
    {
        SetPlayerInterior(playerid, 5);
        SetPlayerPos(playerid, 372.3520, -131.6543, 1001.4922);
        SendClientMessage(playerid, 0xffffffff, "Welcome to the Pizza Parlor");
        SetPlayerFacingAngle(playerid, Float:0.0);
        return 1;
    }
    else if (PlayerToPoint(playerid, 10, 1554.9174, -1675.5553, 15.5010))
    {
        SetPlayerInterior(playerid, 6);
        SetPlayerPos(playerid, 246.7840, 63.9002, 1003.6406);
        SendClientMessage(playerid, 0xffffffff, "Welcome to the Police Department");
        return 1;
    }
    else return SendClientMessage(playerid, 0xff0000AA, "ERROR: You can't enter here!");
    return 1;
}
Reply
#3

I tried that out, but now I got
Code:
C:\Program Files\Rockstar Games\GTA San Andreas\samp\gamemodes\my-Gamemode.pwn(234) : warning 225: unreachable code
C:\Program Files\Rockstar Games\GTA San Andreas\samp\gamemodes\my-Gamemode.pwn(236) : warning 209: function "OnPlayerCommandText" should return a value
C:\Program Files\Rockstar Games\GTA San Andreas\samp\gamemodes\my-Gamemode.pwn(237) : error 010: invalid function or declaration
C:\Program Files\Rockstar Games\GTA San Andreas\samp\gamemodes\my-Gamemode.pwn(239) : error 010: invalid function or declaration
C:\Program Files\Rockstar Games\GTA San Andreas\samp\gamemodes\my-Gamemode.pwn(245) : error 010: invalid function or declaration
C:\Program Files\Rockstar Games\GTA San Andreas\samp\gamemodes\my-Gamemode.pwn(247) : error 010: invalid function or declaration
C:\Program Files\Rockstar Games\GTA San Andreas\samp\gamemodes\my-Gamemode.pwn(330) : warning 203: symbol is never used: "ret_memcpy"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#4

Ok, so I fixed up the code that you gave me and got it down to two warnings so that i could compile/run, but now no matter where I am, if I type /enter it always gives me "ERROR: You cant enter here!"

lol, we're makin progress though!
Reply
#5

pawn Code:
if (strcmp("/enter", cmdtext, true, 6) == 0)
    {
        if (PlayerToPoint(playerid, 10, 2104.8997, -1806.4668, 14.1484))
        {
            SetPlayerInterior(playerid, 5);
            SetPlayerPos(playerid, 372.3520, -131.6543, 1001.4922);
            SendClientMessage(playerid, 0xffffffff, "Welcome to the Pizza Parlor");
            SetPlayerFacingAngle(playerid, Float:0.0);
        }
    }
   
    if (PlayerToPoint(playerid, 10, 1554.9174, -1675.5553, 15.5010))
    {
        SetPlayerInterior(playerid, 6);
        SetPlayerPos(playerid, 246.7840, 63.9002, 1003.6406);
        SendClientMessage(playerid, 0xffffffff, "Welcome to the Police Department");
    }
    else return SendClientMessage(playerid, 0xff0000AA, "ERROR: You can't enter here!");
    return 1;
    }
Reply
#6

cool thanks, it works now
Reply
#7

*sigh* another problem... this time with the /exit command... I copied the way it looks (here it is)

Code:
	if (strcmp("/exit", cmdtext, true, 10) ==0)
	{
	  if (PlayerToPoint(playerid, Float:10, Float:362.3520, Float:-131.6543, Float:1001.4922))
	  {
	    SetPlayerInterior(playerid, 0);
	    SetPlayerPos(playerid, Float:2104.8997, Float:-1806.4668, Float:14.1484);
	    SendClientMessage(playerid, 0xffffffff, "You have left the Pizza Parlor.");
	    SetPlayerFacingAngle(playerid, Float:90.0);
     }
     else if (PlayerToPoint(playerid, Float:10, Float:245.7840, Float:63.9002, Float:1003.6406))
     {
      SetPlayerInterior(playerid, 0);
      SetPlayerPos(playerid, Float: 1554.9174, Float:-1675.5553, Float:15.5010);
      SendClientMessage(playerid, 0xfffffff, "You have left the Police Department.");
      SetPlayerFacingAngle(playerid, Float:90.0);
     }
		else return SendClientMessage(playerid, 0xff0000AA, "ERROR: You cant exit a building from your position");
		return 1;
	}
I made it look as similar as the other ones, but I'm not sure if PlayerToPoint works with Interior IDs, because there is no "interiorid" param in the PlayerToPoint function.

Basically, no matter where I am, it always returns "ERROR: ..." I'm not sure what the problem is here :/
Reply
#8

pawn Code:
if (strcmp("/exit", cmdtext, true) ==0)
    {
      if (PlayerToPoint(10.00, playerid, 362.3520, -131.6543, 1001.4922))
      {
        SetPlayerInterior(playerid, 0);
        SetPlayerPos(playerid, Float:2104.8997, Float:-1806.4668, Float:14.1484);
        SendClientMessage(playerid, 0xffffffff, "You have left the Pizza Parlor.");
        SetPlayerFacingAngle(playerid, Float:90.0);
     }

     if (PlayerToPoint(10.00, playerid, 245.7840, 63.9002, 1003.6406))
     {
      SetPlayerInterior(playerid, 0);
      SetPlayerPos(playerid, Float: 1554.9174, Float:-1675.5553, Float:15.5010);
      SendClientMessage(playerid, 0xfffffff, "You have left the Police Department.");
      SetPlayerFacingAngle(playerid, Float:90.0);
     }
    else return SendClientMessage(playerid, 0xff0000AA, "ERROR: You cant exit a building from your position");
    return 1;
    }
Reply
#9



I still get the message "You cannot exit a building from your position."

the same problem as earlier
Reply
#10

Dumb question but, are you sure you are close to the required coord?

Try removing the else SendClientMessage ... just to see what happens.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)