SA-MP Forums Archive
Commands work only for id 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Commands work only for id 0 (/showthread.php?tid=90639)



Commands work only for id 0 - Rickk - 09.08.2009

Hey,
I got the problem that a lot of the functions I make only work for the player with id 0.

Yesterday I finished my own pay 'n spray, I tested it and it worked fine (because I had id 0). but when a friend of mine joined the server the pay 'n spray didn't respond. This is the third time I come across this problem. Does anybody know what the solution is for this issue?

This is Part of the code:

This is the code for the menu (it's placed under OnGameModeInit):
Код:
	SetColor = CreateMenu("SetColor", 1, 50.0, 180.0, 200.0, 200.0);
	SetMenuColumnHeader(Navigation, 0, "Color1");
	AddMenuItem(SetColor, 0, "Red");
	AddMenuItem(SetColor, 0, "Blue");
	AddMenuItem(SetColor, 0, "Green")
	AddMenuItem(SetColor, 0, "Yellow")
	AddMenuItem(SetColor, 0, "White")
	AddMenuItem(SetColor, 0, "Black")
	AddMenuItem(SetColor, 0, "Pink")
	AddMenuItem(SetColor, 0, "Grey")
	AddMenuItem(SetColor, 0, "Back")
This is the code for the menu function (I only copied case 1 because other cases are partly the same)
Код:
  if(current == SetColor)
  {
    switch(row)
    {
      case 0:
			{
				if (PlayerToPoint(2.0, playerid, 2703.0295,-2607.8708,13.3313))
				{
 	  			ChangeVehicleColor(mycar, 3, 1);
 	  			SendClientMessage(playerid, COLOR_ORANGE, "The car is painted red.");
 	  			HideMenuForPlayer(SetColor, playerid);
 	  			TogglePlayerControllable(playerid, 1);
 	  			SetVehiclePos(mycar, 2703.0295,-2607.8708,13.3313);
 	  			PlayerPlaySound(playerid, 1134, 2703.0295,-2607.8708,13.3313);
				}
				else if (PlayerToPoint(2.0, playerid, 2703.0989,-2598.2961,13.3497))
				{
			 	  ChangeVehicleColor(mycar, 3, 1);
 	  			SendClientMessage(playerid, COLOR_ORANGE, "The car is painted red.");
 	  			HideMenuForPlayer(SetColor, playerid);
 	  			TogglePlayerControllable(playerid, 1);
 	  			SetVehiclePos(mycar, 2703.0989,-2598.2961,13.3497);
 	  			PlayerPlaySound(playerid, 1134, 2703.0989,-2598.2961,13.3497);
				}
			}
      case 1:
			{
				if (PlayerToPoint(2.0, playerid, 2703.0295,-2607.8708,13.3313))
				{
 	  			ChangeVehicleColor(mycar, 79, 1);
 	  			SendClientMessage(playerid, COLOR_ORANGE, "The car is painted blue.");
 	  			HideMenuForPlayer(SetColor, playerid);
 	  			TogglePlayerControllable(playerid, 1);
 	  			SetVehiclePos(mycar, 2703.0295,-2607.8708,13.3313);
 	  			PlayerPlaySound(playerid, 1134, 2703.0295,-2607.8708,13.3313);
				}
				else if (PlayerToPoint(2.0, playerid, 2703.0989,-2598.2961,13.3497))
				{
			 	  ChangeVehicleColor(mycar, 79, 1);
 	  			SendClientMessage(playerid, COLOR_ORANGE, "The car is painted blue.");
 	  			HideMenuForPlayer(SetColor, playerid);
 	  			TogglePlayerControllable(playerid, 1);
 	  			SetVehiclePos(mycar, 2703.0989,-2598.2961,13.3497);
 	  			PlayerPlaySound(playerid, 1134, 2703.0989,-2598.2961,13.3497);
				}
      }
This is the playertopoint code (this is placed under my public custom pickups):
Код:
			if (PlayerToPoint(2.0, playerid, 2697.7610,-2608.0239,13.6535))
			{// Pay & Spray
				if(PlayerInfo[playerid][pMember] == 6 || PlayerInfo[playerid][pLeader] == 6)
				{
					ShowMenuForPlayer(SetColor, playerid);
					TogglePlayerControllable(playerid, 0);
					SetVehiclePos(mycar, 2703.0295,-2607.8708,13.3313);
				}
				else
				{
					SendClientMessage(playerid, COLOR_WHITE, "This pay & spray is Only for yakuza members");
					SendClientMessage(playerid, COLOR_WHITE, "Please try one of the regular pay & sprays");
				}
			}
			if (PlayerToPoint(2.0, playerid, 2697.8784,-2598.3198,13.6725))
			{// Pay & Spray
				if(PlayerInfo[playerid][pMember] == 6 || PlayerInfo[playerid][pLeader] == 6)
				{
					ShowMenuForPlayer(SetColor, playerid);
					TogglePlayerControllable(playerid, 0);
					SetVehiclePos(mycar, 2703.0989,-2598.2961,13.3497);
				}
				else
				{
					SendClientMessage(playerid, COLOR_WHITE, "This pay & spray is Only for yakuza members");
					SendClientMessage(playerid, COLOR_WHITE, "Please try one of the regular pay & sprays");
				}
			}
Thanks!


Re: Commands work only for id 0 - Weirdosport - 09.08.2009

I am guessing you use timers? The problem is that the playerid bit doesn't pop out of nowehere you have to send it.

If you use SetTimer, you need to change it to SetTimerEx, posting some code would help me explain this better.


Re: Commands work only for id 0 - Rickk - 09.08.2009

No I am not using timers.

It's a code that uses IfPlayerToPoint. When the player is at the pay 'n spray a menu pops up with some fuctions.

Another fuction I had the same problem with is a fuction that tuned cars on spawn. When player with id 0 entered the car, the car got tuned. Then a player with another id entered the car nothing happened.



Re: Commands work only for id 0 - Weirdosport - 09.08.2009

In that case I/We'll need to see some code, we can't fix things blindly.


Re: Commands work only for id 0 - abhinavdabral - 09.08.2009

Oo - If you will show the code, it would be easy for us to fix the problem.


Re: Commands work only for id 0 - Rickk - 09.08.2009

Allright, I will post parts of the code:

This is most of the code. It is still in experimental stage, and it will become larger


This is the code for the menu (it's placed under OnGameModeInit):
Код:
	SetColor = CreateMenu("SetColor", 1, 50.0, 180.0, 200.0, 200.0);
	SetMenuColumnHeader(Navigation, 0, "Color1");
	AddMenuItem(SetColor, 0, "Red");
	AddMenuItem(SetColor, 0, "Blue");
	AddMenuItem(SetColor, 0, "Green")
	AddMenuItem(SetColor, 0, "Yellow")
	AddMenuItem(SetColor, 0, "White")
	AddMenuItem(SetColor, 0, "Black")
	AddMenuItem(SetColor, 0, "Pink")
	AddMenuItem(SetColor, 0, "Grey")
	AddMenuItem(SetColor, 0, "Back")
This is the code for the menu function (I only copied case 1 because other cases are partly the same)
Код:
  if(current == SetColor)
  {
    switch(row)
    {
      case 0:
			{
				if (PlayerToPoint(2.0, playerid, 2703.0295,-2607.8708,13.3313))
				{
 	  			ChangeVehicleColor(mycar, 3, 1);
 	  			SendClientMessage(playerid, COLOR_ORANGE, "The car is painted red.");
 	  			HideMenuForPlayer(SetColor, playerid);
 	  			TogglePlayerControllable(playerid, 1);
 	  			SetVehiclePos(mycar, 2703.0295,-2607.8708,13.3313);
 	  			PlayerPlaySound(playerid, 1134, 2703.0295,-2607.8708,13.3313);
				}
				else if (PlayerToPoint(2.0, playerid, 2703.0989,-2598.2961,13.3497))
				{
			 	  ChangeVehicleColor(mycar, 3, 1);
 	  			SendClientMessage(playerid, COLOR_ORANGE, "The car is painted red.");
 	  			HideMenuForPlayer(SetColor, playerid);
 	  			TogglePlayerControllable(playerid, 1);
 	  			SetVehiclePos(mycar, 2703.0989,-2598.2961,13.3497);
 	  			PlayerPlaySound(playerid, 1134, 2703.0989,-2598.2961,13.3497);
				}
			}
      case 1:
			{
				if (PlayerToPoint(2.0, playerid, 2703.0295,-2607.8708,13.3313))
				{
 	  			ChangeVehicleColor(mycar, 79, 1);
 	  			SendClientMessage(playerid, COLOR_ORANGE, "The car is painted blue.");
 	  			HideMenuForPlayer(SetColor, playerid);
 	  			TogglePlayerControllable(playerid, 1);
 	  			SetVehiclePos(mycar, 2703.0295,-2607.8708,13.3313);
 	  			PlayerPlaySound(playerid, 1134, 2703.0295,-2607.8708,13.3313);
				}
				else if (PlayerToPoint(2.0, playerid, 2703.0989,-2598.2961,13.3497))
				{
			 	  ChangeVehicleColor(mycar, 79, 1);
 	  			SendClientMessage(playerid, COLOR_ORANGE, "The car is painted blue.");
 	  			HideMenuForPlayer(SetColor, playerid);
 	  			TogglePlayerControllable(playerid, 1);
 	  			SetVehiclePos(mycar, 2703.0989,-2598.2961,13.3497);
 	  			PlayerPlaySound(playerid, 1134, 2703.0989,-2598.2961,13.3497);
				}
      }
This is the playertopoint code (this is placed under my public custom pickups):
Код:
			if (PlayerToPoint(2.0, playerid, 2697.7610,-2608.0239,13.6535))
			{// Pay & Spray
				if(PlayerInfo[playerid][pMember] == 6 || PlayerInfo[playerid][pLeader] == 6)
				{
					ShowMenuForPlayer(SetColor, playerid);
					TogglePlayerControllable(playerid, 0);
					SetVehiclePos(mycar, 2703.0295,-2607.8708,13.3313);
				}
				else
				{
					SendClientMessage(playerid, COLOR_WHITE, "This pay & spray is Only for yakuza members");
					SendClientMessage(playerid, COLOR_WHITE, "Please try one of the regular pay & sprays");
				}
			}
			if (PlayerToPoint(2.0, playerid, 2697.8784,-2598.3198,13.6725))
			{// Pay & Spray
				if(PlayerInfo[playerid][pMember] == 6 || PlayerInfo[playerid][pLeader] == 6)
				{
					ShowMenuForPlayer(SetColor, playerid);
					TogglePlayerControllable(playerid, 0);
					SetVehiclePos(mycar, 2703.0989,-2598.2961,13.3497);
				}
				else
				{
					SendClientMessage(playerid, COLOR_WHITE, "This pay & spray is Only for yakuza members");
					SendClientMessage(playerid, COLOR_WHITE, "Please try one of the regular pay & sprays");
				}
			}