/veh command dont park
#1

Hey guys i use a nighlife rp edit... My /veh command working perfect but when i /apark or /park the vehicle it is disappeared... Can someone help me? Here is the commands:
Код:
	if(strcmp(cmd, "/veh", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
	    if (PlayerInfo[playerid][pAdmin] < 4)
			{
			  SendClientMessage(playerid, COLOR_GRAD1, "  you are not authorized to use that command!");
			  return 1;
			}
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
				return 1;
			}
			new car;
			car = strval(tmp);
			if(car < 400 || car > 611) { SendClientMessage(playerid, COLOR_GREY, "  Vehicle Number can't be below 400 or above 611 !"); return 1; }
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
				return 1;
			}
			new color1;
			color1 = strval(tmp);
			if(color1 < 0 || color1 > 126) { SendClientMessage(playerid, COLOR_GREY, "  Color Number can't be below 0 or above 126 !"); return 1; }
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
				return 1;
			}
			new color2;
			color2 = strval(tmp);
			if(color2 < 0 || color2 > 126) { SendClientMessage(playerid, COLOR_GREY, "  Color Number can't be below 0 or above 126 !"); return 1; }
			new Float:X,Float:Y,Float:Z;
			GetPlayerPos(playerid, X,Y,Z);
			new carid = CreateVehicle(car, X,Y,Z, 0.0, color1, color2, 60000);
			CreatedCars[CreatedCar] = carid;
			CreatedCar ++;
			format(string, sizeof(string), "  Vehicle %d spawned.", carid);
			SendClientMessage(playerid, COLOR_GREY, string);
		}
		return 1;
	}

Код:
	if(strcmp(cmd, "/apark", true) == 0)
	{
		if(IsPlayerConnected(playerid))
 		{
			new Float:x,Float:y,Float:z;
			new Float:a;
			new carid;
			carid = GetPlayerVehicleID(playerid);
			GetPlayerName(playerid, playername, sizeof(playername));
			GetVehiclePos(carid, x, y, z);
//			GetPlayerFacingAngle(playerid, a);
			GetVehicleZAngle(carid, a);
			if(PlayerInfo[playerid][pAdmin] >= 3)
			{
				CarInfo[carid][cLocationx] = x;
				CarInfo[carid][cLocationy] = y;
				CarInfo[carid][cLocationz] = z;
				CarInfo[carid][cAngle] = a;
				format(string, sizeof(string), "~n~ You have parked your car in this location. ~n~");
				GameTextForPlayer(playerid, "You have parked this car in this position. It will respawn here.", 10000, 3);
				OnPropUpdate();
				OnPlayerUpdate(playerid);
	  		DestroyVehicle(carid);
	  		CreateVehicle(CarInfo[carid][cModel],CarInfo[carid][cLocationx],CarInfo[carid][cLocationy],CarInfo[carid][cLocationz]+1.0,CarInfo[carid][cAngle],CarInfo[carid][cColorOne],CarInfo[carid][cColorTwo],60000);
				return 1;
			}
			else
			{
			  SendClientMessage(playerid, COLOR_GREY, "  You are not authorized to use that command !");
			  return 1;
			}
		}
		return 1;
	}

Reply
#2

Well.
I am still learning, but know some things and some I don't about pawn.
With /veh, I to have had troubles with this and still don't achieve it.

But I think that only vehicles you add into the gamemode pawn can be parked.
Because those vehicles are assigned an ID.
But for /veh, it doesnt assign an ID to each vehicle.
Thats how I see it.

You could do /veh and it saves the vehicle to a file and then you can do /apark and it updates/saves the vehicles position.
But like I said, I am still learning so I don't know how to create the file and save.
Reply
#3

