30.10.2014, 11:50
Hello!
I made myself a new timer that loops through all players, something similiar as the OnPlayerUpdate; but this one is called every 1 second in my script.
But, my question is, i need to check if someone is wanted, and afterwards assign a variable giving me their playerid in the code further down.
i did it with the variable wantedid and ticketid to save their id's for later use.
But; this fails, and it seems like it's only the ID=0 who gets affected.
Can someone help me to recognize a wanted player in my code, when a cop is getting close to the wanted player? I am a bit stuck here :/
Any explanation or further ideas will be very welcomed!
Thanks alot
I made myself a new timer that loops through all players, something similiar as the OnPlayerUpdate; but this one is called every 1 second in my script.
But, my question is, i need to check if someone is wanted, and afterwards assign a variable giving me their playerid in the code further down.
i did it with the variable wantedid and ticketid to save their id's for later use.
But; this fails, and it seems like it's only the ID=0 who gets affected.
Can someone help me to recognize a wanted player in my code, when a cop is getting close to the wanted player? I am a bit stuck here :/
pawn Код:
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;
}
Thanks alot
![Smiley](images/smilies/smile.png)