Help with break lock timing system
#1

I've been working on a house system, and I've made it so the lock on a house door can be broken. Now, at the default locklevel of 1 (the weakest lock level without the lock being broken) the breaking procedure should take between 35000 to 55000ms, or 35 to 55 seconds, but for some reason it only takes around 5 seconds to break the lock.

Here is my code (the /breaklock command and the function):
http://pastebin.com/fXcpnQNA

And here is my debug log:
Quote:

[10:30:45] i: 999, time: 3035, timeremaining: -996
[10:30:45] i: 1999, time: 3035, timeremaining: -1996
[10:30:45] i: 2999, time: 3035, timeremaining: -2996
[10:30:45] i: 3999, time: 3035, timeremaining: -3996

I hope someone can help me.
Reply
#2

The mistake is in there

pawn Код:
lockBreakTime = HD[h][locklevel] * 35 + random(20) * 1000;
Shouldnt be hard to notice that the value range is [35; 19035]

Than you call BreakHouseLock after lockBreakTime (should be each second for a countdown)

But the main problem is in BreakHouseLock itself (no clue what that code should do)
Reply
#3

Try this

pawn Код:
command(breaklock, playerid, params[])
{
    new lockBreakTime;
    for(new h; h < MAX_HOUSES; h++) {
        if(IsPlayerInRangeOfPoint(playerid, 3.5, HD[h][exteriorX], HD[h][exteriorY], HD[h][exteriorZ])) {
            if(HD[h][locklevel] == 0) return SendClientMessage(playerid, COLOR_WHITE, "This house doesn't have a lock!");
            lockBreakTime = HD[h][locklevel] * 35 + random(20);
            TogglePlayerControllable(playerid, 0);
            SetTimerEx("BreakHouseLock", 1000, false, "did", h, playerid, lockBreakTime);
        }
        if(IsPlayerInRangeOfPoint(playerid, 3.5, HD[h][interiorX], HD[h][interiorY], HD[h][interiorZ]) && GetPlayerInterior(playerid) == HD[h][interiorInt]) {
            if(GetPlayerVirtualWorld(playerid) == h) {
                if(HD[h][locklevel] == 0) return SendClientMessage(playerid, COLOR_WHITE, "This house doesn't have a lock!");
                lockBreakTime = HD[h][locklevel] * 40 + random(20);
                TogglePlayerControllable(playerid, 0);
                SetTimerEx("BreakHouseLock", 1000, false, "did", h, playerid, lockBreakTime);
            }
        }
    }
    return 1;
}
pawn Код:
public BreakHouseLock(houseid, playerid, time)
{
    time--;
    if(time == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "You broke the lock on the house!");
        HD[houseid][locked] = 0;
        HD[houseid][locklevel] = 0;
        TogglePlayerControllable(playerid, 1);
    }
    else
    {
        new string[128];
        format(string, sizeof(string), "Breaking Lock~n~%d seconds remaining", time);
        GameTextForPlayer(playerid, string, 900, 1);
        SetTimerEx("BreakHouseLock", 1000, false, "did", houseid, playerid, time);
    }
}
Reply
#4

It works, apart from the textdraw stays there for 8 seconds - it went from 41 seconds to 33 seconds when it should have been destroyed after 900ms.
Reply
#5

Bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)