random spawns with cmd
#1

Hey , i want to know if its possible like , when a player type /setspawn , for each place he types it saves and when he respawns he spawn on that spawns.. Is it possible?
Reply
#2

https://sampwiki.blast.hk/wiki/Random (see bottom for examples)

Make an array for random spawns, as shown there, select a random one from the sizeof the array, set that number in a variable for the player, OnPlayerSpawn spawn the player using the array and variable previously mentioned.

Example:

Код:
new myVar[MAX_PLAYERS];

new Float:RandomSpawn[][4] =
{
    //positions, (X, Y, Z and facing angle)
    {-2796.9854, 1224.8180, 20.5429, 192.0335},
    {-2454.2170, 503.8759, 30.0790, 267.2932},
    {-2669.7322, -6.0874, 6.1328, 89.8853}
};
 
public OnPlayerConnect(playerid)
{
	myVar[playerid] = -1; //reset the variable to -1 
        return 1;
} 
 
public OnPlayerSpawn(playerid)
{
	if(myArray[playerid] != -1);
	{
		SetPlayerPos(playerid, RandomSpawn[myVar[playerid]][0], RandomSpawn[myVar[playerid]][1],RandomSpawn[myVar[playerid]][2]);  //setPlayerPos to the random spawn data
		SetPlayerFacingAngle(playerid, RandomSpawn[myVar[playerid]][3]); //setPlayerFacingAngle to the random facing angle data
        }
	return 1;
}

CMD:randomspawn(playerid, params[])
{
	myVar[playerid] = random(sizeof(RandomSpawn)); //generate random number up to the size of the 'RandomSpawn' array.
	return 1;
}
Reply
#3

Ah i know that dude , i want to know how can i save these positions when player type /setspawn?
Reply
#4

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
Ah i know that dude , i want to know how can i save these positions when player type /setspawn?
Updated my post with some example code. Looks like I may have missed what you meant, however, same point, just make a variable saving the spawn ID, make a command that lists the spawns in the order declared in the array(starting from 0) and then simply save that to the variable and set the player position/angle on spawn based on that.
Reply
#5

Lmao you gave me a wrong info , how will i know where is the player typing the cmd? lmao
Reply
#6

pawn Код:
CMD:setspawn(playerid, params[])
{
    if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return SendClientMessage(playerid, -1, "You must be on-foot to use this command.");
    new Float:x, Float:y, Float:z, Float:a;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, a);
    SetSpawnInfo(playerid, GetPlayerTeam(playerid), GetPlayerSkin(playerid), x, y, z, a, 0, 0, 0, 0, 0, 0);
    SendClientMessage(playerid, 0xFFFF00FF, "Position saved. You will spawn here next time you respawn.");
    return 1;
}
https://sampwiki.blast.hk/wiki/SetSpawnInfo
Reply
#7

Ok dude that is only for 1 position , and hr have authority to spawn on 5 spawns now what will be the code
Reply
#8

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
Lmao you gave me a wrong info , how will i know where is the player typing the cmd? lmao
Lmao your code yourself then. Your title says you want 'random spawns' - and you want said 'random spawn' to be applied on the players next spawn. Perhaps if you explained your question a bit more clear, you'd get replies that spoon feed you exactly what you want.
Reply
#9

Hmm not really I tried my self and then came here.. I could possibly do it for 1 position , but I wanted to know how could I do for more.
Reply
#10

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
Hmm not really I tried my self and then came here.. I could possibly do it for 1 position , but I wanted to know how could I do for more.
Yes, but you're not exactly giving the best description, and if someone is kind enough to write code for you, you should probably not 'lmao' it because it's not exactly what you had in mind. This section is for scripting help with that, it infers people will give you advice on how to do something, not spoon feed you code.

So judging from what you're saying now, perhaps you're looking to let players select a list of spawns that they can chose to spawn at for their next spawn using a command?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)