SA-MP Forums Archive
Values of arrays change - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Values of arrays change (/showthread.php?tid=351837)



Values of arrays change - Jochemd - 17.06.2012

Hello,

This is weird. Values of arrays are changing, with proof.

pawn Код:
LicenseVehicle[0] = AddStaticVehicleEx(426,211.9338,-140.8551,1.2101,179.5805,42,42,-1); // Car 1 [Premier]
    LicenseVehicle[1] = AddStaticVehicleEx(426,201.8325,-141.0570,1.2098,180.4212,42,42,-1); // Car 2 [Premier]
    LicenseVehicle[2] = AddStaticVehicleEx(426,194.1738,-140.9005,1.2133,359.6569,42,42,-1); // Car 3 [Premier]
    LicenseVehicle[3] = AddStaticVehicleEx(454,-133.9991,-553.7247,0.1571,35.5402,26,26,-1); // Boat 1 [Tropic]
    LicenseVehicle[4] = AddStaticVehicleEx(454,-161.5800,-579.4626,0.1670,35.6688,26,26,-1); // Boat 2 [Tropic]
    LicenseVehicle[5] = AddStaticVehicleEx(515,-161.9176,-248.4982,2.4536,90.8201,54,77,-1); // Truck 1 [Roadtrain]
    LicenseVehicle[6] = AddStaticVehicleEx(515,-161.2630,-237.1448,2.4465,90.4855,39,78,-1); // Truck 2 [Roadtrain]
As you see I create the vehicles here. This is the only place where I assign the value to the vehicles!!

Now when I check once for their value in OnPlayerStateChange...

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid),modelid = GetVehicleModel(vehicleid),string[128];
        for(new v = 0; v < MAX_CARSHOPVEHS; v ++)
        {
            if(vehicleid == CarshopInfo[v][VehicleID])
            {
                format(string,sizeof(string),"~w~You can buy a ~y~%s ~w~for ~r~$%d~w~. Type ~b~/buyvehicle to ~w~purchase one!",vNames[modelid - 400],CarshopInfo[v][Price]);
                SetInfoBoxMessage(playerid,string,5000);
                SetPVarInt(playerid,"EngineDisabled",1);
                return 1;
            }
        }
        if(modelid != 509 && modelid != 510 && modelid != 481)
        {
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleBoxDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleNameDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleSpeedDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleFuelDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleLightsDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleDoorsDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleTrunkDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleWindowsDraw]);
            if(!VehicleInfo[vehicleid][EngineRunning]) SendClientMessage(playerid,COLOR_WHITE,"The engine is currently {FF0F0F}not running.");
            else SendClientMessage(playerid,COLOR_WHITE,"The engine is currently {008000}running.");
            SetPVarInt(playerid,"CurrentVehicle",vehicleid);
            printf("vehicleid = %d - IsInLicTest = %d",vehicleid,GetPVarInt(playerid,"IsInLicTest"));
            printf("LicenseVehicle 0 = %d",LicenseVehicle[0]);
            printf("LicenseVehicle 1 = %d",LicenseVehicle[1]);
            printf("LicenseVehicle 2 = %d",LicenseVehicle[2]);
            if(vehicleid == LicenseVehicle[0] || vehicleid == LicenseVehicle[1] || vehicleid == LicenseVehicle[2])
            {
                if(GetPVarInt(playerid,"IsInLicTest") == 1)
                {
                    GameTextForPlayer(playerid,"~r~Follow ~y~the ~b~Checkpoints ~g~in order! ~y~Do not ~b~damage ~r~the car!",4000,3);
                    SetPlayerRaceCheckpoint(playerid,0,150.499099,-139.523223,1.324658,-2004.248291,-57.189411,34.906349,3);
                    SetPVarInt(playerid,"RaceCheckpoint",1);
                }
                else
                {
                    RemovePlayerFromVehicle(playerid);
                    SendClientMessage(playerid,COLOR_RED,"(( Error: You are not following the driving lessons. ))");
                }
            }
            //.... The rest does not matter
As you see I added some debug lines. Debug says this

Код:
[15:10:56] vehicleid = 1 - IsInLicTest = 0
[15:10:56] LicenseVehicle 0 = 1
[15:10:56] LicenseVehicle 1 = 2
[15:10:56] LicenseVehicle 2 = 3
All fine and well, work good. Now when I enter it the second time;

Код:
[15:11:11] vehicleid = 1 - IsInLicTest = 0
[15:11:11] LicenseVehicle 0 = 100
[15:11:11] LicenseVehicle 1 = 44
[15:11:11] LicenseVehicle 2 = 32
The values have changed! I change them nowhere in the script, so how in hell can this happen? It also does not remove me from the vehicle anymore. Obviously because the the values changed.

Jochem


AW: Values of arrays change - Nero_3D - 17.06.2012

Try to dubug the error out, put at the beginning and at the end these print statments
If it does change its somewhere in that code, than put more and more prints inside till the point only one line is left


