SA-MP Forums

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

 
 
Thread Tools Display Modes
Old 23/04/2009, 08:32 PM   #1
Outbreak
Huge Clucker
 
Join Date: Dec 2008
Posts: 303
Reputation: 3
Default Question about arrays

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?
Outbreak is offline  
Old 23/04/2009, 08:37 PM   #2
Think
Gangsta
 
Think's Avatar
 
Join Date: Nov 2007
Posts: 810
Reputation: 39
Default Re: Question about arrays

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]);
}
__________________
"If we cant stand strong alone, there is no fucking way we can stand strong united" - Kevin T Thoms
Think is offline  
Old 23/04/2009, 08:38 PM   #3
lavamike
Huge Clucker
 
lavamike's Avatar
 
Join Date: Mar 2008
Posts: 384
Reputation: 2
Default Re: Question about arrays

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
lavamike is offline  
Old 23/04/2009, 09:16 PM   #4
Outbreak
Huge Clucker
 
Join Date: Dec 2008
Posts: 303
Reputation: 3
Default Re: Question about arrays

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?
Outbreak is offline  
Old 23/04/2009, 09:20 PM   #5
Think
Gangsta
 
Think's Avatar
 
Join Date: Nov 2007
Posts: 810
Reputation: 39
Default Re: Question about arrays

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.
__________________
"If we cant stand strong alone, there is no fucking way we can stand strong united" - Kevin T Thoms
Think is offline  
Old 23/04/2009, 10:56 PM   #6
1337pr0
Big Clucker
 
Join Date: Feb 2008
Posts: 141
Reputation: 0
Default Re: Question about arrays

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.
1337pr0 is offline  
 

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
[Question] Arrays ArTisT Help Archive 1 20/06/2010 06:44 PM
Help with arrays Gozerr Help Archive 3 28/02/2010 01:07 PM
Arrays •Ajax• Help Archive 3 28/11/2009 06:40 AM
Help With Arrays StrickenKid Help Archive 1 01/10/2009 09:01 PM


All times are GMT. The time now is 02:15 AM.


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