SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 09/04/2020, 11:42 PM   #1
RemaLegend
Little Clucker
 
Join Date: Jul 2017
Posts: 6
Reputation: 0
Post [debug] #0 006be168 in public OtherTimer

Hello,
I have a problem in timers as i see [debug] messages in my server console.
pawn Code:
[debug] Run time error 3: "Stack/heap collision (insufficient stack size)"
[debug]  Stack pointer (STK) is 0x1BD9054, heap pointer (HEA) is 0x1BD91E4
[debug] AMX backtrace:
[debug] #0 006be168 in public OtherTimer () at modules/timers.pwn:910
in script 910
pawn Code:
public OtherTimer()
{
    new string[128];
    foreach(new i:Player)
    {
        if(pLoggedIn[i] == 1)
        {
            if(PlayerAnimTime[i] != 0)
            {
                PlayerAnimTime[i]++;
                if(PlayerAnimTime[i] > 180 && !IsPlayerBlocked(i) && !IsPlayerInAnyVehicle(i))
                {
                    SendClientMessage(i,COLOR_GREY,"[SERVER] Animacija automatski prekinuta");
                    PlayerAnimTime[i] = 0;
                    PlayerAnim[i] = 0;
                    ClearAnimations(i);
                }
            }
            //resetovanje pickupa
            if(MenuPickup[i] > 0)
            {
                MenuPickup[i]--;
            }
            //mjenjaj port status
            if(pPortBlock[i] != 0)
            {
                pPortBlock[i]--;
                if(pPortBlock[i] <= 0)
                {
                    pPortBlock[i] = 0;
                    if(!IsPlayerFreezed(i) && !IsPlayerBlocked(i) && !IsPlayerDruged(i)) TogglePlayerControllable(i,true);
                }
            }
            //ostalo
            new Float:Hp[MAX_PLAYERS],Float:Px[MAX_PLAYERS],Float:Py[MAX_PLAYERS],Float:Pz[MAX_PLAYERS];
            SafeGetPlayerHealth(i,Hp[i]);
            GetPlayerPos(i,Px[i],Py[i],Pz[i]);
            if(Hp[i] >= 1 && Hp[i] <= 10)
            {
                if(IsPlayerInDmEvent(i) == 0)
                {
                    if(HpSetPos[i] == 0) SafeSetPlayerPos(i,Px[i],Py[i],Pz[i]);
                    ApplyAnimation(i,"CRACK","crckdeth2",3,1,0,0,1,500,1);
                    HpOnGround[i] = 1;
                    SetPlayerArmedWeapon(i,0);
                }
            }
            else HpOnGround[i] = 0;
           
           
            if(RingTone[i] != 0)//ZVONI
            {
                if(RingTone[i] == 15 || RingTone[i] == 9 || RingTone[i] == 3)
                {
                    SendClientMessage(i,COLOR_YELLOW,"Zvoni vam telefon, kucajte (/pickup)");
                }
                RingTone[i] -= 1;
                if(RingTone[i] == 0)
                {
                    if(Mobile[i] != INVALID_PLAYER_ID)
                    {
                        TextDrawShowForPlayer(Mobile[i],IconPhone);
                        TextDrawHideForPlayer(Mobile[i],IconPhonePickup);
                        TextDrawHideForPlayer(Mobile[i],IconPhoneHangup);
                        CellTime[Mobile[i]] = 0;
                        IsTalkingOnMobile[Mobile[i]] = 0;
                        SendClientMessage(Mobile[i],COLOR_GRAD2,"Ne javlja se.");
                        if(GetPlayerSpecialAction(Mobile[i]) == SPECIAL_ACTION_USECELLPHONE) SetPlayerSpecialAction(Mobile[i], SPECIAL_ACTION_NONE);
                        if(IsPlayerAttachedObjectSlotUsed(Mobile[i],7)) RemovePlayerAttachedObject(Mobile[i],7);
                        Mobile[Mobile[i]] = INVALID_PLAYER_ID;
                    }
                    SendClientMessage(i,COLOR_GRAD2,"Niste se javili.");
                    IsTalkingOnMobile[i] = 0;
                    Mobile[i] = INVALID_PLAYER_ID;
                    TextDrawShowForPlayer(i,IconPhone);
                    TextDrawHideForPlayer(i,IconPhonePickup);
                    TextDrawHideForPlayer(i,IconPhoneHangup);
                }
                if(RingTone[i] < 0) RingTone[i] = 0;
            }
            if(CellTime[i] > 0)
            {
                CallCost[i] = CallCost[i] + 1;
            }
            if(CellTime[i] == 0 && CallCost[i] > 0)
            {
                PlayerInfo[i][pPhoneBill] -= CallCost[i];
                CallCost[i] = 0;
            }
            if(Refueling[i][Time] != 0)
            {
                Refueling[i][Time]--;
                if(Refueling[i][Time] == 0)//Gorivo sipano
                {
                    if(IsPlayerNearPumpStation(i) == 0) return SendClientMessage(i,COLOR_GREY,"Niste u blizini pumpe!");
                    new VID = GetPlayerVehicleID(i);
                    if(IsAPdCar(VID) || IsAFbiCar(VID) || IsAnAmbulance(VID) || IsAGovernmentCar(VID) || IsANovinarCar(VID))
                    {
                        if(Refueling[i][Amount] + floatround(VehicleInfo[VID][vFuel]) > 102.0)
                        {
                            SendClientMessage(i,COLOR_GREY,"Trenutno imate vise goriva od izabrane kolicine!");
                            if(IsPlayerFreezed(i) == 0) TogglePlayerControllable(i,1);
                            Refueling[i][Time] = 0;
                            Refueling[i][Amount] = 0;
                            Refueling[i][Price] = 0;
                            return 1;
                        }
                        VehicleInfo[VID][vFuel] = VehicleInfo[VID][vFuel] + Refueling[i][Amount];
                        if(VehicleInfo[VID][vFuel] > 100.0) VehicleInfo[VID][vFuel] = 100.0;
                        Refueling[i][Time] = 0;
                        Refueling[i][Amount] = 0;
                        Refueling[i][Price] = 0;
                        if(IsPlayerFreezed(i) == 0) TogglePlayerControllable(i,1);
                        SendClientMessage(i,COLOR_YELLOW,"[Pumpa] Uprava je platila za gorivo.");
                    }
                    else
                    {
                        if(SafeGetPlayerMoney(i) >= Refueling[i][Price])
                        {
                            if(Refueling[i][Amount] + VehicleInfo[VID][vFuel] > 100.0)
                            {
                                SendClientMessage(i,COLOR_GREY,"Trenutno imate vise goriva od izabrane kolicine!");
                                if(IsPlayerFreezed(i) == 0) TogglePlayerControllable(i, 1);
                                Refueling[i][Time] = 0;
                                Refueling[i][Amount] = 0;
                                Refueling[i][Price] = 0;
                                return 1;
                            }
                            format(string,sizeof(string),"[Pumpa] Natocili ste gorivo, cena: $%d.",Refueling[i][Price]);
                            SendClientMessage(i,COLOR_YELLOW,string);
                            SafeGivePlayerMoney(i, -Refueling[i][Price]);
                            Log_Money(i,-Refueling[i][Price],"[cmd:refueling]");
                            VehicleInfo[VID][vFuel] = VehicleInfo[VID][vFuel] + Refueling[i][Amount]; //910
                            if(VehicleInfo[VID][vFuel] > 100.0) VehicleInfo[VID][vFuel] = 100.0;
                            if(IsPlayerFreezed(i) == 0) TogglePlayerControllable(i, 1);
                            Refueling[i][Time] = 0;
                            Refueling[i][Amount] = 0;
                            Refueling[i][Price] = 0;
                        }
                        else
                        {
                            format(string,sizeof(string),"* Nemate dovoljno novca za gorivo, racun je $%d .",Refueling[i][Price]);
                            SendClientMessage(i,COLOR_WHITE,string);
                            if(IsPlayerFreezed(i) == 0) TogglePlayerControllable(i, 1);
                            Refueling[i][Time] = 0;
                            Refueling[i][Amount] = 0;
                            Refueling[i][Price] = 0;
                        }
                    }
                    UpdatePlayerVehTD(i,true);
                }
            }
        }
    }
    return 1;
}
If anyone knows how to solve, thank him in advance.
I tried many ways but it didn't work ...
Debug was happens when a player refueling vehicle, and because of this debug, the fuel is not poured into the vehicle
RemaLegend is offline   Reply With Quote
Old 10/04/2020, 02:14 AM   #2
Jastak
Huge Clucker
 
