SA-MP Forums Archive
Random spawn - 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 spawn (/showthread.php?tid=497832)



Random spawn - Pawnie - 28.02.2014

Alright so I got random spawn system for gifts, but how do I tell players where did it spawn?

Code:
pawn Код:
new Float:RandomSpawns[][] =
{
    {1249.7258, -2047.9263, 59.9209, 90.2055}, //KingHouse
    {1241.2084, -2057.6521, 60.0190, 94.9352},
    {1241.0105, -2052.6873, 59.9975, 2.8144}
};

public RP_SpawnGift(playerid)
{
    new Random = random(sizeof(RandomSpawns));
    CreateObject(giftbox,RandomSpawns[Random][1],RandomSpawns[Random][2],RandomSpawns[Random][3],RandomSpawns[Random][4],0,0,0);
}

How do I tell players know where it spawned?

Like if it spawned at KingHouse it will send all players message "It spawned at the KingsHouse"


Re: Random spawn - Clad - 28.02.2014

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

Now create the client messages


Re: Random spawn - Pawnie - 28.02.2014

Quote:
Originally Posted by Clad
Посмотреть сообщение
PHP код:
public OnPlayerSpawn(playerid)
{
    new 
Random random(sizeof(RandomSpawns));
    
SetPlayerPos(playeridRandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2]);
    
SetPlayerFacingAngle(playeridRandomSpawns[Random][3]);
    return 
1;

Now create the client messages
You dont understand.

If the object spawns at these coords for example. It will SendClientMessageToAll(COLOR_RED, "It spawned at Kings House!");
pawn Код:
{1249.7258, -2047.9263, 59.9209, 90.2055}, //KingHouse



Re: Random spawn - Clad - 28.02.2014

Is it random spawn for players or objects ?


Re: Random spawn - Pawnie - 28.02.2014

Quote:
Originally Posted by Clad
Посмотреть сообщение
Is it random spawn for players or objects ?
Object.


Re: Random spawn - iPrivate - 28.02.2014

pawn Код:
enum Gift
{
    LocX,
    LocY,
    LocZ,
    Msg[128]
}

new Float:RandomSpawns[][Gift] =
{
    {1249.7258, -2047.9263, 59.9209, 90.2055, "King House"}, //KingHouse
    {1241.2084, -2057.6521, 60.0190, 94.9352, " Other loc"},
    {1241.0105, -2052.6873, 59.9975, 2.8144, " Other loc"}
};

public RP_SpawnGift(playerid)
{
    new Random = random(sizeof(RandomSpawns));
    new Text[128];
    CreateObject(giftbox,RandomSpawns[Random][LocX],RandomSpawns[Random][LocY],RandomSpawns[Random][LocZ],RandomSpawns[Random][4],0,0,0);
    format(Text, sizeof(Text), "Gift is found at %s", RandomSpawns[Random][Msg]);
    SendClientMessageToAll(-1, Text);
}
This shall work, untested.


Re: Random spawn - Pawnie - 28.02.2014

Quote:
Originally Posted by iPrivate
Посмотреть сообщение
pawn Код:
enum Gift
{
    LocX,
    LocY,
    LocZ,
    Msg[128]
}

new Float:RandomSpawns[][Gift] =
{
    {1249.7258, -2047.9263, 59.9209, 90.2055, "King House"}, //KingHouse
    {1241.2084, -2057.6521, 60.0190, 94.9352, " Other loc"},
    {1241.0105, -2052.6873, 59.9975, 2.8144, " Other loc"}
};

public RP_SpawnGift(playerid)
{
    new Random = random(sizeof(RandomSpawns));
    new Text[128];
    CreateObject(giftbox,RandomSpawns[Random][LocX],RandomSpawns[Random][LocY],RandomSpawns[Random][LocZ],RandomSpawns[Random][4],0,0,0);
    format(Text, sizeof(Text), "Gift is found at %s", RandomSpawns[Random][Msg]);
    SendClientMessageToAll(-1, Text);
}
This shall work, untested.
Thanks