SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/11/2013, 01:25 AM   #1
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,324
Reputation: 652
Default Array of pickup coordinates.

Well, I am making buy-able spawns for my RP server... I have an array of their coordinates...
Just for example this is what it looks like.

pawn Code:
enum SpawnInfo {X, Y, Z, R}
new Float:BoughtSpawns[][SpawnInfo] =
{
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781)
};
new BS[(sizeof(BoughtSpawns)];

On OnGamemodeInit(), I have...

pawn Code:
for(new i = 0; i < sizeof(BoughtSpawns); i++)
{
    BS[i] = CreateDynamicPickup(1313, 1, BoughtSpawns[i][X], BoughtSpawns[i][Y], BoughtSpawns[i][Z]);
}

This doesn't create these pickups... So what can I do...?









Also! How would I show this message when a player picks up any of these pickups...
Would this work?

pawn Code:
for(new o = -1; o < sizeof(BS); o++)
    {
        if(pickupid == o && IsValidDynamicPickup(o))
        {
            GameTextForPlayer(playerid, "~l~~h~DO ~g~/buyspawn ~l~~h~TO BUY THIS SPAWN!", 2000, 5);
        }
    }
Crayder is offline   Reply With Quote
Old 15/11/2013, 02:13 AM   #2
Loot
Huge Clucker
 
Join Date: Nov 2013
Posts: 235
Reputation: 17
Default Re: Array of pickup coordinates.

Why are you using both enum and floats when you can do all at once?
P.S I haven't tested that, so there might be an error.
pawn Code:
static Float:BoughtSpawns[11][3] =
{
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781)
};

public OnGameModeInit()
{
     for(new i = 0; i < sizeof(BoughtSpawns); i++)
     {
         BS[i] = CreateDynamicPickup(1313, 1, BoughtSpawns[i][0], BoughtSpawns[i][1], BoughtSpawns[i][2]);
     }
     return 1;
}

//pickups public
for(new i = 0; i < sizeof(BoughtSpawns); i++)
{
     if(IsValidDynamicPickup(i))
     {
          GameTextForPlayer(playerid, "~l~~h~DO ~g~/buyspawn ~l~~h~TO BUY THIS SPAWN!", 2000, 5);
     }
}
Loot is offline   Reply With Quote
Old 15/11/2013, 02:20 AM   #3
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,324
Reputation: 652
Default Re: Array of pickup coordinates.

Quote:
Originally Posted by Loot View Post
Why are you using both enum and floats when you can do all at once?
P.S I haven't tested that, so there might be an error.
pawn Code:
static Float:BoughtSpawns[11][3] =
{
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781)
};

public OnGameModeInit()
{
     for(new i = 0; i < sizeof(BoughtSpawns); i++)
     {
         BS[i] = CreateDynamicPickup(1313, 1, BoughtSpawns[i][0], BoughtSpawns[i][1], BoughtSpawns[i][2]);
     }
     return 1;
}

//pickups public
for(new i = 0; i < sizeof(BoughtSpawns); i++)
{
     if(IsValidDynamicPickup(i))
     {
          GameTextForPlayer(playerid, "~l~~h~DO ~g~/buyspawn ~l~~h~TO BUY THIS SPAWN!", 2000, 5);
     }
}
Thats basically the same EXACT thing... Thanks anyway but, the enum is for replacing the number, well not replace but just take place as the numbers... So X = 0, Y = 1, and Z = 2... R is for my random spawns... They just make it easier for a noob scripter to understand, I am eventually releasing this, so im making it for beginners...
Crayder is offline   Reply With Quote
Old 15/11/2013, 02:28 AM   #4
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,324
Reputation: 652
Default Re: Array of pickup coordinates.

Quote:
Originally Posted by Loot View Post
Why are you using both enum and floats when you can do all at once?
P.S I haven't tested that, so there might be an error.
pawn Code:
static Float:BoughtSpawns[11][3] =
{
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781)
};

public OnGameModeInit()
{
     for(new i = 0; i < sizeof(BoughtSpawns); i++)
     {
         BS[i] = CreateDynamicPickup(1313, 1, BoughtSpawns[i][0], BoughtSpawns[i][1], BoughtSpawns[i][2]);
     }
     return 1;
}

//pickups public
for(new i = 0; i < sizeof(BoughtSpawns); i++)
{
     if(IsValidDynamicPickup(i))
     {
          GameTextForPlayer(playerid, "~l~~h~DO ~g~/buyspawn ~l~~h~TO BUY THIS SPAWN!", 2000, 5);
     }
}
Thats basically the same EXACT thing... Thanks anyway but, the enum is for replacing the number, well not replace but just take place as the numbers... So X = 0, Y = 1, and Z = 2... R is for my random spawns... They just make it easier for a noob scripter to understand, I am eventually releasing this, so im making it for beginners...

