Stock returns 3 different float's
#1

Hello, I have a stock
GetPlayerRandomSpawn(playerid, Float:rX, Float:rY, Float:rZ)

When it makes the random and says the right coords
I want it to return it to the given float's
like GetPlayerPos(playerid, x, y, z);

meaning:

new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z); // Returns coords to X, Y, Z
GetPlayerRandomSpawn(playerid, X, Y, Z); // How to make it return coords to X, Y, Z ?

the stock:
pawn Код:
stock GetPlayerRandomSpawn(playerid, Float:rX, Float:rY, Float:rZ)
{
    // --> DO RANDOM SPAWN.
    new rnumber = rand(0, 6);
    if(rnumber == 0)
    {
        rX = 0.0;
        rY = 0.0;
        rZ = 0.0;
    }
    if(rnumber == 1)
    {
        rX = 1.0;
        rY = 1.0;
        rZ = 1.0;
    }
    if(rnumber == 2)
    {
        rX = 2.0;
        rY = 2.0;
        rZ = 2.0;
    }
    if(rnumber == 3)
    {
        rX = 3.0;
        rY = 3.0;
        rZ = 3.0;
    }
    if(rnumber == 4)
    {
        rX = 4.0;
        rY = 4.0;
        rZ = 4.0;
    }
    if(rnumber == 5)
    {
        rX = 5.0;
        rY = 5.0;
        rZ = 5.0;
    }
    if(rnumber == 6)
    {
        rX = 6.0;
        rY = 6.0;
        rZ = 6.0;
    }
    // --> HERE HOW TO MAKE IT RETURN TO rX, rY, rZ ?
}
This is my long version, to understand
I dont have a return because I know thats not the way, so what is it ?
Thank you.
Reply
#2

EDIT: Just read your first post again, I didn't read it correctly sorry, this reply may be useless to you.

You can't return more than 1 value of information (I beleive) from a function. This code still works, you just need to create a variable, and this function basically will add values to that variable.

Example:

pawn Код:
new Float:RandomSpawn[3];
GetPlayerRandomSpawn(playerid, RandomSpawn[0], RandomSpawn[1], RandomSpawn[2]);
SetSpawnInfo(playerid, 0, 0, RandomSpawn[0], RandomSpawn[1], RandomSpawn[2], 180.00, 0, 0, 0, 0, 0, 0);
Add return 1 on to that code of yours. It may also be worth adding an angle.

pawn Код:
stock GetPlayerRandomSpawn(playerid, Float:rX, Float:rY, Float:rZ)
{
    // --> DO RANDOM SPAWN.
    new rnumber = rand(0, 6);
    if(rnumber == 0)
    {
        rX = 0.0;
        rY = 0.0;
        rZ = 0.0;
    }
    if(rnumber == 1)
    {
        rX = 1.0;
        rY = 1.0;
        rZ = 1.0;
    }
    if(rnumber == 2)
    {
        rX = 2.0;
        rY = 2.0;
        rZ = 2.0;
    }
    if(rnumber == 3)
    {
        rX = 3.0;
        rY = 3.0;
        rZ = 3.0;
    }
    if(rnumber == 4)
    {
        rX = 4.0;
        rY = 4.0;
        rZ = 4.0;
    }
    if(rnumber == 5)
    {
        rX = 5.0;
        rY = 5.0;
        rZ = 5.0;
    }
    if(rnumber == 6)
    {
        rX = 6.0;
        rY = 6.0;
        rZ = 6.0;
    }
    return 1;
}
Reply
#3

This wont work, and it is possible.
GetPlayerPos returns 3 to Float's that you choose.
return 1 will be added later, I first of all want to make it return 3 float's to my choosen one like GetPlayerPos

I can do it the easy way, but the advanced way will be better and progress me more.
Reply
#4

Well I guess you could return an array that contains the values.
Reply
#5

Quote:
Originally Posted by Bicentric
Посмотреть сообщение
Well I guess you could return an array that contains the values.
Okay thanks, I'll try that

If anyone can give me a tutorial for this I would be glad.
If this isnt the way, can someone explain to me how to exactly do this like GetPlayerPos ?
thank you !
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
You need "call-by-reference". Check the file attached here:

https://sampforum.blast.hk/showthread.php?tid=289258
I have read the pdf about "call-by-refrence" and "call-by-value" but I havent understood the example of the Juliet day, can you explain how is it possible, sorry for the inconvines .
Reply
#7

****** means you should like this here. But you should add more things like GetPlayerPos(%0, %1, %2, %3) etc.
pawn Код:
#define GetPlayerRandomSpawn(%0, %1, %2, %3) //it's an example
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
That's not what ****** means at all! Maybe you should read that file too.
Thank you ******, I'll study about the syntax, if what I can always contact you for help right ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)