PVars and deleting 3dtext label
#1

Ok so i wanted to use PVARs to delete a text label this is what i've got and i just cant get it to work with the PVARS
pawn Код:
new label[128];
new Text3D:vehicle3DText;
// This function adds a vehicle to the house (if possible)
House_AddVehicle(HouseID, cModel, cPaint, cComponents[], Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, playerid)
{
    // Setup local variables
    new vid, CarSlot;

    // Get a free carslot from the house
    CarSlot = House_GetFreeCarSlot(HouseID);

    // Check if there is a free carslot
    if (CarSlot != -1)
    {
        // Create a new vehicle and get the vehicle-id
        vid = CreateVehicle(cModel, cx, cy, cz, crot, Col1, Col2, 600);
        // Store the vehicle-id in the house's free carslot
        AHouseData[HouseID][VehicleIDs][CarSlot] = vid;

        // Save the model of the vehicle
        AVehicleData[vid][Model] = cModel;
        // Save the paintjob of the vehicle and apply it
        AVehicleData[vid][PaintJob] = cPaint;
        if (cPaint != 0)
            ChangeVehiclePaintjob(vid, cPaint - 1);

        // Also update the car-color
        ChangeVehicleColor(vid, Col1, Col2);
        // Save the colors of the vehicle
        AVehicleData[vid][Color1] = Col1;
        AVehicleData[vid][Color2] = Col2;

        // Save the components of the vehicle and apply them
        for (new i; i < 14; i++)
        {
            AVehicleData[vid][Components][i] = cComponents[i];
            // Check if the componentslot has a valid component-id
            if (AVehicleData[vid][Components][i] != 0)
                AddVehicleComponent(vid, AVehicleData[vid][Components][i]); // Add the component to the vehicle
        }

        // Save the spawn-data of the vehicle
        AVehicleData[vid][SpawnX] = cx;
        AVehicleData[vid][SpawnY] = cy;
        AVehicleData[vid][SpawnZ] = cz;
        AVehicleData[vid][SpawnRot] = crot;
        // Also set the fuel to maximum
        AVehicleData[vid][Fuel] = MaxFuel;
        // Also set the owner
        AVehicleData[vid][Owned] = true;
        format(AVehicleData[vid][Owner], 24, AHouseData[HouseID][Owner]);
        // Save the HouseID for the vehicle
        AVehicleData[vid][BelongsToHouse] = HouseID;
       
        format(label, sizeof(label), "This vehicle is owned by: \n %s", AVehicleData[vid][Owner]);
        vehicle3DText = Create3DTextLabel(label, 0x008080FF, AVehicleData[vid][SpawnX], AVehicleData[vid][SpawnY], AVehicleData[vid][SpawnZ], 100.0, 0);
        SetPVarString(playerid, "Label", Text3D:vehicle3DText);
        Attach3DTextLabelToVehicle(vehicle3DText, vid, 0.0, 0.0, 2.0);
    }
    else // No free carslot was found, return 0
        return 0;

    // Exit the function and return the vehicle-id
    return vid;
}

// This function is used only when you respawn your vehicles by exiting your house
House_ReplaceVehicle(HouseID, CarSlot, playerid)
{
    // Setup local variables
    new vid, cModel, cPaint, cComponents[14], Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, Float:Health, cFuel;
    new panels, doors, lights, tires;

    // Get the data from the already existing vehicle that was parked before
    vid = AHouseData[HouseID][VehicleIDs][CarSlot];
    cModel = AVehicleData[vid][Model];
    cPaint = AVehicleData[vid][PaintJob];
    cFuel = AVehicleData[vid][Fuel];
    for (new i; i < 14; i++)
        cComponents[i] = AVehicleData[vid][Components][i];
    Col1 = AVehicleData[vid][Color1];
    Col2 = AVehicleData[vid][Color2];
    cx = AVehicleData[vid][SpawnX];
    cy = AVehicleData[vid][SpawnY];
    cz = AVehicleData[vid][SpawnZ];
    crot = AVehicleData[vid][SpawnRot];
    GetVehicleHealth(vid, Health);
    GetVehicleDamageStatus(vid, panels, doors, lights, tires);

    // Delete the vehicle and clear the data
    Vehicle_Delete(vid);

    // Create a new vehicle in the same carslot
    vid = House_AddVehicle(HouseID, cModel, cPaint, cComponents, Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, playerid);
    // Update the fuel of the vehicle to the previous setting
    AVehicleData[vid][Fuel] = cFuel;
    // Update the health to what it was before and update the bodywork
    SetVehicleHealth(vid, Health);
    UpdateVehicleDamageStatus(vid, panels, doors, lights, tires);
   
    format(label, sizeof(label), "This vehicle is owned by: \n %s", AVehicleData[vid][Owner]);
    vehicle3DText = Create3DTextLabel(label, 0x008080FF, AVehicleData[vid][SpawnX], AVehicleData[vid][SpawnY], AVehicleData[vid][SpawnZ], 100.0, 0);
    SetPVarString(playerid, "Label", label);
    Attach3DTextLabelToVehicle(vehicle3DText, vid, 0.0, 0.0, 2.0);
    return vid;
}

