SA-MP Forums Archive
Getting problem with playerid (0) - 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: Getting problem with playerid (0) (/showthread.php?tid=607758)



Getting problem with playerid (0) - GuthiX - 23.05.2016

Guys, i have my own cnr gamemode, sfcnr.
So lemme explain you, first of all.
When any player join the server from id 0, and if any other id player do quit, so id 0 spawn in a farm or somewhere else everytime.

So please solve my this problem, and i will give +rep to the person.


Re: Getting problem with playerid (0) - Micko123 - 23.05.2016

Show OnPlayerDisconnect


Re: Getting problem with playerid (0) - Dayrion - 23.05.2016

You have to reset vars' OnPlayerDisconnect


Re: Getting problem with playerid (0) - GuthiX - 23.05.2016

Here you go

Код:
public OnPlayerDisconnect(playerid, reason)
{
    SetPlayerColor(playerid, 0xFFFFFFFF);
	if(playerData[playerid][playerLoggedIn])
    {
        savePlayerStats(playerid);
    }

	if(reason == 1) // Manual game-quit.
	{
		new administratorAlert[128];

		if(playerData[playerid][playerIsTazed])
		{
			format(administratorAlert, sizeof(administratorAlert), "{C73E3E}[AVOID-DETECTION] {FFFFFF}%s(%i) quit the game while tazed.", playerData[playerid][playerNamee], playerid);
			adminchat(COLOR_WHITE, administratorAlert);
		}
		else if(playerData[playerid][playerIsCuffed])
		{
			format(administratorAlert, sizeof(administratorAlert), "{C73E3E}[AVOID-DETECTION] {FFFFFF}%s(%i) quit the game while cuffed.", playerData[playerid][playerNamee], playerid);
			adminchat(COLOR_WHITE, administratorAlert);
		}
		else if(playerData[playerid][playerIsTied])
		{
			format(administratorAlert, sizeof(administratorAlert), "{C73E3E}[AVOID-DETECTION] {FFFFFF}%s(%i) quit the game while tied.", playerData[playerid][playerNamee], playerid);
			adminchat(COLOR_WHITE, administratorAlert);
		}
	}

	if(playerData[playerid][playerGangID] != INVALID_GANG_ID)
	{
		cmd_g(playerid, "leave");
	}

	ClearStats(playerid);
	removePlayerRoadblocks(playerid);
	destroyPlayersExplosives(playerid);

	// Delete labels
	Delete3DTextLabel(playerData[playerid][playerAdminLabel]);

	// Destroy timers
	KillTimer(playerData[playerid][unfreezeTimer]);
	KillTimer(playerData[playerid][arrestTimer]);
	KillTimer(playerData[playerid][untieTimer]);
	KillTimer(playerData[playerid][uncuffTimer]);
	KillTimer(playerData[playerid][recuffTimer]);
	KillTimer(playerData[playerid][retazeTimer]);
	KillTimer(playerData[playerid][fixTimer]);
	KillTimer(playerData[playerid][nosTimer]);
	KillTimer(playerData[playerid][mechREMPTimer]);
	KillTimer(playerData[playerid][reactivateRapeStatus]);
	KillTimer(playerData[playerid][reactivateRobStatus]);
	KillTimer(playerData[playerid][hcpTimer]);
	KillTimer(playerData[playerid][courierTimer]);
	KillTimer(playerData[playerid][playerCanKidnap]);
	KillTimer(playerData[playerid][rapedTimer]);
	KillTimer(playerData[playerid][jailTimer]);
	KillTimer(playerData[playerid][spawnPlayerTimer]);
	KillTimer(playerData[playerid][truckExitTimer]);
	KillTimer(playerData[playerid][breakCuffsTimer]);
	KillTimer(playerData[playerid][achieveTimer]);
	KillTimer(playerData[playerid][spamTimer]);
	KillTimer(playerData[playerid][CheckSpeed]);
	KillTimer(playerData[playerid][retruckTimer]);
	KillTimer(playerData[playerid][saveStatsTimer]);
	KillTimer(playerData[playerid][rehealTimer]);
	KillTimer(playerData[playerid][recureTimer]);
	KillTimer(playerData[playerid][breakinTimer]);
	KillTimer(playerData[playerid][houseTimer]);
	
	playerData[playerid][shotTime] = 0;
 	playerData[playerid][shot] = 0;
 	playerData[playerid][shotWarnings] = 0;

	// Reset weapons for next player
	ResetPlayerWeapons(playerid);
    SendDeathMessage(INVALID_PLAYER_ID, playerid, 201);
    
    // Vehicles
 	/*for(new v = 0; v < MAX_SCRIPT_VEHICLES; v++)
	{
		if (oVehicle[v][vehicle_id] != -1)
		{
			if(!strcmp(oVehicle[v][vehicle_owner], playerData[playerid][playerNamee], true))
			{
				DestroyVehicle(oVehicle[v][vehicle_sid]);
			}
		}
	}*/
	
	for(new i; i < MAX_SAVED_VEHICLES; i++)
	{
	    if(VehicleInfo[i][vOwner] != playerData[playerid][actualID]) continue;
	    DestroyVehicle(VehicleInfo[i][vehicleID]);
	    VehicleInfo[i][vehicleID] = INVALID_VEHICLE_ID;
	}

	return 1;
}



