AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved is in array ? (https://forums.alliedmods.net/showthread.php?t=299811)

leonardo121 07-26-2017 16:10

is in array ?
 
Hello, everyone!,

Okay, Suppose i have this:
PHP Code:

new arr1[ ] = { 1}
new 
arr2[ ] = { 3


check the value 1!

I already tried with 2 for loop, dynamic arrays, tries and nothing

help?!

HamletEagle 07-26-2017 16:21

Re: is in array ?
 
arr1[0] == 1?
arr2[1] == 1?

leonardo121 07-26-2017 16:25

Re: is in array ?
 
you're right but the problem is i dont know the index
Code:


arr1[ 0 ]
arr2[ 1 ]

the value 1 Can be the index 1 or 0, So I have to check all, I guess
i think the for loop is solution, but no success

leonardo121 07-27-2017 08:42

Re: is in array ?
 
bump

Black Rose 07-27-2017 09:06

Re: is in array ?
 
How to store and access your data. This is one of the first things you consider because it is the most central function of a plugin.

It's not worth using a static array for something like this. You only create limitations and the speed is really nothing to talk about.

One dynamic array (array) that contains all the information about the skins (unique id, model, name, w/e...).
One dynamic array (integer) for each player containing the unique id of all the skins they own.
ArraySize() will replace iPlayerSkinsCount.

The problem here is how to make a unique id for each skin so if one skin is removed from the server it won't corrupt the whole array and shift all of the skins.
That problem could be solved by storing all of the information of the skin in each player array, but that's just bad practice and will increase the data size of each player, both online and offline.
The simple solution would be to store a separate vault containing a unique identifier of a skin (a model name?) and connect that to a unique id. That way there's no possibility for corruption. Load it when the plugin loads the skins and give all the skins an unique id. If they don't have a unique id because they are new, give them one.

leonardo121 07-27-2017 09:18

Re: is in array ?
 
Quote:

Originally Posted by Black Rose (Post 2538110)
How to store and access your data. This is one of the first things you consider because it is the most central function of a plugin.

It's not worth using a static array for something like this. You only create limitations and the speed is really nothing to talk about.

One dynamic array (array) that contains all the information about the skins (unique id, model, name, w/e...).
One dynamic array (integer) for each player containing the unique id of all the skins they own.
ArraySize() will replace iPlayerSkinsCount.

The problem here is how to make a unique id for each skin so if one skin is removed from the server it won't corrupt the whole array and shift all of the skins.
That problem could be solved by storing all of the information of the skin in each player array, but that's just bad practice and will increase the data size of each player, both online and offline.
The simple solution would be to store a separate vault containing a unique identifier of a skin (a model name?) and connect that to a unique id. That way there's no possibility for corruption. Load it when the plugin loads the skins and give all the skins an unique id. If they don't have a unique id because they are new, give them one.

you're right, thanks for this, i will try it!
What is the best way to create a unique id for each one skin ?

Quote:

One dynamic array (integer) for each player containing the unique id of all the skins they own.
How to make it ?

I have a problem whean im storing a skin data on plugin_precache

when i put this *testing*

PHP Code:

 ArrayPushCell(g_aSkins, *SKIN UNIQUE ID*) 

the plugin giveme one error
Code:

invalid array handle provided (0)
i initialize the array like this
PHP Code:

g_aSkins ArrayCreate

what is this error ?

Black Rose 07-27-2017 09:47

Re: is in array ?
 
Perhaps you are initiating the array after you try to add data to it.
For example, plugin_precache is called before plugin_init and plugin_cfg.
Move array initialization to precache.

I'm going to create a complete example on the whole system I had in mind.

leonardo121 07-27-2017 09:54

Re: is in array ?
 
Quote:

Originally Posted by Black Rose (Post 2538118)
Perhaps you are initiating the array after you try to add data to it.
For example, plugin_precache is called before plugin_init and plugin_cfg.
Move array initialization to precache.

I'm going to create a complete example on the whole system I had in mind.

Ahh thats wayyy give-me the error!!

thankss for the help!

Quote:

I'm going to create a complete example on the whole system I had in mind.
Thanks :)

Black Rose 07-29-2017 11:37

Re: is in array ?
 
I will gladly integrate it more into your plugin if you give me more information or the code.

This will keep track of all skins, their unique ID's and which skins the player has been given. Everything saved in nVault of course.
Use AddSkinToPlayer() to give users skins and GetSkinInfo() to retrieve the information about a certain skin.
If you want it more efficient you can use the trie directly instead of using GetSkinInfo().

To enumerate all skins (for a buy menu):
Code:
new tempSkinID, NumSkins = ArraySize(ghAllSkins); for ( new i ; i < NumSkins ; i++ ) {     tempSkinID = ArrayGetCell(ghAllSkins, i); }

To enumerate a player's skins (for a selection menu):
Code:
new tempSkinID, NumSkins = ArraySize(ghPlayerSkins[id]); for ( new i ; i < NumSkins ; i++ ) {     tempSkinID = ArrayGetCell(ghPlayerSkins[id], i); }

If you have any questions just ask.
Spoiler

leonardo121 07-29-2017 12:53

Re: is in array ?
 
god!!, dude you are a genius !! thankss!, i will learn with this plugin!, damm!
Quote:

I will gladly integrate it more into your plugin if you give me more information or the code.
If I have any questions, I'll tell you!

I sent request on steam, because this is already off-topic, thanks, and keep coding, you are a master piece!


All times are GMT -4. The time now is 23:08.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.