Trunk system
#1

Hello I need help with my own trunk system, I just started with it and I don't know how to detect if vehicle's trunk is already open or not ? I want to make if it's open it will do something and if it's not open and if player want to put something in it it will send him a message here is the code what I tried:

But message appears even if it's open...

pawn Код:
if(listitem == 1) // Put in trunk
            {
                for(new vid; vid<MAX_VEHICLES; vid++)
                {
                    if(Carinfo[vid][Trunk] == 0)
                    {
                        SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to open trunk first.");
                        return 1;
                    }
                }
            }
Rest of codes that might help you:

pawn Код:
enum Car
{
    Float:F, // Fuel
    VehWin, // Windows
    Trunk,
    tWeapon1,
    tWeapon2,
    tWeapon3,
    tWeapon4,
    tWeapon5,
    tWeapon6,
    tAmmo1,
    tAmmo2,
    tAmmo3,
    tAmmo4,
    tAmmo5,
    tAmmo6
};
new Carinfo[MAX_VEHICLES][Car];
pawn Код:
forward Float:GetXYBehindCar(vid, &Float:q, &Float:w, Float:distance);
Float:GetXYBehindCar(vid, &Float:q, &Float:w, Float:distance)
{
    new Float:a;
    GetVehiclePos(vid, q, w, a);
    GetVehicleZAngle(vid, a);
    q += (distance * -floatsin(-a, degrees));
    w += (distance * -floatcos(-a, degrees));
    return a;
}
Guys I really need help with this :S :S The problem is when I press every option in dialog it bug this system and it says "trunk is already open" even if it's close... Can you help guys I really need help with this

pawn Код:
if(dialogid == DIALOG_TRUNK)
    {
        new vehicle = GetPlayerVehicleID(playerid);
        new e,l,a,d,b,bo,o;
        GetVehicleParamsEx(vehicle,e,l,a,d,b,bo,o);
       
        if(response)
        {
            if(listitem == 0) // Open the trunk
            {
                for(new vid; vid<MAX_VEHICLES; vid++)
                {
                    new Float: vx, Float:vy, Float:vz;
                    GetVehiclePos(vid,vx,vy,vz);
                    GetXYBehindCar(vid, vx, vy, 1.5);
                    if(Carinfo[vehicle][Trunk] == 1)
                    {
                        SendClientMessage(playerid, -1,"{FF6A22}INFO: {FFFFFF}Trunk is already open.");
                        return 1;
                    }
                    if(IsPlayerInRangeOfPoint(playerid,1.5,vx,vy,vz))
                    {
                        Carinfo[vehicle][Trunk] = 1;
                        SetVehicleParamsEx(vid,e,l,a,d,b,1,o);
                        return 1;
                    }
                }
            }
            if(listitem == 1) // Put in trunk
            {
                if(Carinfo[vehicle][Trunk] == 0)
                {
                    SendClientMessage(playerid, -1,"{FF6A22}INFO: {FFFFFF}You need to open trunk first.");
                    return 1;
                }
            }
            if(listitem == 2) // Take from trunk
            {
                if(Carinfo[vehicle][Trunk] == 0)
                {
                    SendClientMessage(playerid, -1,"{FF6A22}INFO: {FFFFFF}You need to open trunk first.");
                    return 1;
                }
            }
            if(listitem == 3) // Close the trunk
            {
                for(new vid; vid<MAX_VEHICLES; vid++)
                {
                    new Float: vx, Float:vy, Float:vz;
                    GetVehiclePos(vid,vx,vy,vz);
                    GetXYBehindCar(vid, vx, vy, 1.5);
                    if(Carinfo[vehicle][Trunk] == 0)
                    {
                        SendClientMessage(playerid, -1,"{FF6A22}INFO: {FFFFFF}Trunk is already close.");
                        return 1;
                    }
                    if(IsPlayerInRangeOfPoint(playerid,1.5,vx,vy,vz))
                    {
                        Carinfo[vehicle][Trunk] = 0;
                        SetVehicleParamsEx(vid,e,l,a,d,b,0,o);
                        return 1;
                    }
                }
            }
        }
        return 1;
    }
Still need help with this :/
Reply
#2

Use GetVehicleParamsEx?
Reply
#3

Quote:
Originally Posted by BigGroter
Посмотреть сообщение
Use GetVehicleParamsEx?
Umm where?
Reply
#4