Jastak's Avatar
 
Join Date: Jan 2015
Location: Esparta
Posts: 290
Reputation: 20
Default Re: [debug] #0 006be168 in public OtherTimer

The problem is that your stack is being overwritten by your head, and it causes this error (correct me if I'm wrong). So there can be two solutions, optimize your code which would be the right thing or change the maximum memory with #pragma

Option 1:
Maybe your problem is here
pawn Code:
new Float:Hp[MAX_PLAYERS],Float:Px[MAX_PLAYERS],Float:Py[MAX_PLAYERS],Float:Pz[MAX_PLAYERS];
I really don't understand why you did this.

Correct CODE:
pawn Code:
public OtherTimer()
{
    new string[128];
    foreach(new i:Player)
    {
        if(pLoggedIn[i] == 1)
        {
            if(PlayerAnimTime[i] != 0)
            {
                PlayerAnimTime[i]++;
                if(PlayerAnimTime[i] > 180 && !IsPlayerBlocked(i) && !IsPlayerInAnyVehicle(i))
                {
                    SendClientMessage(i,COLOR_GREY,"[SERVER] Animacija automatski prekinuta");
                    PlayerAnimTime[i] = 0;
                    PlayerAnim[i] = 0;
                    ClearAnimations(i);
                }
            }
            //resetovanje pickupa
            if(MenuPickup[i] > 0)
            {
                MenuPickup[i]--;
            }
            //mjenjaj port status
            if(pPortBlock[i] != 0)
            {
                pPortBlock[i]--;
                if(pPortBlock[i] <= 0)
                {
                    pPortBlock[i] = 0;
                    if(!IsPlayerFreezed(i) && !IsPlayerBlocked(i) && !IsPlayerDruged(i)) TogglePlayerControllable(i,true);
                }
            }
            //ostalo
            new Float:Hp,Float:Px,Float:Py,Float:Pz;
            SafeGetPlayerHealth(i,Hp);
            GetPlayerPos(i,Px,Py,Pz);
            if(Hp >= 1 && Hp <= 10)
            {
                if(IsPlayerInDmEvent(i) == 0)
                {
                    if(HpSetPos[i] == 0) SafeSetPlayerPos(i,Px,Py,Pz);
                    ApplyAnimation(i,"CRACK","crckdeth2",3,1,0,0,1,500,1);
                    HpOnGround[i] = 1;
                    SetPlayerArmedWeapon(i,0);
                }
            }
            else HpOnGround[i] = 0;
           
           
            if(RingTone[i] != 0)//ZVONI
            {
                if(RingTone[i] == 15 || RingTone[i] == 9 || RingTone[i] == 3)
                {
                    SendClientMessage(i,COLOR_YELLOW,"Zvoni vam telefon, kucajte (/pickup)");
                }
                RingTone[i] -= 1;
                if(RingTone[i] == 0)
                {
                    if(Mobile[i] != INVALID_PLAYER_ID)
                    {
                        TextDrawShowForPlayer(Mobile[i],IconPhone);
                        TextDrawHideForPlayer(Mobile[i],IconPhonePickup);
                        TextDrawHideForPlayer(Mobile[i],IconPhoneHangup);
                        CellTime[Mobile[i]] = 0;
                        IsTalkingOnMobile[Mobile[i]] = 0;
                        SendClientMessage(Mobile[i],COLOR_GRAD2,"Ne javlja se.");
                        if(GetPlayerSpecialAction(Mobile[i]) == SPECIAL_ACTION_USECELLPHONE) SetPlayerSpecialAction(Mobile[i], SPECIAL_ACTION_NONE);
                        if(IsPlayerAttachedObjectSlotUsed(Mobile[i],7)) RemovePlayerAttachedObject(Mobile[i],7);
                        Mobile[Mobile[i]] = INVALID_PLAYER_ID;
                    }
                    SendClientMessage(i,COLOR_GRAD2,"Niste se javili.");
                    IsTalkingOnMobile[i] = 0;
                    Mobile[i] = INVALID_PLAYER_ID;
                    TextDrawShowForPlayer(i,IconPhone);
                    TextDrawHideForPlayer(i,IconPhonePickup);
                    TextDrawHideForPlayer(i,IconPhoneHangup);
                }
                if(RingTone[i] < 0) RingTone[i] = 0;
            }
            if(CellTime[i] > 0)
            {
                CallCost[i] = CallCost[i] + 1;
            }
            if(CellTime[i] == 0 && CallCost[i] > 0)
            {
                PlayerInfo[i][pPhoneBill] -= CallCost[i];
                CallCost[i] = 0;
            }
            if(Refueling[i][Time] != 0)
            {
                Refueling[i][Time]--;
                if(Refueling[i][Time] == 0)//Gorivo sipano
                {
                    if(IsPlayerNearPumpStation(i) == 0) return SendClientMessage(i,COLOR_GREY,"Niste u blizini pumpe!");
                    new VID = GetPlayerVehicleID(i);
                    if(IsAPdCar(VID) || IsAFbiCar(VID) || IsAnAmbulance(VID) || IsAGovernmentCar(VID) || IsANovinarCar(VID))
                    {
                        if(Refueling[i][Amount] + floatround(VehicleInfo[VID][vFuel]) > 102.0)
                        {
                            SendClientMessage(i,COLOR_GREY,"Trenutno imate vise goriva od izabrane kolicine!");
                            if(IsPlayerFreezed(i) == 0) TogglePlayerControllable(i,1);
                            Refueling[i][Time] = 0;
                            Refueling[i][Amount] = 0;
                            Refueling[i][Price] = 0;
                            return 1;
                        }
                        VehicleInfo[VID][vFuel] = VehicleInfo[VID][vFuel] + Refueling[i][Amount];
                        if(VehicleInfo[VID][vFuel] > 100.0) VehicleInfo[VID][vFuel] = 100.0;
                        Refueling[i][Time] = 0;
                        Refueling[i][Amount] = 0;
                        Refueling[i][Price] = 0;
                        if(IsPlayerFreezed(i) == 0) TogglePlayerControllable(i,1);
                        SendClientMessage(i,COLOR_YELLOW,"[Pumpa] Uprava je platila za gorivo.");
                    }
                    else
                    {
                        if(SafeGetPlayerMoney(i) >= Refueling[i][Price])
                        {
                            if(Refueling[i][Amount] + VehicleInfo[VID][vFuel] > 100.0)
                            {
                                SendClientMessage(i,COLOR_GREY,"Trenutno imate vise goriva od izabrane kolicine!");
                                if(IsPlayerFreezed(i) == 0) TogglePlayerControllable(i, 1);
                                Refueling[i][Time] = 0;
                                Refueling[i][Amount] = 0;
                                Refueling[i][Price] = 0;
                                return 1;
                            }
                            format(string,sizeof(string),"[Pumpa] Natocili ste gorivo, cena: $%d.",Refueling[i][Price]);
                            SendClientMessage(i,COLOR_YELLOW,string);
                            SafeGivePlayerMoney(i, -Refueling[i][Price]);
                            Log_Money(i,-Refueling[i][Price],"[cmd:refueling]");
                            VehicleInfo[VID][vFuel] = VehicleInfo[VID][vFuel] + Refueling[i][Amount]; //910
                            if(VehicleInfo[VID][vFuel] > 100.0) VehicleInfo[VID][vFuel] = 100.0;
                            if(IsPlayerFreezed(i) == 0) TogglePlayerControllable(i, 1);
                            Refueling[i][Time] = 0;
                            Refueling[i][Amount] = 0;
                            Refueling[i][Price] = 0;
                        }
                        else
                        {
                            format(string,sizeof(string),"* Nemate dovoljno novca za gorivo, racun je $%d .",Refueling[i][Price]);
                            SendClientMessage(i,COLOR_WHITE,string);
                            if(IsPlayerFreezed(i) == 0) TogglePlayerControllable(i, 1);
                            Refueling[i][Time] = 0;
                            Refueling[i][Amount] = 0;
                            Refueling[i][Price] = 0;
                        }
                    }
                    UpdatePlayerVehTD(i,true);
                }
            }
        }
    }
    return 1;
}

Option 2:
Not recommendable
pawn Code:
#pragma dynamic 1000000
__________________
The Lag is real!
Jastak is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem [DEBUG] public OnVehicleSpawn Lloyde Scripting Help 0 06/11/2016 05:30 AM
public OtherTimer Jay_Dixon Scripting Help 2 10/05/2013 08:07 PM
[Debug] Error public PryX0G3n Scripting Help 2 29/09/2012 10:33 PM
Running 1 or 2 timers in a public function? Face9000 Scripting Help 2 30/12/2011 11:53 PM


All times are GMT. The time now is 09:22 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.