SA-MP Forums Archive
Random spawns not working - 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: Random spawns not working (/showthread.php?tid=615152)



Random spawns not working - DwayneMichael - 18.08.2016

I've tried to make a player spawn in randomized positions when he uses a command but unfortunately, it's not spawning him to the correct location.

Code:-

Код:
new Float:area51[4][4] = {

	{262.3471,1470.6333,10.580,89.3090},
	{219.5900,1431.0100,10.5800,273.5500},
	{246.3904,1361.7498,23.3703,5.0454},
	{210.0943,1344.1219,10.5859,0.9721}};
Код:
CMD:area51(playerid,params[]){
        new randomize=random(sizeof(area51));
	SetPlayerPos(playerid, area51[randomize][0],area51[randomize][1],area51[randomize][2]);
	SetPlayerFacingAngle(playerid, area51[randomize][3]);
        SetPlayerHealth(playerid,100.0);
	SetPlayerArmour(playerid,100.0);
	ResetPlayerWeapons(playerid);;
	return 1;}
Could anyone help? This spawns me in a totally different area even though the position I set is the correct one, Please help; Thankyou.

Also this error;
Код:
C:\Users\Michael\Desktop\My GM\gamemodes\Stunt.pwn(412) : error 020: invalid symbol name ""
Line 412 is New float:area51 as shown above


Re: Random spawns not working - Luis- - 18.08.2016

That's a horrible way to code..

Anyway, you've got two ; on the ResetPlayerWeapons(playerid) function.

pawn Код:
new Float:area51[4][4] = {

    {262.3471,1470.6333,10.580,89.3090},
    {219.5900,1431.0100,10.5800,273.5500},
    {246.3904,1361.7498,23.3703,5.0454},
    {210.0943,1344.1219,10.5859,0.9721}
};

CMD:area51(playerid, params[]) {
    new randomize=random(sizeof(area51));
    SetPlayerPos(playerid, area51[randomize][0],area51[randomize][1],area51[randomize][2]);
    SetPlayerFacingAngle(playerid, area51[randomize][3]);
    SetPlayerHealth(playerid,100.0);
    SetPlayerArmour(playerid,100.0);
    ResetPlayerWeapons(playerid);
    return 1;
}



Re: Random spawns not working - DwayneMichael - 18.08.2016

I am new, The problem still exists, could you perhaps show a better way to randomize the spawns. Let me try


Re: Random spawns not working - Luis- - 18.08.2016

I just compiled your code without any errors apart from the extra ;. So, the problem must be from elsewhere.


Re: Random spawns not working - DwayneMichael - 18.08.2016

Worked! :'D, Able to spawn on the correct position, Thanks a bunch.


Re: Random spawns not working - Luis- - 18.08.2016

Glad it's working


Re: Random spawns not working - Sew_Sumi - 18.08.2016

Another thing to mention, is you are using sizeof in your random spawn, so there's no need to set the array size in

PHP код:
new Float:area51[4][4] = {
    {
262.3471,1470.6333,10.580,89.3090},
    {
219.5900,1431.0100,10.5800,273.5500},
    {
246.3904,1361.7498,23.3703,5.0454},
    {
210.0943,1344.1219,10.5859,0.9721}
}; 
If you use

PHP код:
new Float:area51[][4] = {
    {
262.3471,1470.6333,10.580,89.3090},
    {
219.5900,1431.0100,10.5800,273.5500},
    {
246.3904,1361.7498,23.3703,5.0454},
    {
210.0943,1344.1219,10.5859,0.9721}
}; 
you can then add more spawns without having to change the array size all the time.


Re: Random spawns not working - Marricio - 18.08.2016

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Another thing to mention, is you are using sizeof in your random spawn, so there's no need to set the array size in

PHP код:
new Float:area51[4][4] = {
    {
262.3471,1470.6333,10.580,89.3090},
    {
219.5900,1431.0100,10.5800,273.5500},
    {
246.3904,1361.7498,23.3703,5.0454},
    {
210.0943,1344.1219,10.5859,0.9721}
}; 
If you use

PHP код:
new Float:area51[4][] = {
    {
262.3471,1470.6333,10.580,89.3090},
    {
219.5900,1431.0100,10.5800,273.5500},
    {
246.3904,1361.7498,23.3703,5.0454},
    {
210.0943,1344.1219,10.5859,0.9721}
}; 
you can then add more spawns without having to change the array size all the time.
I think you mean,

pawn Код:
new Float:area51[][4] = {
    {262.3471,1470.6333,10.580,89.3090},
    {219.5900,1431.0100,10.5800,273.5500},
    {246.3904,1361.7498,23.3703,5.0454},
    {210.0943,1344.1219,10.5859,0.9721}
};



Re: Random spawns not working - Sew_Sumi - 18.08.2016

Quote:
Originally Posted by Marricio
Посмотреть сообщение
I think you mean,

pawn Код:
new Float:area51[][4] = {
    {262.3471,1470.6333,10.580,89.3090},
    {219.5900,1431.0100,10.5800,273.5500},
    {246.3904,1361.7498,23.3703,5.0454},
    {210.0943,1344.1219,10.5859,0.9721}
};
Yes indeed...