Try replacing:
Код:
if(car....)
With:
Код:
new engine, lights, alarm, doors, bonnet, boot, objective;
if(GetVehicleParamsEx(vehicleid, bonnet, 1)
Don't know if it works
Reply
#5

Nope :/ Need some more help with this.

Please guys, I jsut can't solve this I was trying for a damn hour :/ how can I detect if vehicle trunk is open or closed ? and I'm using this code to detect if I'm near trunk and so on..

pawn Код:
forward Float:GetXYBehindCar(vid, &Float:q, &Float:w, Float:distance);
Float:GetXYBehindCar(vid, &Float:q, &Float:w, Float:distance)
{
    new Float:a;
    GetVehiclePos(vid, q, w, a);
    GetVehicleZAngle(vid, a);
    q += (distance * -floatsin(-a, degrees));
    w += (distance * -floatcos(-a, degrees));
    return a;
}
Can someone tell me how to detect if vehicle's trunk is already open ? :S
Reply
#6

GetVehicleParamsEx (store all vehicle details in local variables) then check proper one for trunk (boot)

if(boot)Trunk is open
else Trunk is closed.
Reply
#7

Okay this is what I tried

pawn Код:
if(listitem == 1) // Put in trunk
            {
                for(new vid; vid<MAX_VEHICLES; vid++)
                {
                    new e,l,a,d,b,bo,o;
                    GetVehicleParamsEx(vid,e,l,a,d,b,bo,o);
                    if(bo == 0)
                    {
                        SendClientMessage(playerid, COLOR_RED,"{00FF00}INFO: {FFFFFF}open it");
                        return 1;
                    }
                }
            }
            if(listitem == 2) // Take from trunk
            {
                for(new vid; vid<MAX_VEHICLES; vid++)
                {
                    new e,l,a,d,b,bo,o;
                    GetVehicleParamsEx(vid,e,l,a,d,b,bo,o);
                    if(bo == 0)
                    {
                        SendClientMessage(playerid, COLOR_RED,"{00FF00}INFO: {FFFFFF}open it");
                        return 1;
                    }
                }
            }
But first time it says that message even if trunk is open :/ :/ Damn just can't figure out how to detect if trunk is open can you help guys?
Reply
#8

if(boot > 0)Boot is open.
else Boot is closed.
Reply
#9

Okay this is the problem (Don't mind that sprite in middle of pic I was learning to add sprites)

When trunk is opened it will count it as closed and it will always send a message that was added at code - if trunk is closed..
that "Open it" message is in at listitem 2 to take something from trunk that's why it sends different message don't mind it because I tested this thing again and it's saying "closed" even if it's opened..


Here is the think I've made - here is to open/close trunk
pawn Код:
if(dialogid == DIALOG_TRUNK)
    {
        if(response)
        {
            if(listitem == 0) // Open the trunk
            {
                for(new vid; vid<MAX_VEHICLES; vid++)
                {
                    new Float: vx, Float:vy, Float:vz;
                    GetVehiclePos(vid,vx,vy,vz);
                    GetXYBehindCar(vid, vx, vy, 2.5);
                    if(IsPlayerInRangeOfPoint(playerid,2.5,vx,vy,vz))
                    {
                        new e,l,a,d,b,bo,o;
                        GetVehicleParamsEx(vid,e,l,a,d,b,bo,o);
                        switch(VTrunk[vid])
                        {
                            case 0:
                            {
                                SetVehicleParamsEx(vid,e,l,a,d,b,1,o);
                                VTrunk[vid]=1;
                                format(string, sizeof(string), "* %s presses the button at the trunk and afterwards opens it.", Name);
                                ProxDetector(30.0, playerid, string, COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE);
                            }
                            case 1:
                            {
                                SetVehicleParamsEx(vid,e,l,a,d,b,0,o);
                                VTrunk[vid]=0;
                                format(string, sizeof(string), "* %s grabs the edge of the trunk and closes it.", Name);
                                ProxDetector(30.0, playerid, string, COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE,COLOR_DBLUE);
                            }
                        }
                        return 1;
                    }
                }
            }
And here is a think that I want to detect if trunk is closed it will send a "error" message and player will need to open the trunk before putting something in it.

pawn Код:
if(listitem == 1) // Put in trunk
            {
                for(new vid; vid<MAX_VEHICLES; vid++)
                {
                    new e,l,a,d,b,bo,o;
                    GetVehicleParamsEx(vid,e,l,a,d,b,bo,o);
                    if(bo > 0)
                    {
                        SendClientMessage(playerid, COLOR_RED,"{00FF00}INFO: {FFFFFF}test message");
                        return 1;
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_RED,"{00FF00}INFO: {FFFFFF} Closed");
                        return 1;
                    }
                }
            }
It's just not working :/ More help please.
Reply
#10

Quote:

VTrunk[vid]

You don't need that if you're using GetVehicleParamsEx!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)