Remote function
#1

Hello,
I am trying to make script, that give tickets to players.
I am trying to use the function IsACop to make sure cops wont get tickets.

Script in gamemode:
Код:
IsACop(playerid)
{
	if(IsPlayerConnected(playerid))
	{
		new leader = PlayerInfo[playerid][pLeader];
		new member = PlayerInfo[playerid][pMember];
		if(member==1 || member==2 || member== 3 || member==5 || member==3 || member==6 || member==7 || member==11 || member==13)
		{
			return 1;
		}
		else if(leader==1 || leader==2 || leader == 3 || leader==5 || leader==3 || leader==6 || leader==7 || leader==11 || leader==13)
		{
			return 1;
		}
 	}
	return 0;
}
Filterscript:
Код:
stock IsMember(playerid)
{
    return CallRemoteFunction("IsACop", "i", playerid);
}

CheckPlayerSpeeding(playerid)
{
	// Check if the player hasn't been caught speeding recently
	if (APlayerData[playerid][PlayerCaughtSpeeding] == 0)
	{
	    if (!IsMember(playerid))
                 {
			// Loop through all speedcameras
			for (new CamID; CamID < MAX_CAMERAS; CamID++)
			{
			    // Check if this camera has been created
			    if (ACameras[CamID][CamSpeed] != 0)
			    {
					// Check if the player is the driver of the vehicle
					if (GetPlayerVehicleSeat(playerid) == 0)
					{
						// Check if the player's speed is greater than the speed allowed by this camera (no need to process a distance-check if not speeding)
						if (APlayerData[playerid][PlayerSpeed] > ACameras[CamID][CamSpeed])
						{
							// Check if the player is near the camera
							if (IsPlayerInRangeOfPoint(playerid, 20.0, ACameras[CamID][CamX], ACameras[CamID][CamY], ACameras[CamID][CamZ]))
							{
								APlayerData[playerid][PlayerCaughtSpeeding] = 20;
								SendClientMessage(playerid, COLOR_LIGHTBLUE, "* Speed Cam has given you a ticket costing $2500, reason: High Speed");
								GivePlayerCash(playerid, -2500);
							}
						}
					}
			    }
			}
		}
	}
	else // If the player has been caught before, reduce the value until it's 0 again, then he can be caught again
	    APlayerData[playerid][PlayerCaughtSpeeding]--;
 	return 1;
}
The problem is that cops and regular players are getting tickets..

help..
Reply
#2

CallRemoteFunction will return always 1 if it execute success.
Just replace
Quote:

if (!IsMember(playerid))

with
Quote:

