public OnPlayerUpdate2()
{
new ticketid = -1, wantedid = -1;
foreach(new i : Player)
{
if(GetPlayerWantedLevel(i) == 1) //how to save the players into variables correctly, for use further down?
ticketid = i;
if(GetPlayerWantedLevel(i) > 1) //same here; i'm doing it the wrong way i think :S
wantedid = i;
if(ticketid != -1)
{
if(GetPVarInt(i, "copduty") == 1)
{
if(IsPlayerInAnyVehicle(i) || IsPlayerInAnyVehicle(ticketid))
{
if (GetPlayerVehicleID(i) != GetPlayerVehicleID(ticketid) || !IsPlayerInAnyVehicle(i) || !IsPlayerInAnyVehicle(ticketid))
{
continue;
}
}
else if(PlayerToPlayer(i, ticketid, 4) && GetPVarInt(ticketid, "afk") == 0 && tDialogOpen[ticketid] == 0 )
{
if(checktime == 0)
checktime = gettime();
GameTextForPlayer(i, "~r~Giving ticket...", 1000, 1);
if(gettime() - checktime >= 3)
{
GameTextForPlayer(i, "~g~Ticket given, please wait...", 3000, 1);
TogglePlayerControllable(ticketid, 0);
ShowPlayerDialog(ticketid,ticketdialog,DIALOG_STYLE_MSGBOX,""cwhite"Pay Ticket: "cgreen"Yes "cwhite"or"cred" No?", ""cwhite"You have wanted level 1, and a cop just busted you.\nAre you willing to pay the ticket?\n"cgreen"PRICE:"cwhite" 10 000$ / 5 cookies / 5 score", "Yes", "No");
tDialogOpen[ticketid] = 1;
cop[i][tickets] ++;
checktime = 0;
}
}
}
}
if(wantedid != -1)
{
if(GetPVarInt(i, "copduty") == 1)
{
if(IsPlayerInAnyVehicle(i) && IsPlayerInAnyVehicle(wantedid))
{
if (GetPlayerVehicleID(i) != GetPlayerVehicleID(wantedid) || !IsPlayerInAnyVehicle(i) || !IsPlayerInAnyVehicle(wantedid))
{
continue;
}
}
else if(PlayerToPlayer(i, wantedid, 2) && GetPVarInt(wantedid, "afk") != 1&& AlreadyWanted[wantedid] == 0)
{
if(checktime == 0)
checktime = gettime() &&
GameTextForPlayer(i, "~r~Arresting...", 1000, 1);
if(gettime() - checktime >= 4)
{
AlreadyWanted[wantedid] = 1; //to prevent it to be called many times
GameTextForPlayer(i, "~g~Arrested player, jailing...", 4000, 1);
TogglePlayerControllable(wantedid, 0);
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(wantedid,x,y,z);
GetPlayerFacingAngle(wantedid, a);
SetPVarFloat(wantedid, "Xpos", x);
SetPVarFloat(wantedid, "Ypos", y);
SetPVarFloat(wantedid, "Zpos", z);
SetPVarFloat(wantedid, "Apos", a);
SetPVarInt(wantedid, "int", GetPlayerInterior(wantedid));
SetPVarInt(wantedid, "world", GetPlayerVirtualWorld(wantedid));
ApplyAnimation(wantedid, "PED", "handsup", 4, 0 , 0, 0, 1, 5000);
SetPVarInt(wantedid, "Jailed", 1);
ResetPlayerWeapons(wantedid);
SetPVarInt(wantedid, "arrested", 1); //for the function call, to define if its /ar or /jail which is used.
new cash;
cash = random (10000);
new msg[180];
format(msg, sizeof(msg),"You jailed "cpurple"%s"cwhite" for "cpurple"%d"cwhite" minutes. You earned "cpurple"$%d"cwhite", good job officer!", PlayerName(wantedid), GetPlayerWantedLevel(wantedid), cash);
GivePlayerMoney(i, cash);
SendClientMessage(i, -1, msg);
format(msg, sizeof(msg),"Info: "cwhite"You got arrested by "cpurple"%s %s"cwhite" for "cpurple"%d"cwhite" minutes", CopRank(i), PlayerName(i), GetPlayerWantedLevel(wantedid));
SendClientMessage(wantedid, purple, msg);
SetTimerEx("putinjail",4000,false,"i",wantedid);
cop[i][arrests] ++ ;
checktime = 0;
}
}
}
}
}
return 1;
}
new wantedid[MAX_PLAYERS],ticketid[MAX_PLAYERS] // declare this on top of your script not inside your public OnPlayerUpdate2() (remove the variable wantedid and the ticketid cuz u already have a gloval var wantedid[MAX_PLAYERS] and ticketid[MAX_PLAYERS]
// and reset it everytime player disconnects
public OnPlayerDisconnect(playerid, reason)
{
wantedid[playerid]=0;
ticketid[playerid]=0;
}
change it to :
pawn Код:
|
if(GetPlayerWantedLevel(i) > 1)
wantedid[i]= i;
if(GetPlayerWantedLevel(i) > 1)
wantedid[i]= 1;
if(IsPlayerInAnyVehicle(ticketid[i]))
if(GetPlayerWantedLevel(i) > 1)
wantedid[i]= 1;// change it to wantedid[i]=GetPlayerWantedLevel(i); so you will configure his actual wanted level and store to his player variable wantedid[playerid]
// ur looping to connected players foreach(new i:Player) and does the "i" signifies the id of the
// current looped player so wantedid[i] is a clever move
//
//the isplayerinvehicle thing
// change it to
if(IsPlayerInAnyVehicle(i)) // as i just have said,,.. the "i" signifies the id of the current plyer looped
// im sorry cuz i just barely read your code and cant understand the rest 3/4 of it
// what does the ticketid and wantedid?
//it should be
if(ticketid == -1) // this checks if the player is a cop right ??? ive notice u write if(ticketid != -1)
if(wantedid==-1)// this one too???
//BTW i can provide you a better code instead of your onplayerupdate like timer
// make a command for cop player so he can ticket or arrest the wanted player
// like /ticket and /arrest
CMD:arrest(playerid,params[])
{
new targetid,msg1[128],msg2[128];
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
if(iscop[playerid]!=1) // checks if the player enter this command is a cop then if its not he cant use this command
{
return SendClientMessage(playerid,-1,"only cops can use this command");
}
if(isnull(params) // if the cop just enter "/arrest"
{
foreach(new i:Player) // looping throuh all players
{
if(i==playerid)continue; // if loops reached the cops id then we'll skip
if(IsPlayerInRangeOfPoint(i, 7.0, X, Y, Z)&&GetPlayerWantedLevel(i)) // checking if there is wanted player nearby
{
// ur command to arrest the player
SendClientMessage(i,-1,"arrested for being wanted");
return SendClientMessage(playerid,-1,"you have arrested a wanted player); // stopping the loop if we found the wantedplayer
}
}
return SendClientMessage(playerid,-1,"no wanted player nearby");// prints to the client if we cant find a wanted player nearby
}
// gets though here if the player type /arrest <id/name>
if(sscanf(params,"u",targetid)) // checks if the player enter a valid syntax
{
return SendClientMessage(playerid,-1,"Syntax: /arrest <id/name>");
}
if(targetid==INVALID_PLAYER_ID) // checks if the player enters the invalid targetid eg.yourself and offline player
{
return SendClientMessage(playerid,-1,"player not found");
}
if(IsPlayerInRangeOfPoint(targetid, 7.0, X, Y, Z)&&GetPlayerWantedLevel(playerid)) // checks if the player is wanted and is if the player nearby
{
// ur command to arrest the player
SendClientMessage(i,-1,"arrested for being wanted");
return SendClientMessage(playerid,-1,"you have arrested a wanted player);
}
else
{
return SendClientMessage(playerid,-1,"player must be near");
}
return 1;
}
// i hope this will help you
// goodluck
i agree with this
pawn Код:
|
// what does the ticketid and wantedid?
//it should be
if(ticketid == -1) // this checks if the player is a cop right ??? ive notice u write if(ticketid != -1)
if(wantedid==-1)// this one too???
if(ticketid[i]) == 1 //did get the variable assigned as he was wanted with 1 wanted level.
else if(PlayerToPlayer(i, ticketid, 4)