Raised This Month: $51 Target: $400
 12% 

Solved is in array ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
leonardo121
Member
Join Date: Sep 2013
Old 07-26-2017 , 16:10   is in array ?
Reply With Quote #1

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

Last edited by leonardo121; 07-30-2017 at 08:37.
leonardo121 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-26-2017 , 16:21   Re: is in array ?
Reply With Quote #2

arr1[0] == 1?
arr2[1] == 1?
__________________
HamletEagle is offline
leonardo121
Member
Join Date: Sep 2013
Old 07-26-2017 , 16:25   Re: is in array ?
Reply With Quote #3

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

Last edited by leonardo121; 07-26-2017 at 16:29.
leonardo121 is offline
leonardo121
Member
Join Date: Sep 2013
Old 07-27-2017 , 08:42   Re: is in array ?
Reply With Quote #4

bump

Last edited by leonardo121; 07-27-2017 at 10:36.
leonardo121 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-27-2017 , 09:06   Re: is in array ?
Reply With Quote #5

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.

Last edited by Black Rose; 07-27-2017 at 09:07.
Black Rose is offline
leonardo121
Member
Join Date: Sep 2013
Old 07-27-2017 , 09:18   Re: is in array ?
Reply With Quote #6

Quote:
Originally Posted by Black Rose View Post
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 ?
leonardo121 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-27-2017 , 09:47   Re: is in array ?
Reply With Quote #7

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.

Last edited by Black Rose; 07-27-2017 at 09:49.
Black Rose is offline
leonardo121
Member
Join Date: Sep 2013
Old 07-27-2017 , 09:54   Re: is in array ?
Reply With Quote #8

Quote:
Originally Posted by Black Rose View Post
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
leonardo121 is offline
Old 07-27-2017, 17:32
leonardo121
This message has been deleted by leonardo121.
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-29-2017 , 11:37   Re: is in array ?
Reply With Quote #9

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

Last edited by Black Rose; 07-29-2017 at 11:50.
Black Rose is offline
leonardo121
Member
Join Date: Sep 2013
Old 07-29-2017 , 12:53   Re: is in array ?
Reply With Quote #10

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!
__________________
" In the end it doesn't even matter " - Linkin Park

Last edited by leonardo121; 07-29-2017 at 12:55.
leonardo121 is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 05:47.


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