Question about arrays
#1

I've got a spawn weapons feature, and im trying to create something to see what weapons each player has...

The weapons are stored in an array, im wondering is it possible to store, 12 weapons in an array, all with varying ammo..

Then use another function to extract the info on what weapons the player has...
I've already got a command to see what weapons the player is carrying.. This isnt what im asking...

I want to store weapon info in 1 array, then be able to extract the info and display it as weapons id and ammo amount.

Is it possible?
Reply
#2

Quote:
Originally Posted by Outbreak
I've got a spawn weapons feature, and im trying to create something to see what weapons each player has...

The weapons are stored in an array, im wondering is it possible to store, 12 weapons in an array, all with varying ammo..

Then use another function to extract the info on what weapons the player has...
I've already got a command to see what weapons the player is carrying.. This isnt what im asking...

I want to store weapon info in 1 array, then be able to extract the info and display it as weapons id and ammo amount.

Is it possible?
Yes it is,

pawn Code:
new wInfo[13][2]; // 13 slots of gunz change it to the right amount :p? 0 = the gun 1 = the ammo

for(new i=0;i<14;++)
{
 GetPlayerWeaponData(playerid, i, wInfo[i][0], wInfo[i][1]);
}
Reply
#3

Quote:
Originally Posted by Outbreak
I've got a spawn weapons feature, and im trying to create something to see what weapons each player has...

The weapons are stored in an array, im wondering is it possible to store, 12 weapons in an array, all with varying ammo..

Then use another function to extract the info on what weapons the player has...
I've already got a command to see what weapons the player is carrying.. This isnt what im asking...

I want to store weapon info in 1 array, then be able to extract the info and display it as weapons id and ammo amount.

Is it possible?
Yes, this is a simpler way than Panda's imo

pawn Code:
new Ammo[12];
new Wep[12];
new WepName[12][20];
for(new i = 0; i < 12; i++)
{
  GetPlayerWeaponData(idx, i+1, Wep[i], Ammo[i]);
  GetWeaponName(Wep[i], WepName[i], 20);
}
Ammo = Weapon Ammo
Wep = Weapon ID
WepName = Weapon Name

the number inside [] is the slot

so if you want the ammo of the weapon is slot 5

Ammo[5]

The reason why it only goes to 12 is because in GetPlayerWeaponData I use +1
so it skips slot 0 because it's bugged and will go to 13 too


p.s credits to seifs admin script for helping me figure this out when I needed it a while ago
Reply
#4

would it worl if i used this below..

if the saved weapon array was "pInfo[playerid][SpawnWeaps]"

ammo array is "pInfo[playerid][SpawnAmmo]"

pawn Code:
new plSweaps[12];
new plAmmo[12];

format(plSweaps[0], 16, pInfo[playerid][SpawnWeaps][0]);//I'll only make 4 of these to keep the post short
format(plSweaps[1], 16, pInfo[playerid][SpawnWeaps][1]);//In the real code thre would be 12.
format(plSweaps[2], 16, pInfo[playerid][SpawnWeaps][2]);
format(plSweaps[3], 16, pInfo[playerid][SpawnWeaps][3]);

format(plAmmo[0], 16, pInfo[playerid][SpawnAmmo][0]);
format(plAmmo[1], 16, pInfo[playerid][SpawnAmmo][1]);
format(plAmmo[2], 16, pInfo[playerid][SpawnAmmo][2]);
format(plAmmo[3], 16, pInfo[playerid][SpawnAmmo][3]);
Would this work? if i was wanting to save each weapon ID and ammo amount?
Reply
#5

Quote:
Originally Posted by Outbreak
would it worl if i used this below..

if the saved weapon array was "pInfo[playerid][SpawnWeaps]"

ammo array is "pInfo[playerid][SpawnAmmo]"

pawn Code:
new plSweaps[12];
new plAmmo[12];

format(plSweaps[0], 16, pInfo[playerid][SpawnWeaps][0]);//I'll only make 4 of these to keep the post short
format(plSweaps[1], 16, pInfo[playerid][SpawnWeaps][1]);//In the real code thre would be 12.
format(plSweaps[2], 16, pInfo[playerid][SpawnWeaps][2]);
format(plSweaps[3], 16, pInfo[playerid][SpawnWeaps][3]);

format(plAmmo[0], 16, pInfo[playerid][SpawnAmmo][0]);
format(plAmmo[1], 16, pInfo[playerid][SpawnAmmo][1]);
format(plAmmo[2], 16, pInfo[playerid][SpawnAmmo][2]);
format(plAmmo[3], 16, pInfo[playerid][SpawnAmmo][3]);
Would this work? if i was wanting to save each weapon ID and ammo amount?
would be easier by doing this:

pawn Code:
for(new i=0;i<12;++)
{
 GetPlayerWeaponData(playerid, i, pInfo[playerid][SpawnWeaps][i], pInfo[playerid][SpawnAmmo][i]);
}
than save it or something.
Reply
#6

If you are using MySQL you could use my weapon functions:

EDIT: decided it was too big, moved to http://pastebin.com/f29820450

If you're not using MySQL, then I assume you have some sort of account system which you could implement into this code pretty easily. Just swap MySQLFetchAcctSingle for whatever you use to get a single user's data.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)