SA-MP Forums Archive
Who owns what car? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Who owns what car? (/showthread.php?tid=500410)



Who owns what car? - jeffery30162 - 13.03.2014

I am creating a Car system.

When the player changes state if he doesn't own the car i want him not to be able to drive it.

in Onplayerstate change to driver state i put this:
Код:
new Owner[128] = CarInfo[idx][cOwner];
   		 GetPlayerName(playerid, name, sizeof(name));
		if(Owner == name)
		{
		SendClientMessage(playerid, COLOR_RED, "YOU DO NOT OWN THIS CAR");
		return 0;
		}
what do i do to get this to work

here is my car enum:
Код:
enum carInfo
{
	cStatus,
	cOwner[32],
	Float:cX,
	Float:cY,
	Float:cZ,
	Float:cAngle,
	cModel,
	cColor1,
	cColor2,
	Text3D:bText,
	cMod1,
	cMod2,
	cMod3,
	cMod4,
	cMod5,
 	cMod6
}
new CarInfo[MAX_CAR][carInfo];
please help me


Re: Who owns what car? - nmader - 13.03.2014

Perhaps,
pawn Код:
RemovePlayerFromVehicle(playerid);
You also may want to change Return 0; to Return 1; Return 0 will remove all functions in that bit of code, if I am not mistaken. Meaning it will not return any values.


Re: Who owns what car? - Ceathor - 13.03.2014

pawn Код:
new Owner[128] = CarInfo[idx][cOwner]; // Why do you create a string[128] for inserting one of size 32? Also why declare this at all? Just a waste of resources. Use it directly for optimization.
         GetPlayerName(playerid, name, sizeof(name));
        if(Owner == name) // You need to use strcmp to compare strings, you cannot use ==. Also, you want to use != to evict them if they DON'T own the vehicle
        {
        SendClientMessage(playerid, COLOR_RED, "YOU DO NOT OWN THIS CAR");
                // This would be a good place to use RemovePlayerFromVehicle.
        return 0; // You don't want to return 0 here. Return 1.
        }
Meaning your code should look somewhat like this:

pawn Код:
GetPlayerName(playerid, name, sizeof(name));
if(strcmp(CarInfo[idx][cOwner], name, false) != 0)
{
    SendClientMessage(playerid, COLOR_RED, "YOU DO NOT OWN THIS CAR");
    RemovePlayerFromVehicle(playerid);
    return 1;
}



Re: Who owns what car? - jeffery30162 - 13.03.2014

Thanks this works great