SA-MP Forums Archive
Trunk system telling me i am not near the car. - 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: Trunk system telling me i am not near the car. (/showthread.php?tid=348359)



Trunk system telling me i am not near the car. - ricardo178 - 05.06.2012

Well, hello again. Made a trunk system, that should open the trunk when we are near an owned car with /trunkinfo but it just tells me i am not near any buyable vehicle.. :S

I am really near them.. Used more distance range thanf or /lock and /lock works...
I verified all, it's a simmple code, i don't really know why it fails...

pawn Код:
CMD:trunkinfo(playerid, params[])
{
    for(new i = 1; i < sizeof(CarInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, CarInfo[i][X], CarInfo[i][Y], CarInfo[i][Z]))
        {
            if(CarInfo[i][Lock] == 0)
            {
                GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
                SetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,true,objective);
                new string[128];
                format(string, sizeof(string), "||--------------Trunk---------------||");
                SendClientMessage(playerid, COLOR_LIGHTRED, string);
                format(string, sizeof(string), "Weapon Slot 1: %d with %d ammo.", CarInfo[i][Weapon1], CarInfo[i][Weapon1Ammo]);
                SendClientMessage(playerid, COLOR_LIGHTRED, string);
                format(string, sizeof(string), "Weapon Slot 2: %d with %d ammo.", CarInfo[i][Weapon2], CarInfo[i][Weapon2Ammo]);
                SendClientMessage(playerid, COLOR_LIGHTRED, string);
                format(string, sizeof(string), "Weapon Slot 3: %d with %d ammo.", CarInfo[i][Weapon3], CarInfo[i][Weapon3Ammo]);
                SendClientMessage(playerid, COLOR_LIGHTRED, string);
                format(string, sizeof(string), "Weapon Slot 4: %d with %d ammo.", CarInfo[i][Weapon4], CarInfo[i][Weapon4Ammo]);
                SendClientMessage(playerid, COLOR_LIGHTRED, string);
                format(string, sizeof(string), "Weapon Slot 5: %d with %d ammo.", CarInfo[i][Weapon5], CarInfo[i][Weapon5Ammo]);
                SendClientMessage(playerid, COLOR_LIGHTRED, string);
                format(string, sizeof(string), "Materials: %d ", CarInfo[i][Materials]);
                SendClientMessage(playerid, COLOR_LIGHTRED, string);
                format(string, sizeof(string), "||----------------------------------||");
                SendClientMessage(playerid, COLOR_LIGHTRED, string);
            }
            else return SendClientMessage(playerid, COLOR_LIGHTRED, "This vehicle is locked.");
        }
        else return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not near any vehicle.");
    }
    return 1;
}
Didn't even made the good look saying gun names and stuff, cos i wanted to make the basic first, but it says me the samething all the time..

Tried with returns, without returns..


Re: Trunk system telling me i am not near the car. - milanosie - 05.06.2012

Same again, your using return in a loop.

pawn Код:
else return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not near any vehicle.");
AKA, if id 1 is not near you, it will return that.


Re: Trunk system telling me i am not near the car. - ricardo178 - 05.06.2012

Damn, so how do i return that when there are no vehicles near and why it shows if ID 1 not near? xD I am really mindfucked with that returns shit..


Re: Trunk system telling me i am not near the car. - milanosie - 05.06.2012

Quote:
Originally Posted by ricardo178
Посмотреть сообщение
Damn, so how do i return that when there are no vehicles near and why it shows if ID 1 not near? xD I am really mindfucked with that returns shit..
Count the amount of vehicles you are near, Posted an example in your previous help request


Re: Trunk system telling me i am not near the car. - ricardo178 - 05.06.2012

Thanks. Will try out.


Re: Trunk system telling me i am not near the car. - ricardo178 - 05.06.2012

Something like this?

