Simple script problem
#1

I have a script like this. I want that when i write /breakout and im not on *IsPlayerInRangeOfPoint* it should write *You are not in /breakout checkpoint*, but it doesnt. I guess i missed a bracket or something.
Код:
     	if (strcmp("/breakout", cmdtext, true, 5) == 0)
		 {
		 if (gTeam[playerid] == TEAM_BALLA)
		 {
    	 if(IsPlayerInRangeOfPoint(playerid, 2.0, 234.8687,1118.6041,1084.9922))
		 SetPlayerPos(playerid,2482.2227,-1646.2852,18.3521);
         SetPlayerInterior(playerid,0);
         }
         }
         else
          {
         SendClientMessage(playerid, COLOR_WHITE,"You are not in /breakout checkpoint");
         return 0;
         }
         return 0;
And another thing, could you explain to me script line *if (strcmp("/breakout", cmdtext, true, 5) == 0)*
What is (srtcmp ,cmdtext, true, 5) == 0)
Reply
#2

use
pawn Код:
if (!strcmp("/breakout", cmdtext) )
another version of what you want
pawn Код:
if(!strcmp("/breakout", cmdtext) )
{
    if(!IsPlayerInRangeOfPoint(playerid, 2.0, 234.8687,1118.6041,1084.9922))return SendClientMessage(playerid, COLOR_WHITE,"You are not in /breakout checkpoint");
    if (gTeam[playerid] == TEAM_BALLA)
    {
        SetPlayerPos(playerid,2482.2227,-1646.2852,18.3521);
        SetPlayerInterior(playerid,0);
        return 1;
    }
    if(gTeam[playerid] == OTHER_TEAM)
    {
         //other stuff for other teams
    }
}
Reply
#3

pawn Код:
if (!strcmp("/breakout", cmdtext, true, 5) == 0)
         {
         if (gTeam[playerid] == TEAM_BALLA)
         {
         if(IsPlayerInRangeOfPoint(playerid, 2.0, 234.8687,1118.6041,1084.9922))
         SetPlayerPos(playerid,2482.2227,-1646.2852,18.3521);
         SetPlayerInterior(playerid,0);
         }
         }
         else
          {
         SendClientMessage(playerid, COLOR_WHITE,"You are not in /breakout checkpoint");
         return 1;
         }
         return 0;
         }
if you have more cmds underneath, remove the return 0

This forum requires that you wait 120 seconds between posts. Please try again in 39 seconds.

ugh.
Reply
#4

Quote:
Originally Posted by nejc001
Посмотреть сообщение
I have a script like this. I want that when i write /breakout and im not on *IsPlayerInRangeOfPoint* it should write *You are not in /breakout checkpoint*, but it doesnt. I guess i missed a bracket or something.
Код:
     	if (strcmp("/breakout", cmdtext, true, 5) == 0)
		 {
		 if (gTeam[playerid] == TEAM_BALLA)
		 {
    	 if(IsPlayerInRangeOfPoint(playerid, 2.0, 234.8687,1118.6041,1084.9922))
		 SetPlayerPos(playerid,2482.2227,-1646.2852,18.3521);
         SetPlayerInterior(playerid,0);
         }
         }
         else
          {
         SendClientMessage(playerid, COLOR_WHITE,"You are not in /breakout checkpoint");
         return 0;
         }
         return 0;
And another thing, could you explain to me script line *if (strcmp("/breakout", cmdtext, true, 5) == 0)*
What is (srtcmp ,cmdtext, true, 5) == 0)
pawn Код:
if (strcmp("/breakout", cmdtext, true, 5) == 0)
{
    if (gTeam[playerid] == TEAM_BALLA)
    {
        if(IsPlayerInRangeOfPoint(playerid, 2.0, 234.8687,1118.6041,1084.9922))
        {
            SetPlayerPos(playerid,2482.2227,-1646.2852,18.3521);
            SetPlayerInterior(playerid,0);
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_WHITE,"You are not in /breakout checkpoint");
    }
    return 1;
}
Try that. You missed some brackets and I fixed your return 0;'s.

The strcmp thing:

strcmp compares two "strings" to see if they are the same.

