Dynamic Vehicle Issues
#1

Hey! So I decided to take a crack at making my own dynamic vehicles system, where you can create a vehicle dynamically via /dvcreate [model] [colour 1] [colour 2].

Below, is the code.

pawn Код:
CMD:dvcreate(playerid, params[])
{
    if(Player[playerid][AdminLevel] >= 4)
    {
   
        new carid, col1, col2, Float: dvposx, Float: dvposy, Float: dvposz, Float: dvposa, model, string[128], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        if(sscanf(params, "ddd", model, col1, col2))
        {
            SendClientMessage(playerid, WHITE, "SYNTAX: /dvcreate [model] [colour 1] [colour 2]");
            SendClientMessage(playerid, GREY, "Models: Vehicle models begin at 400, and end at 611.");
            return 1;
        }
        else if(model < 400 || model > 611)
        {
            {
                 SendClientMessage(playerid, GREY, "Vehicle IDs start at 400 and end at 611.");
                 SendClientMessage(playerid, WHITE, "SYNTAX: /dvcreate [model] [colour 1] [colour 2]");
                 SendClientMessage(playerid, GREY, "Models: Vehicle models begin at 400, and end at 611.");
                 return 1;
            }
        }
        else
        {
       
            GetPlayerPos(playerid, dvposx, dvposy, dvposz);
            carid = CreateVehicle(model, dvposx, dvposy+4, dvposz, dvposa, col1, col2, -1);
            GetVehicleZAngle(carid, dvposa);
            PutPlayerInVehicle(playerid, carid, 0);
       
            format(string, sizeof(string), "Vehicles/%d.ini", GetPlayerVehicleID(playerid));

            if(!fexist(string))
            {
                dini_Create(string);
            }
            dini_IntSet(string, "model", model);
            dini_IntSet(string, "Faction", 0);
            dini_IntSet(string, "Gang", 0);
            dini_IntSet(string, "Rank", 0);
            dini_FloatSet(string, "ParkedX", dvposx);
            dini_FloatSet(string, "ParkedY", dvposy);
            dini_FloatSet(string, "ParkedZ", dvposz);
            dini_FloatSet(string, "ParkedA", dvposa);
            dini_FloatSet(string, "VehicleVW", GetPlayerVirtualWorld(playerid));
            dini_FloatSet(string, "VehicleInt", GetPlayerInterior(playerid));
            dini_IntSet(string, "Colour1", col1);
            dini_IntSet(string, "Colour2", col2);
            dini_IntSet(string, "RespawnDelay", -1);
            dini_IntSet(string, "VehAdminLevel", 0);
           
            format(string, sizeof(string), "[Admin] %s has created dynamic vehicle %d (Model %d).", name, carid, model);
            AdminActionLog(string);
            return 1;
        }
    }
    else
    {
        SendClientMessage(playerid, GREY, NOAUTH);
    }
    return 1;
}
However, doing it my way has made it impossible to spawn throwaway vehicles (vehicles that are used by admins, and go away after the gamemodeexits), delete dynamic cars dynamically, and edit dynamic cars dynamically. If you're unsure why, its because I save using the car ids after the player is inside the car (PutPlayerInVehicle, GetPlayerVehicleID, dini_Create (file of course being named the vehicle id .ini (%d.ini)))

However, this is conflicting as crap.

I want to be able to do /dl, and get the cars id by looking at the ID, and being able to do /dvdelete. However, if I delete vehicles, then I cause conflictions because when the vehicles spawn, their ID will not match their file and it will not properly delete the vehicles and the file.

TLDR; So here's what I mean if you don't quite get it: When vehicles spawn, they are to take on the ID of their file, but if I allow the use of dynamically deleting, and creating thowaway cars, then their in game ID will not match the id of their file.

Example:

*Jason spawns Vehicle 9*
*Jason deletes Vehicle 8*
*Jason restarts the server*
*Vehicle 9, takes on in-game ID 8, while keeping their file name 9.ini*

See the confliction?

