SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 21/04/2015, 01:23 PM   #1
cloudysky
Huge Clucker
 
Join Date: Jul 2010
Posts: 330
Reputation: 17
Default Getting ID of Vehicle from file

Hi again, another hurdle is in the way with my vehicle script haha this time its retrieving the FileID number of a car.
For example I want to be able to use the command /fileid with it responding 'This File ID is 1" (For the first car saved) etc So i know what cars to remove! I use DINI, i know its outdated.

Thanks in advance.
cloudysky is offline   Reply With Quote
Old 21/04/2015, 01:48 PM   #2
Sithis
Gangsta
 
Join Date: Mar 2013
Location: the Netherlands
Posts: 887
Reputation: 79
Default Re: Getting ID of Vehicle from file

Do you have your code and an exampe ini file for a vehicle?
__________________
Developer and owner of https://trinityrpg.com
Sithis is offline   Reply With Quote
Old 21/04/2015, 01:57 PM   #3
cloudysky
Huge Clucker
 
Join Date: Jul 2010
Posts: 330
Reputation: 17
Default Re: Getting ID of Vehicle from file

EDIT:

This is what I now have, the problem is that it comes up all the cars in the server not just that individual car id. So for example if there is 4 cars on the server, i get in and it goes:

Car 1
Car 2
Car 3
Car 4

Instead of just Car 2.

This is the code
pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Vehiclefile[256];
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
        format(Vehiclefile, sizeof(Vehiclefile), "vehicles/Vehicle_%d.ini", i);
        if(fexist(Vehiclefile) )
        {
            Vehicles[i][FILEID] = dini_Int(Vehiclefile, "FILEID");
            new string[128];
            format(string, sizeof(string), "Car %d", Vehicles[i][FILEID]);
            SendClientMessage(playerid, COLOUR_PURPLE, string);
        }
    }
    return 1;
}

Last edited by cloudysky; 21/04/2015 at 03:08 PM.
cloudysky is offline   Reply With Quote
Old 21/04/2015, 03:47 PM   #4
[KHK]Khalid
Gangsta
 
[KHK]Khalid's Avatar
 
Join Date: Jan 2012
Location: Alexandria, Egypt
Posts: 854
Reputation: 136
Default Re: Getting ID of Vehicle from file

Okay, I understand what you're trying to do there, but this isn't the way to go. It should be easier if you assign the file-id of each vehicle to Vehicles[i][FILEID] while CREATING & LOADING it from files (i.e LoadVehicles, show me that function in your script if you can).
[KHK]Khalid is offline   Reply With Quote
Old 21/04/2015, 04:00 PM   #5
Sithis
Gangsta
 
Join Date: Mar 2013
Location: the Netherlands
Posts: 887
Reputation: 79
Default Re: Getting ID of Vehicle from file

Yes, Khalid is right. I also suggest assigning the appropriate fileid to Vehicles[i][FILEID] during the loading of every vehicle.

During OnPlayerEnterVehicle, you can then simply lookup the fileid by selecting the proper vehicleid, and you're done.
__________________
Developer and owner of https://trinityrpg.com
Sithis is offline   Reply With Quote
Old 21/04/2015, 11:16 PM   #6
cloudysky
Huge Clucker
 
Join Date: Jul 2010
Posts: 330
Reputation: 17
Default Re: Getting ID of Vehicle from file

Thanks for the response, I've been at work so a bit late replying..

Last edited by cloudysky; 22/04/2015 at 10:18 AM.
cloudysky is offline   Reply With Quote
Old 22/04/2015, 12:56 AM   #7
[KHK]Khalid
Gangsta
 
[KHK]Khalid's Avatar
 
Join Date: Jan 2012
Location: Alexandria, Egypt
Posts: 854
Reputation: 136
Default Re: Getting ID of Vehicle from file

Fine! I see that you're already assigning the file-id to its variable, then your OnPlayerEnterVehicle code could just be like this:

pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Vehiclefile[256];
    format(Vehiclefile, sizeof(Vehiclefile), "vehicles/Vehicle_%d.ini", vehicleid);
    if(fexist(Vehiclefile))
    {
        Vehicles[i][FILEID] = dini_Int(Vehiclefile, "FILEID");
        new string[128];
        format(string, sizeof(string), "Car %d", Vehicles[i][FILEID]);
        SendClientMessage(playerid, COLOUR_PURPLE, string);
    }
    return 1;
}

Though, I have some notes on your code:

1. Isn't 256 too much for your strings? Have you done your measurement or you're just dropping numbers? Stop wasting memory! Also why more strings when could be less, for example:

Instead of this:
pawn Code:
new Vehiclefile[256];
format(Vehiclefile, sizeof(Vehiclefile), "vehicles/Vehicle_%d.ini", vehicleid);
if(fexist(Vehiclefile))
{
    Vehicles[i][FILEID] = dini_Int(Vehiclefile, "FILEID");
    new string[128];
    format(string, sizeof(string), "Car %d", Vehicles[i][FILEID]);
    SendClientMessage(playerid, COLOUR_PURPLE, string);
}

You could do this, you can format strings twice and more if you want (unless you're gonna need to use them later):
pawn Code:
new string[appropriate size here for both uses];
format(string, sizeof(string), "vehicles/Vehicle_%d.ini", vehicleid);
if(fexist(string))
{
    Vehicles[i][FILEID] = dini_Int(string, "FILEID");
    format(string, sizeof(string), "Car %d", Vehicles[i][FILEID]);
    SendClientMessage(playerid, COLOUR_PURPLE, string);
}

2. I have a feeling that you will probably face other problems in the future by the look of this:

pawn Code:
SpawnedVehicles++;
new id = SpawnedVehicles;
new Vehiclefile[256];
format(Vehiclefile, sizeof(Vehiclefile), "vehicles/Vehicle_%d.ini", id);

I think you're mixing up vehicle FileIDs and in-game vehicleids, however I could be wrong, it's your system anyway and you should know better.
[KHK]Khalid is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing a vehicle file cloudysky Scripting Help 1 21/04/2015 03:09 AM
Create a file to each vehicle Lirbo Scripting Help 0 04/06/2014 07:50 PM
Need help with vehicle loading from file. titanak Scripting Help 3 21/04/2012 07:37 PM
[FilterScript] [FS] File Cars - Vehicle File Storing System! lavamike Filterscripts 11 27/08/2010 11:02 PM
Vehicle Position from File Mike Garber Help Archive 0 18/06/2010 06:43 PM


All times are GMT. The time now is 11:22 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.