if (strcmp("/breakout", cmdtext, true, 5) == 0)
If "/breakout" is the same as cmdtext(what was typed by the player), then execute the command.

"true" is wether or not to check for upper/lower case letters.
If it is "false", "Hello" and "hEllo" are not the same. If it's true, they are the same.
Reply
#5

Quote:
Originally Posted by CrucixTM
Посмотреть сообщение
pawn Код:
if (strcmp("/breakout", cmdtext, true, 5) == 0)
{
    if (gTeam[playerid] == TEAM_BALLA)
    {
        if(IsPlayerInRangeOfPoint(playerid, 2.0, 234.8687,1118.6041,1084.9922))
        {
            SetPlayerPos(playerid,2482.2227,-1646.2852,18.3521);
            SetPlayerInterior(playerid,0);
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_WHITE,"You are not in /breakout checkpoint");
    }
    return 1;
}
Try that. You missed some brackets and I fixed your return 0;'s.

The strcmp thing:

strcmp compares two "strings" to see if they are the same.

if (strcmp("/breakout", cmdtext, true, 5) == 0)
If "/breakout" is the same as cmdtext(what was typed by the player), then execute the command.

"true" is wether or not to check for upper/lower case letters.
If it is "false", "Hello" and "hEllo" are not the same. If it's true, they are the same.
its
pawn Код:
(!strcmp("/breakout", cmdtext, true, 5) == 0)
the '!' is very important.
Reply
#6

Quote:
Originally Posted by iggy1
Посмотреть сообщение
its (!strcmp("/breakout", cmdtext, true, 5) == 0) the '!' is very important.
I completely missed that error in his code. Obviously. I'll fix the code I posted for him
Reply
#7

Quote:
Originally Posted by iggy1
Посмотреть сообщение
its
pawn Код:
(!strcmp("/breakout", cmdtext, true, 5) == 0)
the '!' is very important.
What the hell are you doing?
First of all, when you ! is the same as "is false", aka. is equal to 0

So do either
pawn Код:
(!strcmp("/breakout", cmdtext, true, 5))
or
pawn Код:
(strcmp("/breakout", cmdtext, true, 5) == 0)
Second of all, "/breakout" isn't only 5 characters. Either remove "5" or change it to the correct value:
pawn Код:
(!strcmp("/breakout", cmdtext, true, 9)) //dno if null counts, if so it's 10, not 9

EDIT: This code should work:
pawn Код:
if( !strcmp( cmdtext, "/breakout", true ))
{
    if( gTeam[playerid] != TEAM_BALLA )
        return 0;
    if( !IsPlayerInRangeOfPoint( playerid, 2.0, 234.8687, 1118.6041, 1084.9922 ))
        return 0;
    SetPlayerPos(playerid,2482.2227,-1646.2852,18.3521);
    SetPlayerInterior(playerid,0);
    return 1;
}
Reply
#8

YEAH goddamn you Iggy

LarzI corrected it
Reply
#9

Quote:
Originally Posted by LarzI
What the hell are you doing?
First of all, when you ! is the same as "is false", aka. is equal to 0
My bad i copy pasted the code but just added !.

Quote:
Originally Posted by LarzI
Second of all, "/breakout" isn't only 5 characters. Either remove "5" or change it to the correct value:
You dont need to do that if its 5 charachters. It just means that if you do /brea it will be the same as doing /breakout.
Reply
#10

Quote:
Originally Posted by iggy1
Посмотреть сообщение
use
pawn Код:
if (!strcmp("/breakout", cmdtext) )
another version of what you want
pawn Код:
if(!strcmp("/breakout", cmdtext) )
{
    if(!IsPlayerInRangeOfPoint(playerid, 2.0, 234.8687,1118.6041,1084.9922))return SendClientMessage(playerid, COLOR_WHITE,"You are not in /breakout checkpoint");
    if (gTeam[playerid] == TEAM_BALLA)
    {
        SetPlayerPos(playerid,2482.2227,-1646.2852,18.3521);
        SetPlayerInterior(playerid,0);
        return 1;
    }
    if(gTeam[playerid] == OTHER_TEAM)
    {
         //other stuff for other teams
    }
}
I still dont understand why that doesn't work it gives no errors to me and looks like it will work.(also doesnt have a size)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)