// This function is used only when a player logs out (the vehicles are unloaded)
House_RemoveVehicles(HouseID, playerid)
{
    // Setup local variables
    new vid;

    // Loop through all carslots of this house
    for (new CarSlot; CarSlot < 10; CarSlot++)
    {
        // Get the vehicle-id
        vid = AHouseData[HouseID][VehicleIDs][CarSlot];

        // Check if there was a vehicle in this carslot
        if (vid != 0)
        {
            // Delete the vehicle and clear the data
            DestroyVehicle(vid);
           
            GetPVarString(playerid, "Label", label);
            Delete3DTextLabel(label);
            AHouseData[HouseID][VehicleIDs][CarSlot] = 0;
            AVehicleData[vid][Owned] = false;
            AVehicleData[vid][Owner] = 0;
            AVehicleData[vid][Model] = 0;
            AVehicleData[vid][PaintJob] = 0;
            for (new i; i < 14; i++)
                AVehicleData[vid][Components][i] = 0;
            AVehicleData[vid][SpawnX] = 0.0;
            AVehicleData[vid][SpawnY] = 0.0;
            AVehicleData[vid][SpawnZ] = 0.0;
            AVehicleData[vid][SpawnRot] = 0.0;
            AVehicleData[vid][BelongsToHouse] = 0;
        }
    }
}
Please help!
Thanks in advance
Reply
#2

You're storing the actual text in the PVar, rather than the ID of it. You'll need the ID of the text label to delete it.
Reply
#3

Hmm i never used PVARs before can you give me an example? :S
Reply
#4

pawn Код:
SetPVarInt(playerid, "3DTextLabel", CreateDynamic3DTextLabel(...));
//Store the ID returned from CreateDynamic3DTextLabel(...) in a PVar called "3DTextLabel", related to 'playerid'.

DestroyDynamic3DTextLabel(GetPVarInt(playerid, "3DTextLabel"));
//Destroy the Dynamic3DTextLabel that was stored in a PVar called "3DTextLabel" related to 'playerid'.
Reply
#5

Well now i gotta attach it to the vehicle how that works? i got this:
pawn Код:
format(label, sizeof(label), "This vehicle is owned by: \n %s", AVehicleData[vid][Owner]);
        SetPVarInt(playerid, "Label", vehicle3DText = CreateDynamic3DTextLabel(label, 0x008080FF, AVehicleData[vid][SpawnX], AVehicleData[vid][SpawnY], AVehicleData[vid][SpawnZ], 100.0, 0));
        Attach3DTextLabelToVehicle(vehicle3DText, vid, 0.0, 0.0, 2.0);
This gives me warnings so how can i fix this? :S
Reply
#6

That wouldn't work anyway, you're confusing Incognito's Streamer's Natives with SAMP natives.

pawn Код:
format(label, sizeof(label), "This vehicle is owned by: \n %s", AVehicleData[vid][Owner]);
new Text3D:LabelVar = CreateDynamic3DTextLabel(label, 0x008080FF, AVehicleData[vid][SpawnX], AVehicleData[vid][SpawnY], AVehicleData[vid][SpawnZ], 100.0, INVALID_PLAYER_ID, YOUR_VEHICLE_THAT_YOU_WANT_TO_ATTACH_IT_TOO);
SetPVarInt(playerid, "LabelVar", _:LabelVar); //You'll have to clear the Text3D identifier because otherwise you'll get an annoying tag mismatch error
Reply
#7

Now im getting a tag mismatch from this: DestroyDynamic3DTextLabel(GetPVarInt(playerid, "Label"));
Reply
#8

My bad, add "Text3D:" to the start of the function name (Text3D:GetPVarInt...)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)