SA-MP Forums Archive
Some annoying bug - 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: Some annoying bug (/showthread.php?tid=576010)



Some annoying bug - suni - 31.05.2015

anytimes a player type /nrg or /car, it created. then when a other player type one of the following commands, it destroy the player who spawned the vehicle first and that vehicle create to the second player. i dont know if it is a bug between id 0 and id 1. but it's totally annoying my server. it seen like i cant fix it.


Re: Some annoying bug - Jakwob - 31.05.2015

Show the command


Re: Some annoying bug - Konstantinos - 31.05.2015

It seems to me that you use a global variable (not array [per-player]) to store the vehicle ID and that can only hold one value.

Another reason could be that you indeed use an array as it's supposed to but you never reset the variable when the vehicle is destroyed.


Re: Some annoying bug - suni - 31.05.2015

Код:
CMD:nrg(playerid, params[])
{
    new Float:x, Float:y, Float:z, Float:angle;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, angle);
    if(PlayerAcc[playerid][Log] == 0) return SendClientMessage(playerid, COLOR_RED, "Error: You are not logged in!");
	{
		if(CarId[playerid] != INVALID_VEHICLE_ID) DestroyVehicle(CarId[playerid]);
	    CarId[playerid] = CreateVehicle(522, x, y, z, angle, -1, -1, 6000);
		PutPlayerInVehicle(playerid, CarId[playerid], 0);
	    SendClientMessage(playerid, COLOR_LIME, "You spawn an nrg!");
	}
	return 1;
}

CMD:car(playerid, params[])
{
    new Float:x, Float:y, Float:z, Float:angle;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, angle);
    if(PlayerAcc[playerid][Log] == 0) return SendClientMessage(playerid, COLOR_RED, "Error: You are not logged in!");
	{
		if(CarId[playerid] != INVALID_VEHICLE_ID) DestroyVehicle(CarId[playerid]);
	    CarId[playerid] = CreateVehicle(411, x, y, z, angle, -1, -1, 6000);
		PutPlayerInVehicle(playerid, CarId[playerid], 0);
	    SendClientMessage(playerid, COLOR_LIME, "You spawn an infernus!");
	}
	return 1;
}
Код:
CMD:v(playerid, params[])
{
	new string[128], vID[32], vid, Float:x, Float:y, Float:z, Float:ang;
	if(sscanf(params, "s[32]", vID)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /v (carname)");
	if(isnumeric(vID)) vid = strval(vID);
	else vid = GetVehicleModelIDFromName(vID);
	if (vid < 400 || vid > 611) return SendClientMessage(playerid, COLOR_RED, "Vehicle ID Maxium (Left): 400 - Maxium (Right): 611");
	GetPlayerPos(playerid,x,y,z);
	GetPlayerFacingAngle(playerid,ang);
	if(CarId[playerid] != INVALID_VEHICLE_ID) DestroyVehicle(CarId[playerid]);
	CarId[playerid] = CreateVehicle(vid, x, y, z, ang, -1, -1, 6000);
	LinkVehicleToInterior(CarId[playerid], GetPlayerInterior(playerid));
	SetVehicleVirtualWorld(CarId[playerid], GetPlayerVirtualWorld(playerid));
	PutPlayerInVehicle(playerid, CarId[playerid], 0);
	format(string, sizeof(string), "You've spawned vehicle id %i - %s", vid, VehicleName[vid - 400]);
	SendClientMessage(playerid, COLOR_YELLOW, string);
	return 1;
}
and some dialog bug

when im in a vehicle and i type a command that display a message dialog, when i click on ok or press esc, my vehicle destroy


Re: Some annoying bug - Konstantinos - 31.05.2015

It's the second reason I mentioned.

Player A spawns a vehicle with vehicle ID 1.
Player A's vehicle gets destroyed.
Player B spawns a vehicle with ID 1.
Player A spawns a vehicle with vehicle ID 2 but the server destroys Player B's vehicle as the variable was never reset (previous vehicle of Player A was the vehicle with ID 1).

Whenever the vehicle is destroyed, find who player had it stored and reset the variable CarId[playerid] to INVALID_VEHICLE_ID.


Re: Some annoying bug - suni - 31.05.2015

is there a way to solve it?


Re: Some annoying bug - amirm3hdi - 31.05.2015

Код:
new PlayerVehicle[MAX_PLAYERS];

DestroyVehicle(PlayerVehicle[playerid]);
PlayerVehicle[playerid] = CreateVehicle(...);



Re: Some annoying bug - SoFahim - 31.05.2015

Delete this code from the cmds

Код:
DestroyVehicle(CarId[playerid]



Re: Some annoying bug - suni - 31.05.2015

Quote:
Originally Posted by SoFahim
Посмотреть сообщение
Delete this code from the cmds

Код:
DestroyVehicle(CarId[playerid]
so replace that code with this?

Код:
DestroyVehicle(PlayerVehicle[playerid]);



Re: Some annoying bug - SoFahim - 31.05.2015

Quote:
Originally Posted by suni
Посмотреть сообщение
so replace that code with this?

Код:
DestroyVehicle(PlayerVehicle[playerid]);
Delete this code for avoid destroy spawned car destroy