if(!IsACop(playerid)

Reply
#3

Quote:
Originally Posted by KubiPL
Посмотреть сообщение
CallRemoteFunction will return always 1 if it execute success.
Just replace

with
Its still doesn't work..

I had to change the stock name too because if I would not change it, it says undefined symbol...

Updated script:

pawn Код:
stock IsACop(playerid)
{
    return CallRemoteFunction("IsACop", "i", playerid);
}

CheckPlayerSpeeding(playerid)
{
    // Check if the player hasn't been caught speeding recently
    if (APlayerData[playerid][PlayerCaughtSpeeding] == 0)
    {
        if (!IsACop(playerid))
            {
            // Loop through all speedcameras
            for (new CamID; CamID < MAX_CAMERAS; CamID++)
            {
                // Check if this camera has been created
                if (ACameras[CamID][CamSpeed] != 0)
                {
                    // Check if the player is the driver of the vehicle
                    if (GetPlayerVehicleSeat(playerid) == 0)
                    {
                        // Check if the player's speed is greater than the speed allowed by this camera (no need to process a distance-check if not speeding)
                        if (APlayerData[playerid][PlayerSpeed] > ACameras[CamID][CamSpeed])
                        {
                            // Check if the player is near the camera
                            if (IsPlayerInRangeOfPoint(playerid, 20.0, ACameras[CamID][CamX], ACameras[CamID][CamY], ACameras[CamID][CamZ]))
                            {
                                APlayerData[playerid][PlayerCaughtSpeeding] = 20;
                                SendClientMessage(playerid, COLOR_LIGHTBLUE, "* Speed Cam has given you a ticket costing $2500, reason: High Speed");
                                GivePlayerCash(playerid, -2500);
                            }
                        }
                    }
                }
            }
        }
    }
    else // If the player has been caught before, reduce the value until it's 0 again, then he can be caught again
        APlayerData[playerid][PlayerCaughtSpeeding]--;
    return 1;
}
Reply
#4

There is any way to check if function returens true or false?
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
"CallRemoteFunction" and use "public" not "stock" (why were you using "stock" in the first place?)
Its not working with public too..
I used stock in the first place because I used it in another filterscript and it worked (And public didn't)...
Reply
#6

pawn Код:
public IsACop(playerid)
{
    if(!IsPlayerConnected(playerid)) return 0;
    switch(PlayerInfo[playerid][pLeader])
        case 1 .. 3, 5 .. 7, 11, 13: return 1;
    switch(PlayerInfo[playerid][pMember])
        case 1 .. 3, 5 .. 7, 11, 13: return 1;
    return 0;
}
pawn Код:
CheckPlayerSpeeding(playerid)
{
    // Check if the player hasn't been caught speeding recently
    if(APlayerData[playerid][PlayerCaughtSpeeding]) return APlayerData[playerid][PlayerCaughtSpeeding]--;
    if(IsACop(playerid)) return 1;
    // Loop through all speedcameras
    for(new CamID = 0; CamID < MAX_CAMERAS; CamID++)
    {
        // Check if this camera has been created
        if(ACameras[CamID][CamSpeed] != 0)
        {
            // Check if the player is the driver of the vehicle
            if(GetPlayerVehicleSeat(playerid) == 0)
            {
                // Check if the player's speed is greater than the speed allowed by this camera (no need to process a distance-check if not speeding)
                if(APlayerData[playerid][PlayerSpeed] > ACameras[CamID][CamSpeed])
                {
                    // Check if the player is near the camera
                    if(IsPlayerInRangeOfPoint(playerid, 20.0, ACameras[CamID][CamX], ACameras[CamID][CamY], ACameras[CamID][CamZ]))
                    {
                        APlayerData[playerid][PlayerCaughtSpeeding] = 20;
                        SendClientMessage(playerid, COLOR_LIGHTBLUE, "* Speed Cam has given you a ticket costing $2500, reason: High Speed");
                        GivePlayerCash(playerid, -2500);
                        break;
                    }
                }
            }
        }
    }
    return 1;
}
Fingers crossed.
Reply
#7

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
pawn Код:
public IsACop(playerid)
{
    if(!IsPlayerConnected(playerid)) return 0;
    switch(PlayerInfo[playerid][pLeader])
        case 1 .. 3, 5 .. 7, 11, 13: return 1;
    switch(PlayerInfo[playerid][pMember])
        case 1 .. 3, 5 .. 7, 11, 13: return 1;
    return 0;
}
pawn Код:
CheckPlayerSpeeding(playerid)
{
    // Check if the player hasn't been caught speeding recently
    if(APlayerData[playerid][PlayerCaughtSpeeding]) return APlayerData[playerid][PlayerCaughtSpeeding]--;
    if(IsACop(playerid)) return 1;
    // Loop through all speedcameras
    for(new CamID = 0; CamID < MAX_CAMERAS; CamID++)
    {
        // Check if this camera has been created
        if(ACameras[CamID][CamSpeed] != 0)
        {
            // Check if the player is the driver of the vehicle
            if(GetPlayerVehicleSeat(playerid) == 0)
            {
                // Check if the player's speed is greater than the speed allowed by this camera (no need to process a distance-check if not speeding)
                if(APlayerData[playerid][PlayerSpeed] > ACameras[CamID][CamSpeed])
                {
                    // Check if the player is near the camera
                    if(IsPlayerInRangeOfPoint(playerid, 20.0, ACameras[CamID][CamX], ACameras[CamID][CamY], ACameras[CamID][CamZ]))
                    {
                        APlayerData[playerid][PlayerCaughtSpeeding] = 20;
                        SendClientMessage(playerid, COLOR_LIGHTBLUE, "* Speed Cam has given you a ticket costing $2500, reason: High Speed");
                        GivePlayerCash(playerid, -2500);
                        break;
                    }
                }
            }
        }
    }
    return 1;
}
Fingers crossed.
Код:
D:\Alwil Software\Vas-Rps\gamemodes\VasRpV0.30Beta.pwn(6134) : error 001: expected token: "{", but found "case"
D:\Alwil Software\Vas-Rps\gamemodes\VasRpV0.30Beta.pwn(6135) : error 002: only a single statement (or expression) can follow each "case"
D:\Alwil Software\Vas-Rps\gamemodes\VasRpV0.30Beta.pwn(6135 -- 6136) : warning 215: expression has no effect
D:\Alwil Software\Vas-Rps\gamemodes\VasRpV0.30Beta.pwn(6136) : error 001: expected token: ";", but found "case"
D:\Alwil Software\Vas-Rps\gamemodes\VasRpV0.30Beta.pwn(6136) : error 014: invalid statement; not in switch
D:\Alwil Software\Vas-Rps\gamemodes\VasRpV0.30Beta.pwn(6136) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
Reply
#8

True... why did I do that :l

pawn Код:
public IsACop(playerid)
{
    if(!IsPlayerConnected(playerid)) return 0;
    switch(PlayerInfo[playerid][pLeader])
    {
        case 1 .. 3, 5 .. 7, 11, 13: return 1;
    }
    switch(PlayerInfo[playerid][pMember])
    {
        case 1 .. 3, 5 .. 7, 11, 13: return 1;
    }
    return 0;
}
Reply
#9

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
True... why did I do that :l

pawn Код:
public IsACop(playerid)
{
    if(!IsPlayerConnected(playerid)) return 0;
    switch(PlayerInfo[playerid][pLeader])
    {
        case 1 .. 3, 5 .. 7, 11, 13: return 1;
    }
    switch(PlayerInfo[playerid][pMember])
    {
        case 1 .. 3, 5 .. 7, 11, 13: return 1;
    }
    return 0;
}
No script errors, but still everyone can get tickets...

Quote:
Originally Posted by ******
Посмотреть сообщение
That's not a reason to use "stock", in fact that's a very good reason NOT to use "stock"!
I have this warning when I don't use stock:
Код:
D:\Alwil Software\Vas-Rps\filterscripts\F_SpeedoMeter.pwn(28) : warning 235: public function lacks forward declaration (symbol "IsACop"
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
That's not a reason to use "stock", in fact that's a very good reason NOT to use "stock"!
I think I know why people might like to do that, it makes it easier to find your function when you search but is that a good reason to use it probably not.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)