AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Dynamic Objects and Properties - v.0.0.32 - [2018.05.08] (https://forums.alliedmods.net/showthread.php?t=270519)

zipcore 09-06-2015 10:16

Re: Dynamic Objects and Properties
 
Quote:

Originally Posted by Neuro Toxin (Post 2337629)
It's up to 10 times faster.[/CODE]

Using a trie was a very good idea

headline 09-07-2015 04:18

Re: Dynamic Objects and Properties
 
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?

Neuro Toxin 09-07-2015 05:14

Re: Dynamic Objects and Properties
 
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.

DabuDos 09-14-2015 12:35

Re: Dynamic Objects and Properties
 
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)

Neuro Toxin 09-14-2015 19:41

Re: Dynamic Objects and Properties
 
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.

DabuDos 09-16-2015 10:29

Re: Dynamic Objects and Properties
 
Quote:

Originally Posted by Neuro Toxin (Post 2343037)
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.

Neuro Toxin 09-16-2015 19:17

Re: Dynamic Objects and Properties
 
Ok. I'll do something up on the weekend hopefully.

Dr. Api 09-18-2015 01:44

Re: Dynamic Objects and Properties
 
Nice, i'm learning more and more from you, keep going.
I will propably use for my next mod.

Nerus 12-26-2015 11:10

Re: Dynamic Objects and Properties
 
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

Neuro Toxin 12-27-2015 17:56

Re: Dynamic Objects and Properties
 
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);


All times are GMT -4. The time now is 14:36.

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