Checkpoint only updating for ID 0
#1

Title says it.

My checkpoint only updates for the person with ID 0.
The checkpoint shows for ID 1 - ID x but it doesn't update with the new location of the PD member.
It only updates for ID 0.

Command:
pawn Код:
if(strcmp(cmdtext, "/bku", true) == 0)
        {
            if(IsACop(playerid))
            {
                new string[256];
                if(backuprequester[playerid] == 1) return SendClientMessage(playerid, COLOR_GREY, "You've requested backup already! (/bkc to cancel)");
                if(backuprequested == 1) return SendClientMessage(playerid, COLOR_GREY, "Someone else request backup already!");
                SendClientMessage(playerid, COLOR_GREY, "Type in /bkc to cancel the backup");
                new Float:x, Float:y, Float:z;
                GetPlayerPos(playerid, x,y,z);
                backuprequested = 1;
                backuprequester[playerid] = 1;
                for (new i = 0; i < MAX_PLAYERS; i++)
                {
                    if(IsPlayerConnected(playerid))
                    {
                        if(IsACop(playerid))
                        {
                            new location[MAX_ZONE_NAME];
                            GetPlayer2DZone(playerid, location, MAX_ZONE_NAME);
                            format(string, sizeof(string), "* Dispatch: %s[%d] is in need of backup! Location at (%s)",GetPlayerNameEx(playerid),playerid, location);
                            SendClientMessage(i, COLOR_LIGHTBLUE, string);
                            SetPlayerCheckpoint(i, x, y, z, 5);
                            backuptimer[i] = SetTimerEx("updatebackup", 1000, true, "i", playerid);
                        }
                    }
                }
                return 1;
            }
        }
    if(strcmp(cmdtext, "/bkc", true) == 0)
        {
            if(IsACop(playerid))
            {
                new string[256];
                if(backuprequester[playerid] == 0) return SendClientMessage(playerid, COLOR_GREY, "You've not requested any backup!");
                backuprequested = 0;
                backuprequester[playerid] = 0;
                for (new i = 0; i < MAX_PLAYERS; i++)
                {
                    if(IsPlayerConnected(playerid))
                    {
                        if(IsACop(playerid))
                        {
                        format(string, sizeof(string), "* Dispatch: %s[%d] has canceled his backup", GetPlayerNameEx(playerid),playerid);
                        SendClientMessage(i, COLOR_LIGHTBLUE, string);
                        KillTimer(backuptimer[i]);
                        DisablePlayerCheckpoint(i);
                        }
                    }
                }
                return 1;
            }
        }
Timer:
pawn Код:
forward updatebackup(playerid);
public updatebackup(playerid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x,y,z);
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
            DisablePlayerCheckpoint(i);
            SetPlayerCheckpoint(i, x, y, z, 5);
            return 1;
    }
    return 1;
}
Help is much appreciated.
Reply
#2

pawn Код:
forward updatebackup(playerid);
public updatebackup(playerid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x,y,z);
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
            DisablePlayerCheckpoint(i);
            SetPlayerCheckpoint(i, x, y, z, 5);
    }
    return 1;
}
You returned 1 before the loop could finish, therefore allowing it to only run once! first id = 0, sets to that only.

Have fun!
Reply
#3

Thank you Dokins
Now, I want that the backup call is cancelled when the officer dies and when the officer disconnects from the server.
So I made this:

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(backuprequester[playerid] == 1)
    {
            new string[128];
            backuprequested = 0;
            KillTimer(backuptimer[playerid]);
            for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsACop(i))
                {
                    format(string, sizeof(string), "* Dispatch: %s[%d] has canceled his backup call ((Officer died))", GetPlayerNameEx(playerid),playerid);
                    SendClientMessage(i, COLOR_LIGHTBLUE, string)
                    DisablePlayerCheckpoint(i);
                }
            }
    }
    return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
    backuprequester[playerid] = 0;
    return 1;
}

public OnPlayerDisconnect(playerid)
{
    if(backuprequester[playerid] == 1)
    {
            new string[128];
            backuprequested = 0;
            KillTimer(backuptimer[playerid]);
            for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsACop(i))
                {
                    format(string, sizeof(string), "* [Dispatch] code 4, %s[%d] has canceled his backup call ((Leaving server))", GetPlayerNameEx(playerid),playerid);
                    SendClientMessage(i, COLOR_LIGHTBLUE, string);
                    DisablePlayerCheckpoint(i);
                }
            }
    }
    return 1;
}
It broadcasts the string but it does not kill the timer nor disables the checkpoint.

Can you help me?
Reply
#4

Can you show me the timer please?
Reply
#5

This should do


pawn Код:
new backuprequested;
new backuprequester[MAX_PLAYERS];
new backuptimer[MAX_PLAYERS];
pawn Код:
forward updatebackup(playerid);
public updatebackup(playerid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x,y,z);
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
            DisablePlayerCheckpoint(i);
            SetPlayerCheckpoint(i, x, y, z, 5);
    }
    return 1;
}
Reply
#6

Try this!

pawn Код:
public OnPlayerDisconnect(playerid)
{
    if(backuprequester[playerid] == 1)
    {
            new string[128];
            for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsACop(i))
                {
                    format(string, sizeof(string), "* [Dispatch] code 4, %s[%d] has canceled his backup call ((Leaving server))", GetPlayerNameEx(playerid),playerid);
                    SendClientMessage(i, COLOR_LIGHTBLUE, string);
                    DisablePlayerCheckpoint(i);
                }
            }
            backuprequested = 0;
            KillTimer(backuptimer[playerid]);
            backuprequester[playerid] = 0;
           
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(backuprequester[playerid] == 1)
    {
            new string[128];
            for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsACop(i))
                {
                    format(string, sizeof(string), "* Dispatch: %s[%d] has canceled his backup call ((Officer died))", GetPlayerNameEx(playerid),playerid);
                    SendClientMessage(i, COLOR_LIGHTBLUE, string)
                    DisablePlayerCheckpoint(i);
                }
            }
            backuprequested = 0;
            KillTimer(backuptimer[playerid]);
            backuprequester[playerid] = 0;
    }
    return 1;
}
Reply
#7

It works but the timer doesn't get killed and the checkpoint isn't disabled.

backuprequested = 0; works perfectly!
Reply
#8

What is the define for this:

pawn Код:
backuptimer[playerid] == SetTimer...
Reply
#9

You mean this?

pawn Код:
new backuptimer[MAX_PLAYERS];
Reply
#10

Where are you assigning that variable to a timer?

As in backuptimer[playerid] =

It can't kill the checkpoints because the timer isn't destroyed, so I'm sure it's to do with that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)