Raised This Month: $119 Target: $400
 29% 

Dynamic Objects and Properties - v.0.0.32 - [2018.05.08]


Post New Thread Reply   
 
Thread Tools Display Modes
zipcore
Veteran Member
Join Date: Mar 2010
Location: m_flZipcore
Old 09-06-2015 , 10:16   Re: Dynamic Objects and Properties
Reply With Quote #11

Quote:
Originally Posted by Neuro Toxin View Post
It's up to 10 times faster.[/CODE]
Using a trie was a very good idea
__________________
zipcore is offline
Headline
SourceMod Moderator
Join Date: Mar 2015
Old 09-07-2015 , 04:18   Re: Dynamic Objects and Properties
Reply With Quote #12

Okay, so I get that you can store integers, floats, and strings in this thing. For someone who's first "language" is SourcePawn: When and Why should I use this?

Last edited by Headline; 09-07-2015 at 04:19.
Headline is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-07-2015 , 05:14   Re: Dynamic Objects and Properties
Reply With Quote #13

Hi headline

Great question.

The main purpose of use is when you require irregular data sets to be stored and shared between plugins. An example maybe storing times for a timer plugin. You would not be required to store arrays for level / player times and could simply use a dynamic object for storage.

You could also hook member data changes which will call forwards to each plugin that has hooked the dynamic object. With this your plugins can be aware of changes in real time without constantly checking for updated data via natives or global forwards.

You wouldn't use dynamic objects for plain arrays that dont need to be shared via other plugins.

If you've ever had a moment where you wish you could make your own netprop. This is a viable solution that would allow such functionality without the need for you to write natives.

I'm personally using this to create member sets for each player. Where one plugin can store members like a playerid and others can read them easily and or hook member changes. I also hook changes and use them to update a mysql databases to synchronise changes automatically to and from plugins with no effort at all.

I have some planned changes where <dynamic>(1-maxplayers) will always relate to data for the corresponding client index that auto initialises and disposes with client connect and disconnect events.
__________________
Neuro Toxin is offline
DabuDos
Junior Member
Join Date: Feb 2015
Location: Germany
Old 09-14-2015 , 12:35   Re: Dynamic Objects and Properties
Reply With Quote #14

Got something weird.