Re: Getting problem with playerid (0) - GuthiX - 24.05.2016

Bump please.


Re: Getting problem with playerid (0) - GuthiX - 24.05.2016

Please help me and he will get a +rep from me.


Re: Getting problem with playerid (0) - MBilal - 24.05.2016

savePlayerStats(playerid);

ClearStats(playerid);

Show both these function code.


Re: Getting problem with playerid (0) - GuthiX - 25.05.2016

Quote:
Originally Posted by MBilal
Посмотреть сообщение
savePlayerStats(playerid);

ClearStats(playerid);

Show both these function code.
That both function code is already defined.
See the code of ShowPlayerDisconnect


Re: Getting problem with playerid (0) - Dayrion - 25.05.2016

Quote:
Originally Posted by GuthiX
Посмотреть сообщение
That both function code is already defined.
See the code of ShowPlayerDisconnect
Yes, they are defined but show us those functions.


Re: Getting problem with playerid (0) - GuthiX - 25.05.2016

savePlayerstats function:
Код:
public saveStats()
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i) && playerData[i][playerLoggedIn])
		{
			savePlayerStats(i);
		}
	}
}
ClearStats function:
Код:
stock ClearStats(playerid)
{
	if (playerData[playerid][playerLoggedIn])
	{
		forceRobberyCancel(playerid);

		// Reset main stats
		playerData[playerid][playerLevel] 			= 0;
		playerData[playerid][playerMoney]			= 0;
		playerData[playerid][playerBank]			= 0;
		playerData[playerid][playerScore]			= 0;
		playerData[playerid][playerXP]				= 0;
		playerData[playerid][playerIP]				= 0;
		playerData[playerid][playerInterior]		= 0;
		playerData[playerid][playerVWorld]			= 0;
		playerData[playerid][playerJailTime] 		= 0;
		playerData[playerid][playerMuteTime] 		= 0;
		playerData[playerid][playerCheckpointTime]	= 0;
		playerData[playerid][playerRobTime]			= 0;
		playerData[playerid][playerSafeObj]			= 0;
		playerData[playerid][playerClass]			= 0;
		playerData[playerid][playerWantedLevel]     = 0;
		playerData[playerid][playerVIPLevel]		= 0;
		playerData[playerid][playerRope]			= 0;
		playerData[playerid][playerJailKit]			= 0;
		playerData[playerid][playerScissors]		= 0;
		playerData[playerid][playerButtPlug]		= 0;
		playerData[playerid][playerBiggerPockets]	= 0;
		playerData[playerid][playerSecureWallet]	= 0;
		playerData[playerid][playerCourierLevel]    = 0;
		playerData[playerid][playerBanned]          = 0;
		playerData[playerid][playerLastVehicleID]   = 0;
		playerData[playerid][playerWarnings]        = 0;
		playerData[playerid][playerHelper]			= 0;
		playerData[playerid][playerWeed]			= 0;
		playerData[playerid][playerExplosives]		= 0;
		playerData[playerid][vipWeapon]             = 0;
		playerData[playerid][innocentKills]			= 0;
		playerData[playerid][aInnocentKills]		= 0;
		playerData[playerid][healthInsurance]		= 0;

		// Reset stats
		playerData[playerid][playerKills]			= 0;
		playerData[playerid][playerDeaths]			= 0;
		playerData[playerid][playerRobberies]		= 0;
		playerData[playerid][playerTimesJailed]		= 0;
		playerData[playerid][copArrests]			= 0;
		playerData[playerid][rulesRead]				= 0;
		playerData[playerid][streetRobberies] 		= 0;
		playerData[playerid][streetRapes] 			= 0;
		playerData[playerid][playersTied] 			= 0;
		playerData[playerid][playersKidnapped] 		= 0;
		playerData[playerid][copDetains]			= 0;
		playerData[playerid][copKills]				= 0;
		playerData[playerid][forkliftCompleted]		= 0;
		playerData[playerid][bankRobs]				= 0;
		playerData[playerid][bombsDefused]			= 0;

		// Reset Jobs
		playerData[playerid][lastCarDrop]			= -1;
		playerData[playerid][playerJob]				= -1;

		// Reset ID systems
		playerData[playerid][playerLastTicket] 		= -1;
		playerData[playerid][playerBailTo] 			= -1;
		playerData[playerid][playerBailPrice] 		= -1;
		playerData[playerid][playerAdminJailed] 	= -1;
		playerData[playerid][playerGunOffer] 		= -1;
		playerData[playerid][playerGunDealer] 		= -1;
		playerData[playerid][playerHousePass]       = -1;
		playerData[playerid][lastRecipient]         = -1;
		playerData[playerid][playerCustomSkin]		= -1;
		playerData[playerid][vehicleMenu]			= -1;
		playerData[playerid][playerStoreID]			= 0;
		playerData[playerid][playerCheckID]         = 0;
		playerData[playerid][playerInsideHouse]     = 0;
		playerData[playerid][playerInsideBusiness]  = 0;
		playerData[playerid][adDetected]			= 0;
		playerData[playerid][shotWarnings]			= 0;
		playerData[playerid][cbugWarnings]			= 0;
		playerData[playerid][carSwing]				= 0;

		// Reset Trucking
		if (playerData[playerid][truckingStatus] > 0)
		{
			DestroyDynamicRaceCP(playerData[playerid][truckingCheckpoint]);
		}

		playerData[playerid][truckingStatus]        = -1;
		playerData[playerid][truckingMission]       = -1;

		playerData[playerid][playerMissionCPTime] 	= 0;

		// Reset Forklift
		if (playerData[playerid][forkliftStatus] > 0)
		{
			DestroyObject(playerData[playerid][forkliftObject]);
		}

		playerData[playerid][forkliftStatus]		= -1;
		playerData[playerid][forkliftDamage]		= -1;

		// Reset Bus

		if (playerData[playerid][busStatus] > 0)
		{
			DestroyDynamicRaceCP(playerData[playerid][busCP]);
		}

		playerData[playerid][busStatus] 			= -1;

		// Reset Sweeper

		if (playerData[playerid][sweepStatus] > 0)
		{
			DestroyDynamicRaceCP(playerData[playerid][sweepCP]);
		}

		// Reset medic
		if (playerData[playerid][medicStatus] > 0)
		{
			playerData[playerid][medicStatus] = -1;
			playerData[playerid][medicMission] = -1;

			RemovePlayerMapIcon(playerid, 69);
			DestroyDynamicRaceCP(playerData[playerid][medicCheckpoint]);
		}

		playerData[playerid][sweepStatus] 			= -1;

		// Reset DM
		playerData[playerid][dmStreak] 			= 0;

		// Reset booleans
		playerData[playerid][playerGangID]			= INVALID_GANG_ID;
		playerData[playerid][hasSTD] 				= false;
		playerData[playerid][isInEvent]             = false;
		playerData[playerid][playerPingImmune]      = false;
		playerData[playerid][hasSpawned]            = false;
		playerData[playerid][playerLoggedIn] 		= false;
		playerData[playerid][playerAdminDuty]		= false;
		playerData[playerid][playerCanTaze]			= false;
		playerData[playerid][playerCanCuff]			= false;
		playerData[playerid][playerCanArrest]		= false;
		playerData[playerid][playerCanEMP]			= false;
		playerData[playerid][playerIsTazed]			= false;
		playerData[playerid][playerIsCuffed]		= false;
		playerData[playerid][playerIsInHouse]		= false;
		playerData[playerid][playerHitmarker]		= false;
		playerData[playerid][playerCanRape]			= false;
		playerData[playerid][playerCanRob]			= false;
		playerData[playerid][playerCanRepair]		= false;
		playerData[playerid][adminWeapon]			= false;
		playerData[playerid][pEnterHouse]			= false;
		playerData[playerid][showALog]              = false;
		playerData[playerid][iscourier]             = false;
		playerData[playerid][pmSpy]            		= false;
		playerData[playerid][isBanned]              = false;
		playerData[playerid][playerBeenBanned]      = false;
		playerData[playerid][playerDied]	        = false;
		playerData[playerid][suicide] 				= false;
		playerData[playerid][vipColour]				= false;
		playerData[playerid][isInDM]				= false;
		playerData[playerid][hasBackpack] 			= false;
		playerData[playerid][hasParrot] 			= false;
		playerData[playerid][luckyCharm] 			= false;
		playerData[playerid][weaponSkill]			= false;
		playerData[playerid][playerDefuseKit]		= false;
		playerData[playerid][allowSpec]				= true;
		playerData[playerid][canEscape]				= true;

		playerData[playerid][canAsk] 				= true;
		playerData[playerid][canReport] 			= true;
		playerData[playerid][useAdminName]			= false;

		if (playerData[playerid][vSellTo] != -1)
		{
			// Remove the sale
			new sellto = playerData[playerid][vSellTo];
			playerData[sellto][vBuyFrom] = -1;
			SendClientMessage(sellto, COLOR_WHITE, "{B7B7B7}[SERVER] {FFFFFF}The vehicle offer has expired, the seller has quit.");
		}

		if (playerData[playerid][vBuyFrom] != -1)
		{
			// Remove the sale
			new buyfrom = playerData[playerid][vBuyFrom];
			playerData[buyfrom][vSellTo] = -1;
			SendClientMessage(buyfrom, COLOR_WHITE, "{B7B7B7}[SERVER] {FFFFFF}The vehicle offer has expired, the buyer has quit.");
		}

		// Progress Bars
		if (GetProgressBarValue(playerData[playerid][breakin]) != INVALID_BAR_VALUE)
		{
			DestroyProgressBar(playerData[playerid][breakin]);
		}

		DestroyProgressBar(playerData[playerid][robbery]);
	}
}