SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 13/06/2018, 11:50 PM   #1
Crystallize
Banned
 
Join Date: Aug 2013
Posts: 1,595
Reputation: 314
Default assign number automatically as array?

Let's say I have a 2d array

new OBJECTS[MAX_PLAYERS][5];

and it works like this
objects[1]
objects[2]
objects[3]

Now this is for global.

But let's say I want to make it per player.
How do i assign the numbers automatically.

EG:
Code:
cmd:object(playerid,params[])
{

objects[assign automatically per player instead of always being 1,2,3,4,5] = createplayerobjectxxx

return 1;

}
Crystallize is offline   Reply With Quote
Old 14/06/2018, 12:10 AM   #2
Ada32
Huge Clucker
 
Ada32's Avatar
 
Join Date: Apr 2013
Posts: 301
Reputation: 62
Default Re: assign number automatically as array?

loop through it
Ada32 is offline   Reply With Quote
Old 14/06/2018, 12:16 AM   #3
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Posts: 1,584
Reputation: 466
Default Re: assign number automatically as array?

You'll need the playerid together with the object ID so storing it in an array that is indexed by a playerid would be a good idea, depending on how many slots there should be per player.
NaS is offline   Reply With Quote
Old 14/06/2018, 12:25 AM   #4
jlalt
Banned
 
Join Date: Oct 2014
Location: Iran
Posts: 1,292
Reputation: 366
Default Re: assign number automatically as array?

If your first index is always as playerid.
->
PHP Code:
new OBJECTS[MAX_PLAYERS][5];
#define OBJECTS[%0] OBJECTS[playerid][%0]

cmd:object(playerid,params[])
{

objects[0] = createplayerobjectxxx
// now compiler repaced it with objects[player][0] =... 
return 1;


[ I dont know if I misunderstood or no D:]
jlalt is offline   Reply With Quote
Old 14/06/2018, 10:56 AM   #5
Crystallize
Banned
 
Join Date: Aug 2013
Posts: 1,595
Reputation: 314
Default Re: assign number automatically as array?

Quote:
Originally Posted by Ada32 View Post
loop through it
Loop is the only way?


Btw jalt I know that but I need an automatic number instead of 1,2,3,4,5 however I fixed it temporary.I need a permanent solution.
Crystallize is offline   Reply With Quote
Old 14/06/2018, 12:02 PM   #6
Ada32
Huge Clucker
 
Ada32's Avatar
 
Join Date: Apr 2013
Posts: 301
Reputation: 62
Default Re: assign number automatically as array?

Quote:
Originally Posted by Crystallize View Post
Loop is the only way?
what's wrong with looping?
Ada32 is offline   Reply With Quote
Old 14/06/2018, 09:42 PM   #7
AmigaBlizzard
Huge Clucker
 
Join Date: Jul 2012
Posts: 320
Reputation: 60
Default Re: assign number automatically as array?

If you want to use that array per player to store 5 objects each per player:
Code:
new objects[MAX_PLAYERS][5];

cmd:object(playerid, params[])
{
    objects[playerid][0] = createplayerobjectxxx
    objects[playerid][1] = createplayerobjectxxx
    objects[playerid][2] = createplayerobjectxxx
    objects[playerid][3] = createplayerobjectxxx
    objects[playerid][4] = createplayerobjectxxx

    return 1;
}
When player 3 uses this command, the server will have the value "3" for the "playerid" variable and will simply use it as a reference to access the array.
So it will create all 5 objects for player 3 in this array as if you had typed this:
Code:
new objects[MAX_PLAYERS][5];

cmd:object(playerid, params[])
{
    objects[3][0] = createplayerobjectxxx
    objects[3][1] = createplayerobjectxxx
    objects[3][2] = createplayerobjectxxx
    objects[3][3] = createplayerobjectxxx
    objects[3][4] = createplayerobjectxxx

    return 1;
}
The same will happen for player 27.
The server will simply paste "27" as the first index of the array.
AmigaBlizzard is offline   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
Value from array is not number? Killer#Mummy Scripting Help 3 28/07/2012 05:33 PM
Automatically exit the player's vehicle and enter it again automatically Pz Help Archive 2 15/04/2011 02:21 PM
How to assign this to array? Torran Help Archive 7 18/04/2010 05:28 PM
Array List assign to Variable member Help Archive 8 10/10/2009 12:15 AM
Random number, then pick string out of an array depending on number? Robbin237 Help Archive 3 26/02/2009 06:26 PM


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


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