PHP Code:
L 09/14/2015 18:11:29SourceMod error session started
L 09
/14/2015 18:11:29Info (map "de_dust2") (file "errors_20150914.log")
L 09/14/2015 18:11:29: [SMNative "ThrowNativeError" reportedUnable to access dynamic handle 0
L 09
/14/2015 18:11:29: [SMDisplaying call stack trace for plugin "dynamic.smx":
L 09/14/2015 18:11:29: [SM]   [0]  Line 149E:\CSGO\Sourcemod\tracker\addons\sourcemod\scripting\dynamic.sp::Native_Dynamic_IsValidCollectionIndex()
L 09/14/2015 18:11:29: [SMNative "Dynamic_IsValidCollectionIndex" reportedError encountered while processing a dynamic native
L 09
/14/2015 18:11:29: [SMDisplaying call stack trace for plugin "dynamic.smx":
L 09/14/2015 18:11:29: [SM]   [0]  Line 401E:\CSGO\Sourcemod\tracker\addons\sourcemod\scripting\dynamic.sp::Native_Dynamic_SetInt()
L 09/14/2015 18:11:29: [SMNative "Dynamic_SetInt" reportedError encountered while processing a dynamic native
L 09
/14/2015 18:11:29: [SMDisplaying call stack trace for plugin "DynamicTest1.smx":
L 09/14/2015 18:11:29: [SM]   [0]  Line 73D:\SourcemodPlugins\include\dynamic.inc::Dynamic.SetInt()
L 09/14/2015 18:11:29: [SM]   [1]  Line 9D:\SourcemodPlugins\DynamicTest1.sp::OnPluginStart()
L 09/14/2015 18:13:08: [SMNative "ThrowNativeError" reportedUnable to access dynamic handle 0
L 09
/14/2015 18:13:08: [SMDisplaying call stack trace for plugin "dynamic.smx":
L 09/14/2015 18:13:08: [SM]   [0]  Line 149E:\CSGO\Sourcemod\tracker\addons\sourcemod\scripting\dynamic.sp::Native_Dynamic_IsValidCollectionIndex()
L 09/14/2015 18:13:08: [SMNative "Dynamic_IsValidCollectionIndex" reportedError encountered while processing a dynamic native
L 09
/14/2015 18:13:08: [SMDisplaying call stack trace for plugin "dynamic.smx":
L 09/14/2015 18:13:08: [SM]   [0]  Line 401E:\CSGO\Sourcemod\tracker\addons\sourcemod\scripting\dynamic.sp::Native_Dynamic_SetInt()
L 09/14/2015 18:13:08: [SMNative "Dynamic_SetInt" reportedError encountered while processing a dynamic native
L 09
/14/2015 18:13:08: [SMDisplaying call stack trace for plugin "DynamicTest1.smx":
L 09/14/2015 18:13:08: [SM]   [0]  Line 73D:\SourcemodPlugins\include\dynamic.inc::Dynamic.SetInt()
L 09/14/2015 18:13:08: [SM]   [1]  Line 9D:\SourcemodPlugins\DynamicTest1.sp::OnPluginStart() 
if you need the code, tell me (well nothing special, I just made a basic SetInt Plugin and another that should receive the value)
DabuDos is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-14-2015 , 19:41   Re: Dynamic Objects and Properties
Reply With Quote #15

Quote:
L 09/14/2015 - 18:11:29: [SM] Native "ThrowNativeError" reported: Unable to access dynamic handle 0
Looks like it's not initialised.

Code:
Dynamic someobject = Dynamic();
You then need to share someobject. Internally someobject is an integer and represents the internal index for the collection array. The best idea is to pass it through a native.

Code:
Dynamic someobject = view_as<Dynamic>(Native_GetDynamicObject());
You would return someobject in the native like so.

Code:
return view_as<int>(someobject);
If you still encounter problems with this advise feel free to post code for both plugins.
__________________
Neuro Toxin is offline
DabuDos
Junior Member
Join Date: Feb 2015
Location: Germany
Old 09-16-2015 , 10:29   Re: Dynamic Objects and Properties
Reply With Quote #16

Quote:
Originally Posted by Neuro Toxin View Post
Looks like it's not initialised.

Code:
Dynamic someobject = Dynamic();
You then need to share someobject. Internally someobject is an integer and represents the internal index for the collection array. The best idea is to pass it through a native.

Code:
Dynamic someobject = view_as<Dynamic>(Native_GetDynamicObject());
You would return someobject in the native like so.

Code:
return view_as<int>(someobject);
If you still encounter problems with this advise feel free to post code for both plugins.
Well, I get many errors with "undefined symbol" now, I don't really understand why.
Can you maybe post a basic code for one plugin that sends the value and another plugin that receives the value? Maybe thats easier to understand for me & others.
DabuDos is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-16-2015 , 19:17   Re: Dynamic Objects and Properties
Reply With Quote #17

Ok. I'll do something up on the weekend hopefully.
__________________
Neuro Toxin is offline
Dr. Api
BANNED
Join Date: Mar 2015
Location: France
Old 09-18-2015 , 01:44   Re: Dynamic Objects and Properties
Reply With Quote #18

Nice, i'm learning more and more from you, keep going.
I will propably use for my next mod.
Dr. Api is offline
Nerus
Senior Member
Join Date: Aug 2010
Location: Poland
Old 12-26-2015 , 11:10   Re: Dynamic Objects and Properties
Reply With Quote #19

Nice to see similar objectives like in C# and Java in SM I head problems with methodsmaps, now I think that u solve my problem, THX !

I always create same question in any topic of plugins, but this is my first time in lib thread: will you add dynamic to github please ?

P.S. One more thing:

Quote:
someobject.GetInt("m_iSomeField");
Please add second 'default' parameter if value not found.

I had some errors i try to create dynamic player like:
Quote:
Dynamic player = Dynamic();
Next I added some values like:
Quote:
player.SetString("steam_id3", steam_id3, sizeof(steam_id3));
get working correct after set.

Next I added dynamic player to array based on client id:
Quote:
Players[client] = player;
Last code check player is INVALID_HANDLE and result: is invalid.
Quote:
if(player == INVALID_HANDLE)
What is wrong ?


Regards,
Nerus

Last edited by Nerus; 12-26-2015 at 13:48.
Nerus is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 12-27-2015 , 17:56   Re: Dynamic Objects and Properties
Reply With Quote #20

To check if a object is valid use...

Code:
if (player.IsValid)


You also need to Dispose() your object OnClientDisconnect. These objects are not managed and will cause memory leaks if not disposed of correctly.

Code:
player.Dispose();


GetInt() already supports default values as the second parameter.

Code:
int defaultvalue = player.GetInt ("notset", 123);
__________________
Neuro Toxin is offline
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

Forum Jump


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


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