ALSO, you used an exact amount (the 11)... (Float:BoughtSpawns[11][3])
By using sizeof(), it automatically counts the array.

(I dont know why it double posted... I clicked EDIT POST!)
Crayder is offline   Reply With Quote
Old 15/11/2013, 12:37 PM   #5
Loot
Huge Clucker
 
Join Date: Nov 2013
Posts: 235
Reputation: 17
Default Re: Array of pickup coordinates.

I know that's the exact thing... But does it works? I was hoping to fix your code, not to teach you new stuff.
Loot is offline   Reply With Quote
Old 15/11/2013, 12:58 PM   #6
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,122
Reputation: 529
Default Re: Array of pickup coordinates.

pawn Code:
new Float:BoughtSpawns[][3] =
{
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781),
    (132.0000,  -67.2844,   3.5781)
};
new BS[sizeof(BoughtSpawns)];

pawn Code:
for(new i = 0; i < sizeof(BoughtSpawns); i++)
{
    BS[i] = CreateDynamicPickup(1313, 1, BoughtSpawns[i][0], BoughtSpawns[i][1], BoughtSpawns[i][2]);
}

Also:

pawn Code:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i = 0; i < sizeof(BoughtSpawns); i++)
    {
        if(pickupid == BS[i])
        {
            GameTextForPlayer(playerid, "~l~~h~DO ~g~/buyspawn ~l~~h~TO BUY THIS SPAWN!", 2000, 5);
        }
    }
    return 1;
}

--

I haven't worked with these in a while, but give it a shot and see if it works.
Threshold is online now   Reply With Quote
Old 15/11/2013, 09:23 PM   #7
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,324
Reputation: 652
Default Re: Array of pickup coordinates.

Niether of these work... They are all the same, therefore work the same way, in which that way is a non-working way... Thanks guys, but does someone else wanna give a shot at this, please...? (Yes, I've tested both of yours... , and thanks Loot, I'll Rep you for the commitment...)
Crayder is offline   Reply With Quote
Old 15/11/2013, 09:29 PM   #8
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,885
Reputation: 1337
Default Re: Array of pickup coordinates.

Of course this will not work...

pawn Code:
new BS[sizeof(BoughtSpawns)];

Want to know how I would do it....

pawn Code:
enum BSINFO
{
   bool:SpawnBought,
   SpawnPickupID,
   SpawnOwner[MAX_PLAYER_NAME],
   Float:SpawnX,
   Float:SpawnY,
   Float:SpawnZ,
}

static BoughtSpawns[][BSINFO];
Pottus is offline   Reply With Quote
Old 15/11/2013, 09:30 PM   #9
Jefff
Banned
 
Join Date: Dec 2007
Posts: 2,593
Reputation: 326
Default Re: Array of pickup coordinates.

pawn Code:
enum SpawnInfo {
    Float:X,
    Float:Y,
    Float:Z
};
new BoughtSpawns[][SpawnInfo] =
{
    {132.0000,  -67.2844,   3.5781},
    {132.0000,  -67.2844,   3.5781},
    {132.0000,  -67.2844,   3.5781},
    {132.0000,  -67.2844,   3.5781},
    {132.0000,  -67.2844,   3.5781},
    {132.0000,  -67.2844,   3.5781},
    {132.0000,  -67.2844,   3.5781},
    {132.0000,  -67.2844,   3.5781},
    {132.0000,  -67.2844,   3.5781},
    {132.0000,  -67.2844,   3.5781},
    {132.0000,  -67.2844,   3.5781}
};
new BS[2];


pawn Code:
for(new i = 0; i < sizeof(BoughtSpawns); i++)
{
    BS[!!i] = CreateDynamicPickup(1313, 1, BoughtSpawns[i][X], BoughtSpawns[i][Y], BoughtSpawns[i][Z]);
}

pawn Code:
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
    if(BS[0] <= pickupid <= BS[1])
    {
        GameTextForPlayer(playerid, "~l~~h~DO ~g~/buyspawn ~l~~h~TO BUY THIS SPAWN!", 2000, 5);
        return 1;
    }
    return 0
}
Jefff is offline   Reply With Quote
Old 16/11/2013, 12:34 AM   #10
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,122
Reputation: 529
Default Re: Array of pickup coordinates.

Urgh, forgot to remove that and edit it... the first code I gave was just with a removed bracket, other than that I forgot to actually edit it -_-
Threshold is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enter pickup, array must be indexed dominik523 Scripting Help 7 20/04/2013 05:43 PM
Create pickup on big coordinates Killer#Mummy Scripting Help 2 14/05/2012 08:24 PM
I can't Find Pickup Coordinates serkoks Help Archive 0 23/12/2010 04:06 PM
I can't find coordinates at pickup serkoks Server Support 2 23/12/2010 08:17 AM


All times are GMT. The time now is 07:55 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.