This cmd crashes pawno
#1

Hello,i've done this command:

pawn Код:
dcmd_rob(playerid,params[])
{
    if((GetTickCount() - robtime[MAX_PLAYERS]) < 120000)) return SendClientMessage(playerid,color,"You have to wait.");
    if(IsPlayerInRangeOfPoint(playerid, RANGE, COORDINATES))
    {
    new string[120], playerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
    robtime[MAX_PLAYERS] = GetTickCount();
    format(string, sizeof(string), "%s Is Robbing .....etc", playerName);
    SendClientMessageToAll(0xFFFFFFFF, string);
    SetPlayerWantedLevel(playerid, 6);
    GivePlayerMoney(playerid, 10000);
    #pragma unused params
    }
    return 1;
}
The new;

pawn Код:
new robtime[MAX_PLAYERS];
But it crashes pawno when compling,wtf?
Reply
#2

This:
Код:
robtime[MAX_PLAYERS] = GetTickCount();
Should be:
Код:
robtime[playerid] = GetTickCount();
And this:
Код:
if((GetTickCount() - robtime[MAX_PLAYERS]) < 120000)) return SendClientMessage(playerid,color,"You have to wait.");
Needs attention too.
Reply
#3

Quote:
Originally Posted by Stigg
Посмотреть сообщение
This:
Код:
robtime[MAX_PLAYERS] = GetTickCount();
Should be:
Код:
robtime[playerid] = GetTickCount();
And this:
Код:
if((GetTickCount() - robtime[MAX_PLAYERS]) < 120000)) return SendClientMessage(playerid,color,"You have to wait.");
Needs attention too.
Код:
if((GetTickCount() - robtime[playerid]) < 120000)) return SendClientMessage(playerid,color,"You have to wait.");
Reply
#4

pawn Код:
dcmd_rob(playerid,params[])
{
    #pragma unused params
    if((GetTickCount() - robtime[MAX_PLAYERS]) < 120000)) return SendClientMessage(playerid,color,"You have to wait.");
    if(IsPlayerInRangeOfPoint(playerid, RANGE, COORDINATES))
    {
    new string[120], playerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
    robtime[MAX_PLAYERS] = GetTickCount();
    format(string, sizeof(string), "%s Is Robbing .....etc", playerName);
    SendClientMessageToAll(0xFFFFFFFF, string);
    SetPlayerWantedLevel(playerid, 6);
    GivePlayerMoney(playerid, 10000);
    }
    return 1;
}

#pragma unused params NEVER EVER EVER EVER goes beneath dcmd.... EVER!
Reply
#5

pawn Код:
new Variable[500]
...creates an array starting at cell [0] upto [499], thats 500 together.
if you use [MAX_PLAYERS] in any loop, it ill be an "out of bounds" error. your simple mistake was the playerid instead of MAX_PLAYERS:
pawn Код:
dcmd_rob(playerid,params[])
{
    if((GetTickCount() - robtime[playerid]) < 120000)) return SendClientMessage(playerid,0xff0000ff,"You have to wait.");
    if(IsPlayerInRangeOfPoint(playerid, 10.0000, 0.0000,0.0000,0.0000))
    {
        new string[120], playerName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
        robtime[playerid] = GetTickCount();
        format(string, sizeof(string), "%s Is Robbing .....etc", playerName);
        SendClientMessageToAll(0xFFFFFFFF, string);
        SetPlayerWantedLevel(playerid, 6);
        GivePlayerMoney(playerid, 10000);
    }
    return 1;
}
btw: let a player start to rob, then /q, then let another player connect on the same id, and let him try to rob again. the robtime[playerid] gets reset at OnPlayerDisconnect?
oh, and where are the coodrinates and the radius for
Код:
if(IsPlayerInRangeOfPoint(playerid, RANGE, COORDINATES))
? its at blueberry acres now hehe
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)