PDA

View Full Version : Array of pickup coordinates.


Crayder
15/11/2013, 01:25 AM
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.


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...


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?


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);
}
}

Loot
15/11/2013, 02:13 AM
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.

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);
}
}

Crayder
15/11/2013, 02:20 AM
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.

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
15/11/2013, 02:28 AM
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.

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!)

Loot
15/11/2013, 12:37 PM
I know that's the exact thing... But does it works? I was hoping to fix your code, not to teach you new stuff.

Threshold
15/11/2013, 12:58 PM
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)];

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

Also:

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.

Crayder
15/11/2013, 09:23 PM
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...)

Pottus
15/11/2013, 09:29 PM
Of course this will not work...

new BS[sizeof(BoughtSpawns)];

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

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

static BoughtSpawns[][BSINFO];

Jefff
15/11/2013, 09:30 PM
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];


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

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
}

Threshold
16/11/2013, 12:34 AM
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 -_-

Crayder
16/11/2013, 01:39 AM
Pottus;2783604']Of course this will not work...

new BS[sizeof(BoughtSpawns)];

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

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

static BoughtSpawns[][BSINFO];


Yes, but... I wanted to avoid the need to save all of this information, when with my code being fixed I could just save a single variable in the players file.... Such as using Y_INI,
[PLAYER DATA]
BoughtSpawn = (The spawns id, BS[1] or whatever... but instead of "BS[1]" it would be 2, because BS[0] = 1)


//Write
new INI:file = INI_Open(Path(playerid)); //Path being defined in a stock.
INI_WriteInt(file,"Level", pInfo[playerid][pBS]);
_________________________________________________

//Load
INI_Int("BoughtSpawn", pInfo[playerid][pBS]);


Simpler than making a file for the spawns, especially for noob scripters... AND, this...
new BS[sizeof(BoughtSpawns)];
DOES WORK... It just needs to be under BoughtSpawns.