Car Ownership script help!
#1

Hello!
I am currently trying my best to learn how to script. I downloaded a Roleplay Script called "Raven Roleplay" and in the script there's a bug that, if you buy a car you only get ownership of the car when the server restarts.

Here's the related code:
Код:
new vehid;
				if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { vehid = PlayerInfo[playerid][pPcarkey]; }
				else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { vehid = PlayerInfo[playerid][pPcarkey2]; }
				else { return 1; }
	        	if(IsPlayerInVehicle(playerid, vehid))
	        	{
         			CarInfo[vehid][cColorOne] = color1;
	                CarInfo[vehid][cColorTwo] = color2;
	                new Float:x,Float:y,Float:z;
	                GetPlayerPos(playerid, x,y,z);
	                ChangeVehicleColor(vehid, color1, color2);
	                SafeGivePlayerMoney(playerid, -1000);
	                GameTextForPlayer(playerid, "~w~Bill for a Paint Respray~n~~r~-$1000", 5000, 1);
	                ChangeVehicleColor(vehid, color1, color2);
	                OnPropUpdate(4,vehid);
					OnPlayerUpdateEx(playerid);
					return 1;
    			}
	        	else
	        	{
	            	SendClientMessage(playerid, COLOR_GREY,"   You are not in your vehicle.");
	            	return 1;
	        	}
	        }
	        else if(strcmp(x_nr,"buy",true) == 0)
	        {
	            new car = 1;
	            new model = GetVehicleModel(idcar);
	            if(IsASalesVehicle(idcar))
	            {
	                if(PlayerInfo[playerid][pLevel] < 2)
			    	{
                    	SendClientMessage(playerid, COLOR_GREY, "You need to be level 2 to buy a vehicle!");
                    	return 1;
			    	}
			    	if(PlayerInfo[playerid][pPcarkey] == 9999 || PlayerInfo[playerid][pPcarkey2] == 9999) { }
			    	else return SendClientMessage(playerid, COLOR_GREY,"* You already own Two cars!");
					if(GetPlayerMoney(playerid) >= GetVehiclePrice(idcar))
					{
					    if(PlayerInfo[playerid][pCarLic] == 1)
					    {
							for(new h = 1; h < sizeof(CarInfo); h++)
							{
								if(CarInfo[h][cOwned] == 0)
								{
									car = h;
									h = 9999;
								}
							}
							format(string, sizeof(string),"LARP/Vehicles/%d.ini",car)
							dini_Create(string);
							
							if(PlayerInfo[playerid][pPcarkey] != 9999) { PlayerInfo[playerid][pPcarkey2] = car; }
							else { PlayerInfo[playerid][pPcarkey] = car; }
							CarInfo[car][cOwned] = 1;
							strmid(CarInfo[car][cOwner], sendername, 0, strlen(sendername), 999);
							SafeGivePlayerMoney(playerid,-GetVehiclePrice(idcar));
2nd part:
Код:
	{
                                CarInfo[car][cLocationx] = -1589.2644;
								CarInfo[car][cLocationy] = 106.9119;
								CarInfo[car][cLocationz] = 3.5495;
								CarInfo[car][cAngle] = 317.1649;
								SendClientMessage(playerid, COLOR_YELLOW2, "Your vehicle has been deliveried to San Fierro Docks, you can get it there!");
								SendClientMessage(playerid, COLOR_YELLOW2, "Your vehicle is unlocked so you can pay someone to deliver it to your new spawn point!");
								SendClientMessage(playerid, COLOR_NICERED, "REMEMBER: Leaving your car in the deliver point can get your car SOLD by an administration without refund!");
								GameTextForPlayer(playerid, "~p~Congratulations~n~~w~Don't forget to pickup your car at the ~b~San Fierro Docks!", 5000, 3);
							}
							CarInfo[car][cModel] = model;
							CarInfo[car][cVirWorld] = 0;
							CarInfo[car][cPaintjob] = 999;
							
							CarInfo[car][cColorOne] = 1;
							CarInfo[car][cColorTwo] = 1;
							
							CarInfo[car][cComponent0] = 0;
							CarInfo[car][cComponent1] = 0;
							CarInfo[car][cComponent2] = 0;
							CarInfo[car][cComponent3] = 0;
							CarInfo[car][cComponent4] = 0;
							CarInfo[car][cComponent5] = 0;
							CarInfo[car][cComponent6] = 0;
							CarInfo[car][cComponent7] = 0;
							CarInfo[car][cComponent8] = 0;
							CarInfo[car][cComponent9] = 0;
							CarInfo[car][cComponent10] = 0;
							CarInfo[car][cComponent11] = 0;
							CarInfo[car][cComponent12] = 0;
					    	CarInfo[car][cComponent13] = 0;
							//DestroyVehicle(car);
							ownedcar[car] = CreateVehicle(CarInfo[car][cModel],CarInfo[car][cLocationx],CarInfo[car][cLocationy],CarInfo[car][cLocationz],90.0,1,1,30000);
							PlayerPlayMusic(playerid);
							SendClientMessage(playerid, COLOR_GRAD2, "Congratulations on your new purchase!");
							SendClientMessage(playerid, COLOR_GRAD2, "Type /vehiclehelp to view the vehicle manual!");
							gEngine[playerid] = 0;
							engineOn[GetPlayerVehicleID(playerid)] = false;
							SendClientMessage(playerid, COLOR_GREY, "Remember to set the new Security Code of the Car (/v setcode)!");
							new pass[24];
							format(pass, sizeof(pass),"%d%d%d",random(9),random(9),random(9));
							CarInfo[car][cCode] = strval(pass);
							OnPropUpdate(4,car);
							OnPlayerUpdateEx(playerid);
						}
						else
						{
							SendClientMessage(playerid, COLOR_WHITE, "* For security reasons, a Driving License is needed to buy a car!");
							return 1;
						}
					}
					else
					{
					    SendClientMessage(playerid, COLOR_GREY, "  You don't have enough cash with you ! ");
					    return 1;
					}
	            }
There's also some other code referring to the vehicle database (LARP/vehicle):
Код:
if(dialogid == 19992)
		{
			if(response)
			{
			    new inter = strval(inputtext);
			    format(string, sizeof(string),"LARP/Vehicles/%d.ini",inter);
			    
				if(!dini_Exists(string))
				{
				    SendClientMessage(playerid, COLOR_GREY,"* Unknown File!");
                    ShowPlayerDialog(playerid,19990,DIALOG_STYLE_LIST,"Select which thing do you want to reload","1\tUser file\n2\tVehicle File\n3\tHouse File\n3\tBizz File\n4\tSBizz File","Select","Cancel");
				}
				else
				{
				    OnPropUpdate(4,inter);
				}
			}
		}
Код:
	{
		    if(response)
		    {
		        new ownvehkey;
	            if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { ownvehkey = PlayerInfo[playerid][pPcarkey]; }
                else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { ownvehkey = PlayerInfo[playerid][pPcarkey2]; }
	            new carsellprice = GetVehiclePrice(ownvehkey) / 5;
	            PlayerInfo[playerid][pMats] += carsellprice;
             	PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
	            format(string, sizeof(string), "~w~You have scratched your car for: ~n~~g~%d materials", carsellprice);
	            GameTextForPlayer(playerid, string, 10000, 3);
	            
	            if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey])
					PlayerInfo[playerid][pPcarkey] = 9999;
				else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2])
					PlayerInfo[playerid][pPcarkey2] = 9999;

				SafeRemovePlayerFromVehicle(playerid);
				DestroyVehicle(ownvehkey);
	            TogglePlayerControllable(playerid, 1);
	            
	            format(string, sizeof(string),"LARP/Vehicles/%d.ini",ownvehkey);
         		fremove(string);
	            
	            OnPlayerUpdateEx(playerid);
	            TogglePlayerDynamicCP(playerid, scratchcarcp, 1);
       		}
		}