Re: AW: Values of arrays change - Jochemd - 17.06.2012

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Try to dubug the error out, put at the beginning and at the end these print statments
If it does change its somewhere in that code, than put more and more prints inside till the point only one line is left
Then I should debug the whole code!


Re: Values of arrays change - Jochemd - 11.07.2012

Must bump this. I really appreciate the person who helps.


Re: Values of arrays change - Jochemd - 12.07.2012

If you'd like to see the whole callback:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid),modelid = GetVehicleModel(vehicleid),string[128];
        for(new v = 0; v < MAX_CARSHOPVEHS; v ++)
        {
            if(vehicleid == CarshopInfo[v][VehicleID])
            {
                format(string,sizeof(string),"~w~You can buy a ~y~%s ~w~for ~r~$%d~w~. Type ~b~/buyvehicle to ~w~purchase one!",vNames[modelid - 400],CarshopInfo[v][Price]);
                SetInfoBoxMessage(playerid,string,5000);
                SetPVarInt(playerid,"EngineDisabled",1);
                return 1;
            }
        }
        if(modelid != 509 && modelid != 510 && modelid != 481)
        {
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleBoxDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleNameDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleSpeedDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleFuelDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleLightsDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleDoorsDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleTrunkDraw]);
            TextDrawShowForPlayer(playerid,VehicleInfo[vehicleid][VehicleWindowsDraw]);
            if(!VehicleInfo[vehicleid][EngineRunning]) SendClientMessage(playerid,COLOR_WHITE,"The engine is currently {FF0F0F}not running.");
            else SendClientMessage(playerid,COLOR_WHITE,"The engine is currently {008000}running.");
            SetPVarInt(playerid,"CurrentVehicle",vehicleid);
            printf("vehicleid = %d - IsInLicTest = %d",vehicleid,GetPVarInt(playerid,"IsInLicTest"));
            printf("LicenseVehicle 0 = %d",LicenseVehicle[0]);
            printf("LicenseVehicle 1 = %d",LicenseVehicle[1]);
            printf("LicenseVehicle 2 = %d",LicenseVehicle[2]);
            if(vehicleid == LicenseVehicle[0] || vehicleid == LicenseVehicle[1] || vehicleid == LicenseVehicle[2])
            {
                if(GetPVarInt(playerid,"IsInLicTest") == 1)
                {
                    GameTextForPlayer(playerid,"~r~Follow ~y~the ~b~Checkpoints ~g~in order! ~y~Do not ~b~damage ~r~the car!",4000,3);
                    SetPlayerRaceCheckpoint(playerid,0,150.499099,-139.523223,1.324658,-2004.248291,-57.189411,34.906349,3);
                    SetPVarInt(playerid,"RaceCheckpoint",1);
                }
                else
                {
                    RemovePlayerFromVehicle(playerid);
                    SendClientMessage(playerid,COLOR_RED,"(( Error: You are not following the driving lessons. ))");
                }
            }
            else if(vehicleid == LicenseVehicle[3] || vehicleid == LicenseVehicle[4])
            {
                if(GetPVarInt(playerid,"IsInLicTest") == 2)
                {
                    GameTextForPlayer(playerid,"~r~Follow ~y~the ~b~Checkpoints ~g~in order! ~y~Do not ~b~damage ~r~the boat!",4000,3);
                    SetPlayerRaceCheckpoint(playerid,0,-299.836578,-381.801025,0.110261,-401.291717,-345.250305,0.179414,6);
                    SetPVarInt(playerid,"RaceCheckpoint",15);
                }
                else
                {
                    RemovePlayerFromVehicle(playerid);
                    SendClientMessage(playerid,COLOR_RED,"(( Error: You are not following the sailing lessons. ))");
                    return 1;
                }
            }
            else if(vehicleid == LicenseVehicle[5] || vehicleid == LicenseVehicle[6])
            {
                if(GetPVarInt(playerid,"IsInLicTest") == 3)
                {
                    GameTextForPlayer(playerid,"~r~Follow ~y~the ~b~Checkpoints ~g~in order! ~y~Do not ~b~damage ~r~the truck!",4000,3);
                    SetPlayerRaceCheckpoint(playerid,0,-228.691650,-296.025085,2.096233,-43.304546,-454.409545,2.319302,3); /* Red County */
                    SetPVarInt(playerid,"RaceCheckpoint",33);
                }
                else
                {
                    RemovePlayerFromVehicle(playerid);
                    SendClientMessage(playerid,COLOR_RED,"(( Error: You are not following the truck driving lessons. ))");
                    return 1;
                }
            }
            else if(modelid == 448 || modelid == 574 || modelid == 408) SetInfoBoxMessage(playerid,"Type ~g~/work ~w~to start working.",4000);
        }
        else if(modelid == 509 || modelid == 510 || modelid == 481)
        {
            SetVehicleParamsEx(vehicleid,1,0,0,1,0,0,0);
            SetPVarInt(playerid,"EngineDisabled",1);
        }
        if(VehicleInfo[vehicleid][Owned] == 1)
        {
            if(strcmp(VehicleInfo[vehicleid][Owner],PlayerName(playerid),false))
            {
                format(string,sizeof(string),"This ~y~%s~w~ is not yours. The cops are able to arrest you now.",vNames[modelid-400]);
                SetInfoBoxMessage(playerid,string,5000);
                SetVehicleAlarm(vehicleid,100000);
            }
            else if(!strcmp(VehicleInfo[vehicleid][Owner],PlayerName(playerid),false))
            {
                format(string,sizeof(string),"You are driving this ~y~%s ~w~as you're the ~r~owner.",vNames[modelid-400]);
                SetInfoBoxMessage(playerid,string,5000);
            }
        }
        return 1;
    }
    else if(newstate == PLAYER_STATE_PASSENGER)
    {
        new vehicleid = GetPlayerVehicleID(playerid),modelid = GetVehicleModel(vehicleid);
        SetPVarInt(playerid,"CurrentVehicle",vehicleid);
        if(modelid == 420 || modelid == 438)
        {
            if(GetPlayerVehicleSeat(playerid) != 0)
            {
                for(new i = 0; i < MAX_PLAYERS; i ++)
                {
                    if(IsPlayerConnected(i))
                    {
                        if(i != playerid)
                        {
                            if(GetPlayerVehicleID(playerid) == GetPlayerVehicleID(i))
                            {
                                if(GetPlayerVehicleSeat(i) == 0)
                                {
                                    if(GetPVarInt(i,"OnDuty") == 1)
                                    {
                                        GivePlayerCash(playerid,-GetPVarInt(i,"TaxiFareDriver"));
                                        GivePlayerCash(i,GetPVarInt(i,"TaxiFareDriver"));
                                        SendFormatMessage(playerid,COLOR_WHITE,"You have paid {FF0F0F}$%d {FFFFFF}to the Taxi Driver.",GetPVarInt(i,"TaxiFareDriver"));
                                        SendFormatMessage(i,COLOR_YELLOW,"  %s has entered your Taxi and paid you $%d.",PlayerName(playerid),GetPVarInt(i,"TaxiFareDriver"));
                                        SetPVarInt(playerid,"CalledTaxi",0);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return 1;
    }
    if(oldstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPVarInt(playerid,"CurrentVehicle"),Float:Pos[4],Float:Health;
        GetVehicleHealth(vehicleid,Health);
        if(VehicleInfo[vehicleid][Owned] == 1)
        {
            if(VehicleInfo[vehicleid][Locked] == 0 && !strcmp(PlayerName(playerid),VehicleInfo[vehicleid][Owner])) SetInfoBoxMessage(playerid,"~w~Lock your ~y~vehicle ~w~or it can be ~r~stolen!",4000);
            GetVehiclePos(vehicleid,Pos[0],Pos[1],Pos[2]);
            GetVehicleZAngle(vehicleid,Pos[3]);
            mysql_format(1,QueryString,"UPDATE `VehicleInfo` SET `VehiclePosX` = %f,`VehiclePosY` = %f,`VehiclePosZ` = %f,`VehicleAngle` = %f, `VehicleFuel` = %d, `VehicleHealth` = %f WHERE `ID` = %d",Pos[0],Pos[1],Pos[2],Pos[3],VehicleInfo[vehicleid][Fuel],Health,VehicleInfo[vehicleid][FileVehicleID]);
            mysql_function_query(1,QueryString,false,"SomeNotExistingCallback","","");
        }
        SetPVarInt(playerid,"EngineDisabled",0);
        TextDrawHideForPlayer(playerid,VehicleInfo[vehicleid][VehicleBoxDraw]);
        TextDrawHideForPlayer(playerid,VehicleInfo[vehicleid][VehicleNameDraw]);
        TextDrawHideForPlayer(playerid,VehicleInfo[vehicleid][VehicleSpeedDraw]);
        TextDrawHideForPlayer(playerid,VehicleInfo[vehicleid][VehicleFuelDraw]);
        TextDrawHideForPlayer(playerid,VehicleInfo[vehicleid][VehicleDoorsDraw]);
        TextDrawHideForPlayer(playerid,VehicleInfo[vehicleid][VehicleLightsDraw]);
        TextDrawHideForPlayer(playerid,VehicleInfo[vehicleid][VehicleTrunkDraw]);
        TextDrawHideForPlayer(playerid,VehicleInfo[vehicleid][VehicleWindowsDraw]);
        SetPVarInt(playerid,"CurrentVehicle",0);
        return 1;
    }
    return 1;
}
Must run crashdetect

Edit: Crashdetect loads fine but does not print any log! I compiled fine with the flag "-d3". It neither works on LVDM.

Also I found out the value of the array changes after the "if(newstate == PLAYER_STATE_DRIVER)" line. What the heck


Re: Values of arrays change - justsomeguy - 12.07.2012

-Nvm-.