pawn Код:
if(strcmp(cmd, "/veh", true) == 0)
    {
      if(IsPlayerConnected(playerid))
      {
        if (PlayerInfo[playerid][pAdmin] < 4)
            {
              SendClientMessage(playerid, COLOR_GRAD1, "  you are not authorized to use that command!");
              return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
                return 1;
            }
            new car;
            car = strval(tmp);
            if(car < 400 || car > 611) { SendClientMessage(playerid, COLOR_GREY, "  Vehicle Number can't be below 400 or above 611 !"); return 1; }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
                return 1;
            }
            new color1;
            color1 = strval(tmp);
            if(color1 < 0 || color1 > 126) { SendClientMessage(playerid, COLOR_GREY, "  Color Number can't be below 0 or above 126 !"); return 1; }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
                return 1;
            }
            new color2;
            color2 = strval(tmp);
            if(color2 < 0 || color2 > 126) { SendClientMessage(playerid, COLOR_GREY, "  Color Number can't be below 0 or above 126 !"); return 1; }
            new Float:X,Float:Y,Float:Z;
            GetPlayerPos(playerid, X,Y,Z);
            new carid;
            carid = CreateVehicle(car, X,Y,Z, 0.0, color1, color2, 60000);
            CreatedCars[CreatedCar] = carid;
            CreatedCar ++;
            format(string, sizeof(string), "  Vehicle %d spawned.", carid);
            SendClientMessage(playerid, COLOR_GREY, string);
        }
        return 1;
    }
Try it?
Reply
#4

It worked bro thank you! I have 1 more question is it possible to add cars in cars.cfg file?
Reply
#5

Quote:
Originally Posted by RichyB
But I think that only vehicles you add into the gamemode pawn can be parked.
Because those vehicles are assigned an ID.
But for /veh, it doesnt assign an ID to each vehicle.
Thats how I see it.
You are very wrong. Once a vehicle is created, It's assigned an ID.
Reply
#6

NP and search it, I can only say those but 0% sure about /apark part

Add this to top of your GM (near defines)
Код:
new File:ParkedCars;
And this
Код:
if(!fexist("CarParked.txt")) ParkedCars = fopen("CarParked.txt", io_readwrite);
else if(fexist("CarParked.txt")) ParkedCars = fopen("CarParked.txt", io_append);
inside OnGamemodeInit

Use this command
Код:
	if(strcmp(cmd, "/apark", true) == 0)
	{
		if(IsPlayerConnected(playerid))
 		{
			new Float:x,Float:y,Float:z;
			new Float:a;
			new carid;
			carid = GetPlayerVehicleID(playerid);
			GetPlayerName(playerid, playername, sizeof(playername));
			GetVehiclePos(carid, x, y, z);
			GetVehicleZAngle(carid, a);
			if(PlayerInfo[playerid][pAdmin] >= 3)
			{
				CarInfo[carid][cLocationx] = x;
				CarInfo[carid][cLocationy] = y;
				CarInfo[carid][cLocationz] = z;
				CarInfo[carid][cAngle] = a;
				format(string, sizeof(string), "~n~ You have parked your car in this location. ~n~");
				GameTextForPlayer(playerid, "You have parked this car in this position. It will respawn here.", 10000, 3);
				OnPropUpdate();
				OnPlayerUpdate(playerid);
	  		DestroyVehicle(carid);
                ParkedCars = fopen("CarParked.txt", io_append);
                format(string, sizeof(string), "%d,%d,%d,%d,%d,%d,%d;",CarInfo[carid][cModel],CarInfo[carid][cLocationx],CarInfo[carid][cLocationy],CarInfo[carid][cLocationz]+1.0,CarInfo[carid][cAngle],CarInfo[carid][cColorOne],CarInfo[carid][cColorTwo]);
                fwrite(ParkedCars, string);
                fclose(ParkedCars);                                                     
	  		CreateVehicle(CarInfo[carid][cModel],CarInfo[carid][cLocationx],CarInfo[carid][cLocationy],CarInfo[carid][cLocationz]+1.0,CarInfo[carid][cAngle],CarInfo[carid][cColorOne],CarInfo[carid][cColorTwo],60000);
				return 1;
			}
			else
			{
			  SendClientMessage(playerid, COLOR_GREY, "  You are not authorized to use that command !");
			  return 1;
			}
		}
		return 1;
	}
