Vehicle system: Check Owner data
#1

Hello. I have made a script which will load seperate files of a player. It seems to read the file and spawn the car, but I can't make it compare the owner's name with the user's name, if you get what I mean.

I want it to send you a message if you enter your OWN car.

I am currently using this code:

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{  
new pname[255];
   
    for(new i; i < sizeof(COwnerData); i++)
    {

    if(COwnerData[i][CarOwner] == GetPlayerName(playerid, pname, sizeof(pname))) {
    SendClientMessage(playerid, COLOR_WHITE, "You entered your own car.");
        }
    }
It doesn't work. So basically I want it to check if you're the owner of that car. It doesn't give errors, it compiles successfully.

I hope you can help me.
Reply
#2

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
   
    for(new a = 0; a < sizeof(COwnerData); i++)
    {
        /* I assume you place all the owned vehicles in an array ?
           For example COwnerData[i][VehicleID] = CreateVehicle(..)
           This is needed or you won't be able to find the vehicleid
           from the index, you will need to do this under OnFilterScrit/GameModeInit
           Upon every sucessfull load of a file, using sscanf is a good idea for lots of data
        */

       
        if(COwnerData[i][VehicleID] == vehicleid)
        {
            if(!strcmp(PlayerName, COwnerData[i][CarOwner], false))
            {
                SendClientMessage(playerid, COLOR_WHITE, "This is your vehicle, bro!");
                return 1;
            }
            // Here is if the vehicleid is a owned vehicle and not the players.
            // It would be bes to only create owned vehicles and not, not-owned vehicles
            // It then would be much easier to find if the vehicle is owned or not.
            // Assuming you have vehicles that are not owned aswell
            // I will use as an example, that CarOwner is named "none" if nobody owns it.
            // You will have to use an extra strcmp check if you have un owned and owned vehicles.
           
            if(strcmp(COwnerData[i][CarOwner], "none", true))
            {
                SendClientMessage(playerid, COLOR_WHITE, "This vehicle is owned because the owners name was not NONE.");
                return 1;
            }
           
            // Remember to ban the name none, this is why I recommend only having brought vehicles! :D
            // Otherwise, if you do use my method, only having brought vehicles, so there are no for-sale vehicles
            // Simply do not use the none strcmp check and place this directly under the closing bracket after the first STRCMP.

            return SendClientMessage(playerid, COLOR_WHITE, "Y0 dawg, stup strealinz shitz");
        }
        // The vehicle is not a ownership vehicle because the vehicleid was not inserted into the array
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by Joe_
Посмотреть сообщение
[...]
It works, thank you. But I don't understand why you touched the loop, it was fine already. I changed that back to i'. It works fine, thank you. I already thought I made a mistake by not making it check for the vehicleID. And yes, I did add COwner[i][VehicleID] = blabla.

Thanks for your help once again.
Reply
#4

There was no problem with the loop, I wrote it out from scratch and I just use A as my loop lol.

Oh right, yes the varible had to be I not A, sorry.

Hope you understand how it works.
Reply
#5

Remember that if the owner variable doesn't contain anything (""), strcmp will return 0 even if the strings don't match
Reply
#6

Thanks, Lenny.
----

At the moment I have an other question, because I don't really have an idea how to make this properly.
I want the car to be spawned if the owner logs in. Except if the owner is "ForSale".

At the login function I added this command, but yeah, as soon as one player logs in, all cars will be spawned.
Tried to add at OnGameModeInit a check if the carowner logs in by using this:
pawn Код:
if(IsPlayerConnected(!strcmp(PlayerName, COwnerData[i][CarOwner], false))
(Just to give you an expression of what I mean)

I have to create different, forgot how it's called; 'CreateVehicles' for the exception, right?
But how do I do that.

I hope you can answer these two questions

Thank you.

Edit:
I'm using this to spawn the vehicles:
pawn Код:
for(new i; i < sizeof(COwnerData); i++)
{
COwnerData[i][CarID] = CreateVehicle(blablalba);
}
Reply
#7

Just make sure noone logs in with the name "ForSale" and you won't need to check it
Reply
#8

Quote:
Originally Posted by Lenny the Cup
Посмотреть сообщение
Just make sure noone logs in with the name "ForSale" and you won't need to check it
You don't get what I meant,

I mean, I want the vehicles to spawn once the owner logs on. It's not clear for me how to do that.
And, if the owner name is "ForSale", it doesn't have to check if the owner logs on. It'll automatically spawn the ForSale cars.
Reply
#9

Simple, use this query:
SELECT * FROM `vehicles` WHERE `owner` = Player_name_here
then do a while loop for fetching all the rows, spawning the cars
Reply
#10

Quote:
Originally Posted by Joe_
Посмотреть сообщение
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
   
    for(new a = 0; a < sizeof(COwnerData); i++)
    {
        /* I assume you place all the owned vehicles in an array ?
           For example COwnerData[i][VehicleID] = CreateVehicle(..)
           This is needed or you won't be able to find the vehicleid
           from the index, you will need to do this under OnFilterScrit/GameModeInit
           Upon every sucessfull load of a file, using sscanf is a good idea for lots of data
        */

       
        if(COwnerData[i][VehicleID] == vehicleid)
        {
            if(!strcmp(PlayerName, COwnerData[i][CarOwner], false))
            {
                SendClientMessage(playerid, COLOR_WHITE, "This is your vehicle, bro!");
                return 1;
            }
            // Here is if the vehicleid is a owned vehicle and not the players.
            // It would be bes to only create owned vehicles and not, not-owned vehicles
            // It then would be much easier to find if the vehicle is owned or not.
            // Assuming you have vehicles that are not owned aswell
            // I will use as an example, that CarOwner is named "none" if nobody owns it.
            // You will have to use an extra strcmp check if you have un owned and owned vehicles.
           
            if(strcmp(COwnerData[i][CarOwner], "none", true))
            {
                SendClientMessage(playerid, COLOR_WHITE, "This vehicle is owned because the owners name was not NONE.");
                return 1;
            }
           
            // Remember to ban the name none, this is why I recommend only having brought vehicles! :D
            // Otherwise, if you do use my method, only having brought vehicles, so there are no for-sale vehicles
            // Simply do not use the none strcmp check and place this directly under the closing bracket after the first STRCMP.

            return SendClientMessage(playerid, COLOR_WHITE, "Y0 dawg, stup strealinz shitz");
        }
        // The vehicle is not a ownership vehicle because the vehicleid was not inserted into the array
    }
    return 1;
}
Hi,
sorry but I don't understand what I must do with the word "COwnerData", can you help me? Can I have and example?
Thank you in advance.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)