SA-MP Forums Archive
/back command - 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: /back command (/showthread.php?tid=648169)



/back command - ivndosos - 16.01.2018

I've made a /back command I have an issue with it

Код:
CMD:back(playerid,params[])
{
    if(!IsPlayerInInterior(playerid)) return SendClientMessage(playerid, -1, "{FF0000}(INFO) You are not in lobby");
    else
   {
	 if(IsPlayerInInterior(playerid)) return SendClientMessage(playerid, -1, "{EFB509}(INFO) Welcome back! You can start playing now.");
	 SpawnPlayer(playerid);
	 SetPlayerVirtualWorld(playerid, 0);
	 SetPlayerInterior(playerid, 0);
   }
   return 1;
}
When I do /back it does not teleport me back to a random spawn


Re: /back command - Daveosss - 16.01.2018

Show your OnPlayerSpawn code.


Re: /back command - ivndosos - 16.01.2018

Код:
public OnPlayerSpawn(playerid)
{
    new Random = random(sizeof(RandomSpawns));
	SetPlayerPos(playerid, RandomSpawns[Random][0], RandomSpawns[Random][1],RandomSpawns[Random][2]);
	SetPlayerFacingAngle(playerid, RandomSpawns[Random][3]);
	return 1;
}



Re: /back command - Daveosss - 16.01.2018

Declare the "Random" variable globally:
Код:
new Random[MAX_PLAYERS];
Then change your OnPlayerSpawn like this:
Код:
public OnPlayerSpawn(playerid)
{
    Random[playerid] = random(sizeof(RandomSpawns));
	SetPlayerPos(playerid, RandomSpawns[Random[playerid]][0], RandomSpawns[Random[playerid]][1],RandomSpawns[Random[playerid]][2]);
	SetPlayerFacingAngle(playerid, RandomSpawns[Random[playerid]][3]);
	return 1;
}
This will teleport player back to where he spawned:
Код:
CMD:back(playerid,params[])
{
	if(!IsPlayerInInterior(playerid)) return SendClientMessage(playerid, -1, "{FF0000}(INFO) You are not in lobby");
    else
   {
	 if(IsPlayerInInterior(playerid)) return SendClientMessage(playerid, -1, "{EFB509}(INFO) Welcome back! You can start playing now.");
	 SetPlayerPos(playerid, RandomSpawns[Random[playerid]][0], RandomSpawns[Random[playerid]][1],RandomSpawns[Random[playerid]][2]);
	 SetPlayerFacingAngle(playerid, RandomSpawns[Random[playerid]][3]);
	 SetPlayerVirtualWorld(playerid, 0);
	 SetPlayerInterior(playerid, 0);
   }
   return 1;
}



Re: /back command - ivndosos - 16.01.2018

Your code didn't work out for me, Anyways, I managed to get closer to fixing this, The only problem is even when I am not in the lobby I can still use back

Код:
CMD:back(playerid,params[])
{
    new Float:IsPlayerInInterior;
    if(IsPlayerInInterior == 10)
	{
        SendClientMessage(playerid, -1, "{FF0000}(INFO) You are not in lobby");
    }
    else
    {
     SendClientMessage(playerid, -1, "{EFB509}(INFO) Welcome back! You can start playing now.");
     SpawnPlayer(playerid);
     SetPlayerVirtualWorld(playerid, 0);
     SetPlayerInterior(playerid, 0);
	 SetPlayerHealth(playerid,100);
    }
    return 1;
}



Re: /back command - Daveosss - 16.01.2018

What exactly didn't work? This is the right way of checking player's interior:

Код:
CMD:back(playerid,params[])
{
    if(GetPlayerInterior(playerid) == 10)
	{
        SendClientMessage(playerid, -1, "{FF0000}(INFO) You are not in lobby");
    }
    else
    {
     SendClientMessage(playerid, -1, "{EFB509}(INFO) Welcome back! You can start playing now.");
     SpawnPlayer(playerid);
     SetPlayerVirtualWorld(playerid, 0);
     SetPlayerInterior(playerid, 0);
	 SetPlayerHealth(playerid,100);
    }
    return 1;
}



Re: /back command - ivndosos - 16.01.2018

I used your code but in-game I just couldn't get back from lobby, Your code is more complicated to be honest.


Re: /back command - ivndosos - 16.01.2018

Okay guys, I fixed it I made a faster code, a simple one that I can't realize how I didn't do it earlier, I'll post it down here in-case someone needs help with the same situation.

Код:
CMD:back(playerid,params[])
{
    new interiorID = GetPlayerInterior(playerid);
    if (interiorID == 10) 
    {
	   SpawnPlayer(playerid);
	   SendClientMessage(playerid, -1, "{EFB509}(INFO) Welcome back! You can start playing now");
	   SetPlayerHealth(playerid, 100);
	   SetPlayerVirtualWorld(playerid, 0);
	   SetPlayerInterior(playerid, 0);
	}
	else
	{
	   SendClientMessage(playerid, -1, "{FF0000}(INFO) You are not in the lobby!");
	}
	return 1;
}
P.S: Make sure if you teleport to an interior, and make a back command, don't forget to set the interior back to 0 and virtual world aswell. (for new beginners like me just a tip i was stuck on this for a while haha!)


Re: /back command - Lucases - 16.01.2018

Quote:
Originally Posted by ivndosos
Посмотреть сообщение
I used your code but in-game I just couldn't get back from lobby, Your code is more complicated to be honest.
SetSpawnInfo bust be used before SpawnPlayer or it will spawn you in random places