Help with vehicle system.
#1

Lets get to the problem shall we?

pawn Код:
new ID = 0;
                    while(ID < sizeof(vehicles) && vehicles[ID])
                    {
                        ID++;
                    }
                    VehicleInfo[ID][owner] = PlayerName(playerid);
                    printf("owner: %s", VehicleInfo[ID][owner]);
                    VehicleInfo[ID][model] = 411;
                    VehicleInfo[ID][value] = 500;
                    VehicleInfo[ID][pannel_damage] = 0;
                    VehicleInfo[ID][door_damage] = 0;
                    VehicleInfo[ID][light_damage] = 0;
                    VehicleInfo[ID][tire_damage] = 0;
                    VehicleInfo[ID][owned] = true;
                    vehicle_creating =ID;
I print out this vehicles owner and it says my name (as i just bought it)


pawn Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        new Vehicleid = GetPlayerVehicleID(playerid);
        printf("vehicle owned by: %s", VehicleInfo[Vehicleid][owner]);
        if(!strcmp(VehicleInfo[Vehicleid][owner], PlayerName(playerid), true))
        {
            SendClientMessage(playerid, -1, "This is not your vehicle");
            RemovePlayerFromVehicle(playerid);
        }
    }
I'm now checking if its my car, for some reason it would always kick me, so i added the print line and printed the vehicles owner variable and it returned nothing (null)

So what am i doing wrong?
Reply
#2

Assuming the second part is something like OnPlayerEnterVehicle....

Код:
 if(!strcmp(VehicleInfo[Vehicleid][owner], PlayerName(playerid), true))
you have a capital V in Vehicleid, all callbacks for cars use a lowercase.
Reply
#3

No, It's not there, it's in OnPlayerStateChange. And i know it all starts with a lowercase v.
Reply
#4

Bump
Reply
#5

Use format instead of normal assignment.
Reply
#6

How would I do that? Not used that method before (I think unless im thinking of something else)
Reply
#7

A string needs to be formatted !
edit
pawn Код:
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid,pname,sizeof pname);
format(VehicleInfo[ID][owner],sizeof(MAX_PLAYER_NAME), pname);
Reply
#8

Instead of this:
pawn Код:
VehicleInfo[ID][owner] = PlayerName(playerid);
Do this:
pawn Код:
format( VehicleInfo[ ID ][ owner ], sizeof( VehicleInfo[ ID ][ owner ] ), "%s", PlayerName( playerid ));
//the spacing is not necessary, it's just how I indent my code to keep it tidy. Personal preference.
Reply
#9

Ah ok thanks, thought it was this. I'll do it in the morning now as I'm tired as hell.
Reply
#10

pawn Код:
new ID = 0;
                    while(ID < sizeof(vehicles) && vehicles[ID])
                    {
                        ID++;
                    }
                    format(VehicleInfo[ID][owner], MAX_PLAYER_NAME, "%s", PlayerName(playerid));
                    printf("owner: %s", VehicleInfo[ID][owner]);
                    VehicleInfo[ID][model] = 411;
                    VehicleInfo[ID][value] = 500;
                    VehicleInfo[ID][pannel_damage] = 0;
                    VehicleInfo[ID][door_damage] = 0;
                    VehicleInfo[ID][light_damage] = 0;
                    VehicleInfo[ID][tire_damage] = 0;
                    VehicleInfo[ID][owned] = true;
                    vehicle_creating =ID;
pawn Код:
if(oldstate == PLAYER_STATE_ONFOOT && (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER))
    {
        new Vehicleid = GetPlayerVehicleID(playerid);
        printf("vehicle owned by: %s", VehicleInfo[Vehicleid][owner]);
        if(strcmp(VehicleInfo[Vehicleid][owner], PlayerName(playerid), false) != 0)
        {
            SendClientMessage(playerid, -1, "This is not your vehicle");
            RemovePlayerFromVehicle(playerid);
        }
    }
This would be the right code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)