PDA

View Full Version : Remote function


morha12
17/05/2014, 06:47 AM
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..

KubiPL
17/05/2014, 07:53 AM
CallRemoteFunction will return always 1 if it execute success.
Just replace
if (!IsMember(playerid))
with
if(!IsACop(playerid)

morha12
17/05/2014, 08:08 AM
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:

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;
}

morha12
17/05/2014, 08:51 AM
There is any way to check if function returens true or false?

morha12
17/05/2014, 09:14 AM
"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)...

Threshold
17/05/2014, 09:31 AM
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;
}

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.

morha12
17/05/2014, 09:46 AM
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;
}

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 (c) 1997-2006, ITB CompuPhase


5 Errors.

Threshold
17/05/2014, 09:49 AM
True... why did I do that :l

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;
}

morha12
17/05/2014, 09:53 AM
True... why did I do that :l

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...

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"

Threshold
17/05/2014, 10:05 AM
forward IsACop(playerid);

Make sure that is ABOVE the public IsACop(playerid) line.

morha12
17/05/2014, 12:53 PM
forward IsACop(playerid);

Make sure that is ABOVE the public IsACop(playerid) line.


Its working thank you!

Pottus
17/05/2014, 01:11 PM
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.