SA-MP Forums Archive
Problem deleting text labels - 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: Problem deleting text labels (/showthread.php?tid=306597)



Problem deleting text labels - thimo - 27.12.2011

Ok so i wanna make that there is a 3dtext label on a OWNED car... i got this:
pawn Код:
new Text3D:vehicle3DText[MAX_VEHICLES];
// 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)
{
    // 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;
        new string[128];
        format(string, sizeof(string), "Vehicle owned by: \n%s", AVehicleData[vid][Owner]);
        vehicle3DText[cModel] = Create3DTextLabel(string, 0xFFFFFF, 0, 0, 0, 80, 0);
        Attach3DTextLabelToVehicle(vehicle3DText[cModel], vid, 0.0, 0.0, 0.0);
       
    }
    else // No free carslot was found, return 0
        return 0;

    // Exit the function and return the vehicle-id
    return vid;
}
This all works...
But now the deleting part when a player leaves... This doesnt work and the next player wichjoins and gets same car ID gets the same 3dtext label on it + its own. This is the code
pawn Код:
// This function is used only when a player logs out (the vehicles are unloaded)
House_RemoveVehicles(HouseID)
{
    // Setup local variables
    new vid, cModel;
    cModel = AVehicleData[vid][Model];
    // 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);
            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;
            Delete3DTextLabel(Text3D:vehicle3DText[cModel]);
        }
    }
}
This gets called at disconnect...
pawn Код:
for (new HouseSlot; HouseSlot < MAX_HOUSESPERPLAYER; HouseSlot++)
    {
        // Get the HouseID from this slot
        HouseID = APlayerData[playerid][Houses][HouseSlot];
        // Check if there is a house in this slot
        if (HouseID != 0)
        {
            // Unload the cars of the house
            House_RemoveVehicles(HouseID);
            // Set the house so it cannot be entered by anyone (close the house)
            AHouseData[HouseID][HouseOpened] = false;
        }
    }
Why this wont delete that text label? I tried like 100 times now :S

Thanks in advance


Re: Problem deleting text labels - Ash. - 27.12.2011

I recognize parts of that code... Oh wait i was helping one of your server devs with it..

You should'nt be deleting it based on the model. You should delete it based on the vehicle id. (Vehicle3DText(vid)) - use square brackets by tue way, still getting used to the symbol system on my new phone haha.


Re: Problem deleting text labels - thimo - 27.12.2011

Well i did that too but... No succes!


Re: Problem deleting text labels - -Prodigy- - 27.12.2011

^ What he said. Change
pawn Код:
vehicle3DText[cModel]
to
pawn Код:
vehicle3DText[vid]



Re: Problem deleting text labels - thimo - 27.12.2011

I had that before also DIDNT delete anything... and there is another prob... It only gives the second house these labels


Re: Problem deleting text labels - Ash. - 27.12.2011

You should ASSIGN the ID's using the vehicle id (vid) too.


Re: Problem deleting text labels - thimo - 27.12.2011

OK that finally works properly as far as i know.. Now there is a problem only the second house cars get a label the first house doesnt get a albel :S What could be the prob? :S


Re: Problem deleting text labels - Ash. - 27.12.2011

I'm not sure as I haven't touched PPC_Trucking/Housing before. Are you sure it's looping through all the vehicles relevant to the house?

//This is one of the reasons I have the systems (Vehicle and Housing) separate, as issues like this don't occur.


Re: Problem deleting text labels - thimo - 27.12.2011

I dont know how to loop true them any idea? (angel) :S


Re: Problem deleting text labels - Ash. - 27.12.2011

Quote:
Originally Posted by thimo
Посмотреть сообщение
I dont know how to loop true them any idea? (angel) :S
As I've already stated; I have never touched nor seen any of the PPC_Trucking script (aside from bits posted in Scripting Discussion), therefore I have absolutely no clue. This is why you should always script your own gamemodes, to ensure that you know what to edit, how to edit it and what to add if and when needed.

From what I can see, the house car creation runs through a stock function to create the vehicles and attach the relevant data to them. You should ensure that everything is running, ie via debugging.