Then copy this to bottom of your script
Код:
stock LoadStaticVehiclesFromFile(const filename[])
{
	new File:file_ptr;
	new line[256];
	new var_from_line[64];
	new vehicletype;
	new Float:SpawnX;
	new Float:SpawnY;
	new Float:SpawnZ;
	new Float:SpawnRot;
  new Color1, Color2;
	new index;
	new vehicles_loaded;

	file_ptr = fopen(filename,filemode:io_read);
	if(!file_ptr) return 0;

	vehicles_loaded = 0;

	while(fread(file_ptr,line,256) > 0)
	{
	  index = 0;

 		index = token_by_delim(line,var_from_line,',',index);
 		if(index == (-1)) continue;
 		vehicletype = strval(var_from_line);
  		if(vehicletype < 400 || vehicletype > 611) continue;

 		index = token_by_delim(line,var_from_line,',',index+1);
 		if(index == (-1)) continue;
 		SpawnX = floatstr(var_from_line);

 		index = token_by_delim(line,var_from_line,',',index+1);
 		if(index == (-1)) continue;
 		SpawnY = floatstr(var_from_line);

 		index = token_by_delim(line,var_from_line,',',index+1);
 		if(index == (-1)) continue;
 		SpawnZ = floatstr(var_from_line);

 		index = token_by_delim(line,var_from_line,',',index+1);
 		if(index == (-1)) continue;
 		SpawnRot = floatstr(var_from_line);

 		index = token_by_delim(line,var_from_line,',',index+1);
 		if(index == (-1)) continue;
 		Color1 = strval(var_from_line);

 		index = token_by_delim(line,var_from_line,';',index+1);
 		Color2 = strval(var_from_line);

		AddStaticVehicleEx(vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2,(30*60));
		vehicles_loaded++;
	}

	fclose(file_ptr);
	printf("Loaded %d vehicles total",vehicles_loaded);
	return vehicles_loaded;
}

stock token_by_delim(const string[], return_str[], delim, start_index)
{
	new x=0;
	while(string[start_index] != EOS && string[start_index] != delim) {
	  return_str[x] = string[start_index];
	  x++;
	  start_index++;
	}
	return_str[x] = EOS;
	if(string[start_index] == EOS) start_index = (-1);
	return start_index;
}
And
Код:
LoadStaticVehiclesFromFile("CarParked.txt");
to your OnGamemodeInit

And create CarParked.txt in your scriptfiles to save them And get a backup of your GM so if it breaks dont flame at me

So when you reset your GM / server cars will stay in their positions!
Reply
#7

I said 0% about /apark and it is really 0%, if you get errors post em here and I can help and if it works "OMGROFL im awsum "
Reply
#8

no errors but dont load:\ This is written in file:
Quote:

0,1157322356,-998992438,1108424020,1129668028,36,1;

But it dont spawn
Reply
#9

Only colors work :S Lemme check it again
Код:
	if(strcmp(cmd, "/apark", true) == 0)
	{
		if(IsPlayerConnected(playerid))
 		{
			new Float:x,Float:y,Float:z;
			new Float:a;
			new carid;
			carid = GetPlayerVehicleID(playerid);
			GetPlayerName(playerid, playername, sizeof(playername));
			GetVehiclePos(carid, x, y, z);
			GetVehicleZAngle(carid, a);
			if(PlayerInfo[playerid][pAdmin] >= 3)
			{
				CarInfo[carid][cLocationx] = x;
				CarInfo[carid][cLocationy] = y;
				CarInfo[carid][cLocationz] = z;
				CarInfo[carid][cAngle] = a;
				format(string, sizeof(string), "~n~ You have parked your car in this location. ~n~");
				GameTextForPlayer(playerid, "You have parked this car in this position. It will respawn here.", 10000, 3);
				OnPropUpdate();
				OnPlayerUpdate(playerid);
	  		DestroyVehicle(carid);
                ParkedCars = fopen("CarParked.txt", io_append);
                format(string, sizeof(string), "%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f;",CarInfo[carid][cModel],CarInfo[carid][cLocationx],CarInfo[carid][cLocationy],CarInfo[carid][cLocationz],CarInfo[carid][cAngle],CarInfo[carid][cColorOne],CarInfo[carid][cColorTwo]);
                fwrite(ParkedCars, string);
                fclose(ParkedCars);                                                     
	  		CreateVehicle(CarInfo[carid][cModel],CarInfo[carid][cLocationx],CarInfo[carid][cLocationy],CarInfo[carid][cLocationz]+1.0,CarInfo[carid][cAngle],CarInfo[carid][cColorOne],CarInfo[carid][cColorTwo],60000);
				return 1;
			}
			else
			{
			  SendClientMessage(playerid, COLOR_GREY, "  You are not authorized to use that command !");
			  return 1;
			}
		}
		return 1;
	}
Not sure again
Reply
#10

Still doesnt work! Np bro thank you fro trying Do you got a MSN? if you want send it with PM
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)