Random
#1

How do i make 3 randoms spawns when playerspawn ?
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=162488 look at this
Reply
#3

Код:
new Float:Spawns [][4] =
{
    {x, y, z, angle}, //Spawn 1
    {x, y, z, angle}, //Spawn 2
    {x, y, z, angle}  //Spawn 3
}; 

public OnPlayerSpawn(playerid)
{
    new spawn = random(sizeof(Spawns));
    SetPlayerPos(playerid, Spawns[spawn][0], Spawns[spawn][1], Spawns[spawn][2]);
    SetPlayerFacingAngle(playerid, Spawns[spawn][3]);
    return 1;
}
More explanation here: https://sampwiki.blast.hk/wiki/Random

EDIT:

Another easy way of making random spawns:

Код:
public OnPlayerSpawn(playerid)
{
    new spawn = random(3);

    switch(random)
    {
        case 0: { SetPlayerPos(playerid, x, y, z); SetPlayerFacingAngle(playerid, angle); } // Spawn 1
        case 1: { SetPlayerPos(playerid, x, y, z); SetPlayerFacingAngle(playerid, angle); } // Spawn 2
        case 2: { SetPlayerPos(playerid, x, y, z); SetPlayerFacingAngle(playerid, angle); } // Spawn 3
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by K0P
Посмотреть сообщение
EDIT:

Another easy way of making random spawns:

Код:
public OnPlayerSpawn(playerid)
{
    new spawn = random(3);

    switch(random)
    {
        case 0: { SetPlayerPos(playerid, x, y, z); SetPlayerFacingAngle(playerid, angle); } // Spawn 1
        case 1: { SetPlayerPos(playerid, x, y, z); SetPlayerFacingAngle(playerid, angle); } // Spawn 2
        case 2: { SetPlayerPos(playerid, x, y, z); SetPlayerFacingAngle(playerid, angle); } // Spawn 3
    }
    return 1;
}
You did a slight mistake

PHP код:
public OnPlayerSpawn(playerid)
{
    new 
spawn random(3);
    switch(
spawn)
    {
        case 
0: { SetPlayerPos(playeridxyz); SetPlayerFacingAngle(playeridangle); } // Spawn 1
        
case 1: { SetPlayerPos(playeridxyz); SetPlayerFacingAngle(playeridangle); } // Spawn 2
        
case 2: { SetPlayerPos(playeridxyz); SetPlayerFacingAngle(playeridangle); } // Spawn 3
    
}
    return 
1;

In case you didn't knew, it is possible to...
PHP код:
switch(random(3))
{
    ...

Reply
#5

First of all it is not considered as a mistake as its just a 1 extra line that does nothing but costs only 4-8 bytes,also i did this for explaining him a bit better that random values can be stored in a variable as the function 'returns' a specific value (As he is a new scripter/programmer) so he will not repeat whole function again and again in cases like random spawns if his concept will be clear.

You are behaving like i kicked into your balls or it seems you are jealous from me or something,you are pointing out tiny mistakes which does not matter and arguing with me on different non-sense things from a long time,it will be better improving your knowledge in programming before interrupting other's peaceful forum posts.

Another thing,are you a wizard? You got some kind of super powers to read minds just by looking at a person's forum account? How do you know that its not in my knowledge that the step can be performed directly? Its common sense that it can be,i would have done it that way but the reason is explained in the first paragraph.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)