Help with vehicle system. -
thefatshizms - 08.01.2013
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?
Re: Help with vehicle system. -
Alternative112 - 08.01.2013
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.
Re: Help with vehicle system. -
thefatshizms - 09.01.2013
No, It's not there, it's in OnPlayerStateChange. And i know it all starts with a lowercase v.
Re: Help with vehicle system. -
thefatshizms - 11.01.2013
Bump
Re: Help with vehicle system. -
LarzI - 11.01.2013
Use format instead of normal assignment.
Re: Help with vehicle system. -
thefatshizms - 11.01.2013
How would I do that? Not used that method before (I think unless im thinking of something else)
Re: Help with vehicle system. -
park4bmx - 11.01.2013
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);
Re: Help with vehicle system. -
LarzI - 11.01.2013
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.
Re: Help with vehicle system. -
thefatshizms - 11.01.2013
Ah ok thanks, thought it was this. I'll do it in the morning now as I'm tired as hell.
Re: Help with vehicle system. -
Threshold - 12.01.2013
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.