SA-MP Forums Archive
Need help with stock and car restriction. - 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: Need help with stock and car restriction. (/showthread.php?tid=559742)



Need help with stock and car restriction. - scout322 - 25.01.2015

So, i have a zgaming script and im really confused. I have a script that doesnt allow players to get inside faction vehicles.. Half of the code works. but toher half doesnt, but both half's are the same....
So here are the codes.

DMV cars works.. i cant get in them but the Miner cars, i can change whatever i want they dont work.. Im so confused. +Rep for helping.

Код:
new DMVCar[5];
new MinerCar[3];
Stocks:
Код:
// Working one
stock IsDMVCar(vehicleid)
{
    for(new i=0; i<5; i++)
    {
        if(vehicleid == DMVCar[i]) return 1;
    }
    return 0;
}
// Not working one
stock IsMinerVehicle(vehicleid)
{
    for(new i=0; i<10; i++)
    {
        if(vehicleid == MinerCar[i]) return 1;
    }
    return 0;
}
Car spawning:
Код:
DMVCar[0] = CreateVehicle(445,2056.0117,-1904.0990,13.4219,180.0940,50,92,300); 
DMVCar[1] = CreateVehicle(445,2062.4028,-1904.3759,13.4219,180.5574,50,92,300);
DMVCar[2] = CreateVehicle(445,2062.1218,-1919.2986,13.4219,359.8005,50,92,300);

	MinerCar[0] = CreateVehicle(486,678.7999900,907.2000100,-40.1000000,102.7540000,1,1,0); //dozer[playerid]
	MinerCar[1] = CreateVehicle(486,680.0000000,901.2999900,-39.8000000,99.9550000,1,1,0); //dozer[playerid]
	MinerCar[2] = CreateVehicle(486,681.2000100,894.7000100,-39.6000000,104.4240000,1,1,0); //dozer[playerid]
The script:
Код:
		if(IsDMVCar(vehicleid))
        {
            if(!LicenseTest[playerid]) SendClientMessage(playerid, COLOR_ORANGE, "You are not taking a drivers license test.");
            else
            {
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "* GPS: Finish the test by driving through all of the checkpoints on your GPS.");
                SetPlayerCheckpoint(playerid, 2052.0376,-1930.2965,13.2517, 5);
                SendClientMessage(playerid, COLOR_RED, "If you exit the car your test will be failed and it will have to be re-done.");
                return 1;
            }
        }
        else if(IsFamVehicle(vehicleid) && Fam[vehicleid] != PlayerInfo[playerid][pFam] && !IsACop(vehicleid) && !IsADOC(vehicleid) && !IsASAAF(vehicleid) && !IsSASD(vehicleid))
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to a family.");
        else if(IsLeoVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 1)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the LSPD.");
        else if(IsLSFMDVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 5)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the LSFMD.");
        else if(IsNewsVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 4)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the News Agency.");
        else if(IsFBIVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 6)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the FBI.");
        else if(IsNGVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 7)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the NG.");
        else if(IsRETOVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 9)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to Rebel's Towing");
        else if(IsTaxiVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 10)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to LS Taxi Co");
        else if(IsTruckerVehicle(vehicleid) && PlayerInfo[playerid][pJob] != JOB_TRUCKER)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the Truckers.");
        else if(IsGovVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 2)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the GOV.");
        else if(IsSAAFVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 11)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the SA Air Force.");
        else if(IsDOCVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 13)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the Department Of Correct.");
        else if(IsSASDVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 8)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the San Andreas Sherrif Department.");
        else if(IsMinerVehicle(vehicleid) && PlayerInfo[playerid][pJob] != JOB_MINER)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the Miner job.");
        else if(IsMinerTruckVehicle(vehicleid) && PlayerInfo[playerid][pJob] != JOB_MINER)
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the Miner job.");
        else return 1;
        if(!ispassenger)
    	{
        new Float:pos[3];
        GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
        SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
        }



Re: Need help with stock and car restriction. - scout322 - 25.01.2015

Anybody ? Is this normal, or realy rare ?


Re: Need help with stock and car restriction. - vassilis - 25.01.2015

Everything else works except miner vehicle ?


Re: Need help with stock and car restriction. - scout322 - 25.01.2015

No.. Goverment vehicles doesnt work too. But the code is excatly the same.. Im so confused


Re: Need help with stock and car restriction. - Schneider - 25.01.2015

I'm not sure if this is the cause of the problem, but you're doing 10 loops while you only have 3 miner-cars.
So the script will checking slots that do not exist. So max the amount of loops to the size of the array and do the same with the loops in the other stocks.

pawn Код:
stock IsMinerVehicle(vehicleid)
{
    for(new i=0; i<sizeof(MinerCar); i++)
    {
        if(vehicleid == MinerCar[i]) return 1;
    }
    return 0;
}



Re: Need help with stock and car restriction. - scout322 - 25.01.2015

I Already checked that.. The loops may be cousing more lag to server but it doesnt couse the script not to work. And the way you did it dont work too. :/ I Really have no idea how to fix this. Maybe other parts of my script couses it not to work ?


Re: Need help with stock and car restriction. - Rabea - 25.01.2015

Use this way.
pawn Код:
else if(IsFamVehicle(vehicleid) && Fam[vehicleid] != PlayerInfo[playerid][pFam] && !IsACop(vehicleid) && !IsADOC(vehicleid) && !IsASAAF(vehicleid) && !IsSASD(vehicleid))
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, " You can't get in this car as it belongs to a family.");
        }
        else if(IsLeoVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 1)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the LSPD.");
        }
        else if(IsLSFMDVehicle(vehicleid) && PlayerInfo[playerid][pFac] != 5)
        {
            new Float:pos[3];
            GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            SendClientMessage(playerid, COLOR_GREY, " You can't get in this car as it belongs to the LSFMD.");
        }



Re: Need help with stock and car restriction. - scout322 - 25.01.2015

Still not working :/ So confused...


Re: Need help with stock and car restriction. - Rabea - 25.01.2015

This codes only for three things, add all ur codes


Re: Need help with stock and car restriction. - Vince - 25.01.2015

Quote:
Originally Posted by scout322
Посмотреть сообщение
The loops may be cousing more lag to server but it doesnt couse the script not to work.
Yes, they do. Out-of-bounds errors are silent killers since they aren't always displayed, but they can cause all sorts of unrelated problems.