Buy vehicles - Stick to username
#1

Hi.

Im trying to do so that if you buy a vehicle at a shop, it will stick to your username, but i'm having a bit of troubles saving / checking the usernames.
Here's what i got so far, i hope someone can help me:

Buy vehicle:
new buyername[24];
GetPlayerName(playerid,buyername, 24);
boughtcar = CreateVehicle(560, 2174.2114,1421.0642,10.5913,91.0247, -1, -1, 99999999999);
BoughtCarsOwnerName[boughtcar] = buyername[0];


Here's the script where i check if username is the same as current:
Check script:
new name[256];
GetPlayerName(playerid, name, 255);

if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER && BoughtCars[GetPlayerVehicleID(playerid)] == 999 && BoughtCarsOwnerName[GetPlayerVehicleID(playerid)] != name[0]) {
SendClientMessage(playerid,COLOR_YELLOW,"This car has been purchased from AutoBahn. You are not the owner");
format(string, sizeof(string), "This vehicle is registered to player: %s",BoughtCarsOwnerName[GetPlayerVehicleID(playerid)]);
SendClientMessage(playerid, COLOR_YELLOW, string);
RemovePlayerFromVehicle(playerid);


The scripts up there will return the 1 character from the string, but how the **** should i get the usernames stored in a string instead of a array?
Reply
#2

I dont understand that completely but i guess adding another dimension to your array should fix the problem.

pawn Код:
//somewhere on the top
new BoughtCarsOwnerName[MaxAmountOfBoughtCars][MAX_PLAYER_NAME];

//When a vehicle is bought
GetPlayername(playerid, BoughtCarsOwnerName[boughtcar]);
Reply
#3

I understand, but how would you make the check to see if the username matches the current user's username then?
Reply
#4

Maybe a cmd to convert a array into a string?
So that i could do this:
if(BoughtCarsOwnerName[boughtcar] != myUsername) {
SendClientMessage(playerid, "You are not the owner");
}
Reply
#5

Код:
			    	if(GetPlayerMoney(playerid) <= 29999)
					{
			   	    	SendClientMessage(playerid, 0xA9A9A9AA, "|_Car Purchase Failed_|");
			   			SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy a Buffalo ($30000)");
			   			return 1;
					}
			   		new boughtcar;
			   		new buyername[MAX_PLAYER_NAME];
			   		GetPlayerName(playerid,buyername,sizeof(buyername));
         	   		boughtcar = CreateVehicle(402, -1985.3544,304.6387,34.9471,269.2919, -1, -1, 99999999999);
         	   		BoughtCars[boughtcar] =999;
         	   		strmid(BoughtCarsOwner[boughtcar], buyername, 0, strlen(buyername), MAX_PLAYER_NAME);
			   		SendClientMessage(playerid, 0xA9A9A9AA, "|_Car Purchased_|");
			   		SendClientMessage(playerid, 0x00C7FFAA, "You have bought a Buffalo from Wang Cars for $30000");
			   		GivePlayerMoney(playerid,-30000);
			   		PutPlayerInVehicle(playerid, boughtcar, 0);
			   		printf("**(CAR PURCHASE)** %s(%d) has purchased a Buffalo from Wang Cars ($30000)",buyername,playerid);
Код:
    new carstring[256];
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vehid = GetPlayerVehicleID(playerid);
        if(BoughtCars[vehid] == 999) 
        {
            new pName[MAX_PLAYER_NAME];
            GetPlayerName(playerid, pName, sizeof(pName));
            if(strcmp(BoughtCarsOwner[vehid], pName, false))
            {
                format(carstring, sizeof(carstring), "This vehicle has been bought by and is registered to: %s", BoughtCarsOwner[vehid]);
                SendClientMessage(playerid, COLOR_YELLOW, carstring);
                SendClientMessage(playerid, COLOR_YELLOW, "You can not drive it.");
                RemovePlayerFromVehicle(playerid);
            }
        }
    }
It's me Geso, you might remember me from lsrcr, ive got the same system out of lvrcr, just use the system above. As long as i used it, it's perfect.
Reply
#6

Quote:
Originally Posted by Geso
Посмотреть сообщение
Код:
			    	if(GetPlayerMoney(playerid) <= 29999)
					{
			   	    	SendClientMessage(playerid, 0xA9A9A9AA, "|_Car Purchase Failed_|");
			   			SendClientMessage(playerid, COLOR_ERROR, "You cannot afford to buy a Buffalo ($30000)");
			   			return 1;
					}
			   		new boughtcar;
			   		new buyername[MAX_PLAYER_NAME];
			   		GetPlayerName(playerid,buyername,sizeof(buyername));
         	   		boughtcar = CreateVehicle(402, -1985.3544,304.6387,34.9471,269.2919, -1, -1, 99999999999);
         	   		BoughtCars[boughtcar] =999;
         	   		strmid(BoughtCarsOwner[boughtcar], buyername, 0, strlen(buyername), MAX_PLAYER_NAME);
			   		SendClientMessage(playerid, 0xA9A9A9AA, "|_Car Purchased_|");
			   		SendClientMessage(playerid, 0x00C7FFAA, "You have bought a Buffalo from Wang Cars for $30000");
			   		GivePlayerMoney(playerid,-30000);
			   		PutPlayerInVehicle(playerid, boughtcar, 0);
			   		printf("**(CAR PURCHASE)** %s(%d) has purchased a Buffalo from Wang Cars ($30000)",buyername,playerid);
Код:
    new carstring[256];
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vehid = GetPlayerVehicleID(playerid);
        if(BoughtCars[vehid] == 999) 
        {
            new pName[MAX_PLAYER_NAME];
            GetPlayerName(playerid, pName, sizeof(pName));
            if(strcmp(BoughtCarsOwner[vehid], pName, false))
            {
                format(carstring, sizeof(carstring), "This vehicle has been bought by and is registered to: %s", BoughtCarsOwner[vehid]);
                SendClientMessage(playerid, COLOR_YELLOW, carstring);
                SendClientMessage(playerid, COLOR_YELLOW, "You can not drive it.");
                RemovePlayerFromVehicle(playerid);
            }
        }
    }
It's me Geso, you might remember me from lsrcr, ive got the same system out of lvrcr, just use the system above. As long as i used it, it's perfect.
Almost forgot some thing:

Код:
new BoughtCarsOwner[MAX_VEHICLES][MAX_PLAYER_NAME];
Contact me if you need the OnVehicleDeath code too..
Reply
#7

You can't compare strings like that. Use strcmp.

pawn Код:
if(strcmp(BoughtCarsOwnerName[boughtcar], buyername) == 0)
https://sampwiki.blast.hk/wiki/Strcmp
Reply
#8

Hey Geso

This actually looks like it is working.
Browsing trough the code you wrote actually makes it alot more simple than the way i thought of it.

Thank you all for helping
Reply
#9

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
You can't compare strings like that. Use strcmp.

pawn Код:
if(strcmp(BoughtCarsOwnerName[boughtcar], buyername) == 0)
https://sampwiki.blast.hk/wiki/Strcmp
Why would I use that, if my snippet works?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)