pawn Код:
CMD:trunkinfo(playerid, params[])
{
    new iTargetID;
    for(new i = 1; i < sizeof(CarInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, CarInfo[i][X], CarInfo[i][Y], CarInfo[i][Z]))
        {
            iTargetID = i;
        }
    }
    GetVehicleParamsEx(iTargetID,engine,lights,alarm,doors,bonnet,boot,objective);
    SetVehicleParamsEx(iTargetID,engine,lights,alarm,doors,bonnet,true,objective);
    new string[128];
    format(string, sizeof(string), "||--------------Trunk---------------||");
    SendClientMessage(playerid, COLOR_LIGHTRED, string);
    format(string, sizeof(string), "Weapon Slot 1: %d with %d ammo.", CarInfo[iTargetID][Weapon1], CarInfo[iTargetID][Weapon1Ammo]);
    SendClientMessage(playerid, COLOR_LIGHTRED, string);
    format(string, sizeof(string), "Weapon Slot 2: %d with %d ammo.", CarInfo[iTargetID][Weapon2], CarInfo[iTargetID][Weapon2Ammo]);
    SendClientMessage(playerid, COLOR_LIGHTRED, string);
    format(string, sizeof(string), "Weapon Slot 3: %d with %d ammo.", CarInfo[iTargetID][Weapon3], CarInfo[iTargetID][Weapon3Ammo]);
    SendClientMessage(playerid, COLOR_LIGHTRED, string);
    format(string, sizeof(string), "Weapon Slot 4: %d with %d ammo.", CarInfo[iTargetID][Weapon4], CarInfo[iTargetID][Weapon4Ammo]);
    SendClientMessage(playerid, COLOR_LIGHTRED, string);
    format(string, sizeof(string), "Weapon Slot 5: %d with %d ammo.", CarInfo[iTargetID][Weapon5], CarInfo[iTargetID][Weapon5Ammo]);
    SendClientMessage(playerid, COLOR_LIGHTRED, string);
    format(string, sizeof(string), "Materials: %d ", CarInfo[iTargetID][Materials]);
    SendClientMessage(playerid, COLOR_LIGHTRED, string);
    format(string, sizeof(string), "||----------------------------------||");
    SendClientMessage(playerid, COLOR_LIGHTRED, string);
    return 1;
}



Re: Trunk system telling me i am not near the car. - milanosie - 05.06.2012

No


Don't place iTrargetId in a loop,

make a variable count = 0;

and for each car you are close to, the count goes ++;


Then just check if count > 0


Re: Trunk system telling me i am not near the car. - ricardo178 - 05.06.2012

This? I hope so. xD

pawn Код:
CMD:trunkinfo(playerid, params[])
{
    new count;
    for(new i = 1; i < sizeof(CarInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, CarInfo[i][X], CarInfo[i][Y], CarInfo[i][Z]))
        {
            count++;
        }
    }
    if(count > 0)
    {
        GetVehicleParamsEx(count,engine,lights,alarm,doors,bonnet,boot,objective);
        SetVehicleParamsEx(count,engine,lights,alarm,doors,bonnet,true,objective);
        new string[128];
        format(string, sizeof(string), "||--------------Trunk---------------||");
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "Weapon Slot 1: %d with %d ammo.", CarInfo[count][Weapon1], CarInfo[count][Weapon1Ammo]);
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "Weapon Slot 2: %d with %d ammo.", CarInfo[count][Weapon2], CarInfo[count][Weapon2Ammo]);
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "Weapon Slot 3: %d with %d ammo.", CarInfo[count][Weapon3], CarInfo[count][Weapon3Ammo]);
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "Weapon Slot 4: %d with %d ammo.", CarInfo[count][Weapon4], CarInfo[count][Weapon4Ammo]);
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "Weapon Slot 5: %d with %d ammo.", CarInfo[count][Weapon5], CarInfo[count][Weapon5Ammo]);
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "Materials: %d ", CarInfo[count][Materials]);
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        format(string, sizeof(string), "||----------------------------------||");
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
    }
    return 1;
}



Re: Trunk system telling me i am not near the car. - milanosie - 05.06.2012

nope, your getting close though


your setting count to 1 and using count as car id aswell,

Use ANOTHER loop after the count loop, like outside it but to loop trough the vehicles again and then use your normal code.


And for if(count == 0)
return SCM(playerid, COLOR_GREY," You are not near a turtle!");


Re: Trunk system telling me i am not near the car. - ricardo178 - 05.06.2012

Quote:
Originally Posted by milanosie
Посмотреть сообщение
nope, your getting close though


your setting count to 1 and using count as car id aswell,

Use ANOTHER loop after the count loop, like outside it but to loop trough the vehicles again and then use your normal code.


And for if(count == 0)
return SCM(playerid, COLOR_GREY," You are not near a turtle!");
Hmm, about the if(count == 0) message i understood, but the other loop didn't..
You mean opening a "for" if again, and check for vehicles again? Didn't understand it.