Giving a HUGE REP+ to anyone who can help me with this.
Reply
#2

I think This FilterScript Will Help, Every Spawned Car With Its ID : CLick Me
+Rep if i helped you !
Reply
#3

Quote:
Originally Posted by GeekSiMo
Посмотреть сообщение
I think This FilterScript Will Help, Every Spawned Car With Its ID : CLick Me
+Rep if i helped you !
That include is useful, however it's not capable of doing what I want, thanks though.

Reminder: I want a vehicle to spawn as the ID it has on its dini file, meaning that if its dini file is 9.ini, it'll spawn as ID 9, and not ID 8 because I deleted car id 8 and its no longer in my files.
Reply
#4

Still need help with this.
Reply
#5

Quote:
Originally Posted by BornHuman
Посмотреть сообщение
Still need help with this.
Yup ^
Reply
#6

The only thing I can think, is creating vehicles outside the map if IDs don't match, but only in that case if vehicle ID from file is bigger than created vehicle ID and there is no possibility to add vehicles while loading them. For example:
pawn Код:
// vehicle loading
// your loop through %i.ini files (%i is variable 'v' in this case)
new bool:cveh = false;
new vehid = CreateVehicle(...);
while(vehid < v)
{
    if(!cveh)   DestroyVehicle(vehid);
    vehid = CreateVehicle(any model any pos); // this is going to be your 'fake' vehicle
    cveh = true;
}
if(cveh) vehid = CreateVehicle(...); // your vehicle with ID that matches filename
Reply
#7

BornHuman, I need your help in a script like that, Please add me on ********

www.********.com/Haseeb.DarkStar1
Reply
#8

Use your own id and try to match it with the car id, when you create "throwaway cars" don't increase so the next car takes it, but don't save with it unless you're restarting the server, cause it's not gonna be correct most of the times, or when you spawn a car after deleting one. like this
pawn Код:
new carid;

//Spawn a normal car

carid ++;//should match the normal id aslong as you didn't create any throwaways

//Spawn a throwaway car

nothing, so the next car takes this id, but don't save it cause it's just when you restart/respawn a car

//restart server

use the carid as the actual id, since the trowaway cars aren't going to respawn
You'll have to do some optimization (like when a normal car is destroyed normally, somebody blow it up), but you should get my idea
Reply
#9

When you do /vdelete just set the vehicle to an unused model. For example 411(Infernus), save the vehicle in the DINI files, then DestroyVehicle it. In the script files it will show the vehicle model ID as being 411.

/vcreate will overwrite the car that you have previous /vdelete'd, but if you don't create a new vehicle before a restart then simply set a timer OnGameModeInti of maybe 5 seconds, that deletes all cars that have the model 411.

That way cars spawn with their matching DINI file ID's, and continue to be delete. (What I used to do).
Reply
#10

Quote:
Originally Posted by FrankTimber
Посмотреть сообщение
When you do /vdelete just set the vehicle to an unused model. For example 411(Infernus), save the vehicle in the DINI files, then DestroyVehicle it. In the script files it will show the vehicle model ID as being 411.

/vcreate will overwrite the car that you have previous /vdelete'd, but if you don't create a new vehicle before a restart then simply set a timer OnGameModeInti of maybe 5 seconds, that deletes all cars that have the model 411.

That way cars spawn with their matching DINI file ID's, and continue to be delete. (What I used to do).
so lets say I spawned 3 cars, two are normal cars and one's a throwaway, ids gonna be
0 - 1(throwaway one) - 2
then when the server restarts, I set the model of id 1 to 411( or something i don't use ) and save it

when I load and spawn cars, I should avoid spawning all the cars with that model, so car 0's gonna be the same id, but since one's not gonna spawn anymore 2's gonna be one, and still saved as two, I don't think setting models will fix this, except if you actually spawn that car and hiding/deleting it later, which will also take alot of unnecessary space in the database.

this idea is good if you're going to delete and spawn cars which will take their space, but what if no cars are going to be spawned after it and overwrite the "411" model, you'll spawn a random car in the server
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)