Код:
public LoadCar()
{
	new file[26];
	for(new idx = 1; idx < sizeof(CarInfo) ; idx++)
	{
	    	format(file, sizeof(file),"LARP/Vehicles/%d.ini", idx);
		 	CarInfo[idx][cModel] = dini_Int(file,"Model");
			CarInfo[idx][cLocationx] = dini_Float(file,"Location_X");
			CarInfo[idx][cLocationy] = dini_Float(file,"Location_Y");
			CarInfo[idx][cLocationz] = dini_Float(file,"Location_Z");
			CarInfo[idx][cAngle] = dini_Float(file,"Angle");
			CarInfo[idx][cColorOne] = dini_Int(file,"Color_1");
			CarInfo[idx][cColorTwo] = dini_Int(file,"Color_2");
			strmid(CarInfo[idx][cOwner], dini_Get(file,"Owner"), 0, strlen(dini_Get(file,"Owner")), 255);
			CarInfo[idx][cOwned] = dini_Int(file,"Owned");
			strmid(CarInfo[idx][cPlate], dini_Get(file,"Plate"), 0, strlen(dini_Get(file,"Plate")), 255);
			CarInfo[idx][cLock] = dini_Int(file,"Locked");
			CarInfo[idx][cID] = dini_Int(file,"ID");
			CarInfo[idx][cPaintjob] = dini_Int(file,"Paintjob");
			CarInfo[idx][cVirWorld] = dini_Int(file,"VirtualWorld");
			CarInfo[idx][cUnused] = dini_Int(file,"Unused");
		   	CarInfo[idx][cComponent0] = dini_Int(file,"Component0");
		   	CarInfo[idx][cComponent1] = dini_Int(file,"Component1");
			CarInfo[idx][cComponent2] = dini_Int(file,"Component2");
			CarInfo[idx][cComponent3] = dini_Int(file,"Component3");
			CarInfo[idx][cComponent4] = dini_Int(file,"Component4");
			CarInfo[idx][cComponent5] = dini_Int(file,"Component5");
			CarInfo[idx][cComponent6] = dini_Int(file,"Component6");
			CarInfo[idx][cComponent7] = dini_Int(file,"Component7");
			CarInfo[idx][cComponent8] = dini_Int(file,"Component8");
			CarInfo[idx][cComponent9] = dini_Int(file,"Component9");
			CarInfo[idx][cComponent10] = dini_Int(file,"Component10");
			CarInfo[idx][cComponent11] = dini_Int(file,"Component11");
			CarInfo[idx][cComponent12] = dini_Int(file,"Component12");
			CarInfo[idx][cComponent13] = dini_Int(file,"Component13");
			CarInfo[idx][cCode] = dini_Int(file,"SecurityCode");
			CarInfo[idx][cParkTicket] = dini_Int(file,"TicketPrice");
			strmid(CarInfo[idx][cTicketer], dini_Get(file,"Officer"), 0, strlen(dini_Get(file,"Officer")), 255);
			CarInfo[idx][cTrunkGun1] = dini_Int(file,"Gun1");
			CarInfo[idx][cTrunkAmmo1] = dini_Int(file,"Ammo1");
			CarInfo[idx][cTrunkGun2] = dini_Int(file,"Gun2");
			CarInfo[idx][cTrunkAmmo2] = dini_Int(file,"Ammo2");
			CarInfo[idx][cTrunkGun3] = dini_Int(file,"Gun3");
			CarInfo[idx][cTrunkAmmo3] = dini_Int(file,"Ammo3");
			CarInfo[idx][cTrunkGun4] = dini_Int(file,"Gun4");
			CarInfo[idx][cTrunkAmmo4] = dini_Int(file,"Ammo4");
			CarInfo[idx][cTrunkGun5] = dini_Int(file,"Gun5");
			CarInfo[idx][cTrunkAmmo5] = dini_Int(file,"Ammo5");
			CarInfo[idx][cTrunkGun6] = dini_Int(file,"Gun6");
			CarInfo[idx][cTrunkAmmo6] = dini_Int(file,"Ammo6");
			CarInfo[idx][cTrunkGun7] = dini_Int(file,"Gun7");
			CarInfo[idx][cTrunkAmmo7] = dini_Int(file,"Ammo7");
			CarInfo[idx][cTrunkGun8] = dini_Int(file,"Gun8");
			CarInfo[idx][cTrunkAmmo8] = dini_Int(file,"Ammo8");
			CarInfo[idx][cTrunkGun9] = dini_Int(file,"Gun9");
			CarInfo[idx][cTrunkAmmo9] = dini_Int(file,"Ammo9");
			CarInfo[idx][cTrunkGun10] = dini_Int(file,"Gun10");
			CarInfo[idx][cTrunkAmmo10] = dini_Int(file,"Ammo10");
			CarInfo[idx][cTrunkGun11] = dini_Int(file,"Gun11");
			CarInfo[idx][cTrunkAmmo11] = dini_Int(file,"Ammo11");
	}
	return 1;
}
Код:
public OnGameModeInit() // Do not add vehicles Above the next lines. - CuervO
{
	ShowPlayerMarkers(2);
	LoadCar();
	new string2[64];
	for(new h = 1; h < sizeof(CarInfo); h++)
	{
		format(string2, sizeof(string2), "LARP/Vehicles/%d.ini",h);
		if(dini_Exists(string2))
		{
			ownedcar[h] = AddStaticVehicleEx(CarInfo[h][cModel],CarInfo[h][cLocationx],CarInfo[h][cLocationy],CarInfo[h][cLocationz]+1.0,CarInfo[h][cAngle],CarInfo[h][cColorOne],CarInfo[h][cColorTwo],60000);
			if(CarInfo[h][cPaintjob] != 999)
			{
				ChangeVehiclePaintjob(h, CarInfo[h][cPaintjob]);
			}
			SetVehicleVirtualWorld(h, CarInfo[h][cVirWorld]);
			SetVehicleModifications(h);
		}
	}
Код:
	{
		format(file, sizeof(file),"LARP/Vehicles/%d.ini",idx);
		if(dini_Exists(file))
		{
			dini_IntSet(file,"Model",CarInfo[idx][cModel]);
			dini_FloatSet(file,"Location_X",CarInfo[idx][cLocationx]);
			dini_FloatSet(file,"Location_Y",CarInfo[idx][cLocationy]);
			dini_FloatSet(file,"Location_Z",CarInfo[idx][cLocationz]);
			dini_FloatSet(file,"Angle",CarInfo[idx][cAngle]);
			dini_IntSet(file,"Color_1",CarInfo[idx][cColorOne]);
			dini_IntSet(file,"Color_2",CarInfo[idx][cColorTwo]);
			dini_Set(file,"Owner",CarInfo[idx][cOwner]);
			dini_IntSet(file,"Owned",CarInfo[idx][cOwned]);
			dini_Set(file,"Plate",CarInfo[idx][cPlate]);
			dini_IntSet(file,"ID",CarInfo[idx][cID]);
			dini_IntSet(file,"Locked",CarInfo[idx][cLock]);
			dini_IntSet(file,"Paintjob",CarInfo[idx][cPaintjob]);
			dini_IntSet(file,"VirtualWorld",CarInfo[idx][cVirWorld]);
			dini_IntSet(file,"Unused",CarInfo[idx][cUnused]);
			dini_IntSet(file,"Component0",CarInfo[idx][cComponent0]);
			dini_IntSet(file,"Component1",CarInfo[idx][cComponent1]);
			dini_IntSet(file,"Component2",CarInfo[idx][cComponent2]);
			dini_IntSet(file,"Component3",CarInfo[idx][cComponent3]);
			dini_IntSet(file,"Component4",CarInfo[idx][cComponent4]);
			dini_IntSet(file,"Component5",CarInfo[idx][cComponent5]);
			dini_IntSet(file,"Component6",CarInfo[idx][cComponent6]);
			dini_IntSet(file,"Component7",CarInfo[idx][cComponent7]);
			dini_IntSet(file,"Component8",CarInfo[idx][cComponent8]);
			dini_IntSet(file,"Component9",CarInfo[idx][cComponent9]);
			dini_IntSet(file,"Component10",CarInfo[idx][cComponent10]);
			dini_IntSet(file,"Component11",CarInfo[idx][cComponent11]);
			dini_IntSet(file,"Component12",CarInfo[idx][cComponent12]);
			dini_IntSet(file,"Component13",CarInfo[idx][cComponent13]);
			dini_IntSet(file,"SecurityCode",CarInfo[idx][cCode]);
		}
 	}
	return 1;
If anyone wanst to help me and wants to edit the file on his own feel free to add me on Steam it would actually be really awesome if someone could do that!

My Steamname is: TheAp4ch3.

Again: if you purchase the vehicle it spawns, though it doesn't have a membership until you restart the server.
Reply
#2

Hello!
A roleplay gamemode isn't the best way to learn to script. ^^
Anyway, give the command (btw with code) you use for buy an vehicle or what do you use for buy a car.
Reply
#3

I'd suggest using another script (possibly not RP?). People think that just because they want to script RP gamemodes they're entitled to learn on one, but that's false when you're doing that you're only learning what you want, not what you need. I'd suggest using the wiki and making a GM from scratch and use sources.
Reply
#4

^^ This guy speaks the truth, even though seeing examples of how things are done in those kind of gamemode is "cool", it also leads to pure copy paste without understanding the code, and leads to breakages and errors.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)