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

Is this the right useage of natives?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 04-08-2016 , 17:01   Is this the right useage of natives?
Reply With Quote #1

hi, I'm still in learn progress...

I dont want a master plugin and subplugins. I want several plugins with equal rights and without dependencies.
it this way a "clean" solution?
can i write a include like this?
can i add CreateNative/APLRes:AskPluginLoad2 in the include without getting headache?

inc.
PHP Code:
#if defined _mytestinc_included_
  #endinput
#endif
#define _mytestinc_included_

char IsTest[128] = "none";

public 
APLRes:AskPluginLoad2(Handle:myselfbool:lateString:error[], err_max)
{

    
CreateNative("SetTest"Native_SetTest);
    
CreateNative("GetTest"Native_GetTest);
}


native SetTest(const String:name[]);

public 
Native_SetTest(Handle:pluginargc)
{
    
decl String:buffer[64];
    
GetNativeString(1buffer64);
    
    
Format(IsTestsizeof(IsTest), buffer);
    
}


native GetTest(String:CurrentString[]);

public 
Native_GetTest(Handle:pluginargc)
{
    
SetNativeString(1IsTestsizeof(IsTest));

PHP Code:
#include <sourcemod>
#include <mytestinc>

public OnPluginStart()
{
    
    
RegConsoleCmd("sm_test1"TestOn);
}

public 
Action:TestOn(clientargs)
{
    
decl String:buffer[64];
    
GetTest(buffer);
    
PrintToChatAll("Old string: %s" ,buffer);
    
    
PrintToChatAll("Set new string: Test1");
    
SetTest("Test1");

PHP Code:
#include <sourcemod>
#include <mytestinc>

public OnPluginStart()
{
    
    
RegConsoleCmd("sm_test2"TestOn);
}

public 
Action:TestOn(clientargs)
{
    
decl String:buffer[64];
    
GetTest(buffer);
    
PrintToChatAll("Old string: %s" ,buffer);
    
    
PrintToChatAll("Set new string: Test2");
    
SetTest("Test2");

and so on...

thanks for reading!
shanapu is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-08-2016 , 18:17   Re: Is this the right useage of natives?
Reply With Quote #2

Unfortunately, you'll run into the problem of unable to bind the fake natives as internally in SM, only unique native names can be bound so multiple plugins trying to bind natives to the same name will run into 1 getting it first, others going into a failed state.
WildCard65 is offline
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 04-09-2016 , 00:31   Re: Is this the right useage of natives?
Reply With Quote #3

Quote:
Originally Posted by shanapu View Post
I dont want a master plugin and subplugins.
In a majority of cases, if you want to have numerous of plugins working together, having a master plugin is the most convenient and efficient way.

Here's a quick code on how to set up a basic native:

testplugin.inc
testplugin.sp
Phil25 is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 04-09-2016 , 13:27   Re: Is this the right useage of natives?
Reply With Quote #4

thanks for the replys!

ok, i accept it, need a master/core/api plugin.
I tinkered just before phil25 answered this version.

inc.
Spoiler

master
Spoiler

sub
Spoiler


and i will implement this!
Spoiler

Last edited by shanapu; 04-09-2016 at 13:28. Reason: formating fix
shanapu is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 04-09-2016 , 15:10   Re: Is this the right useage of natives?
Reply With Quote #5

Quote:
name = "My Plugin's Name",
This is not exactly right. More info in: Optional_Requirements_(SourceMod_Scripting)#C reating_a_Dependency
Kailo is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 04-09-2016 , 20:10   Re: Is this the right useage of natives?
Reply With Quote #6

Dynamic could be usefull here.

To create shared plugin settings you could.

Code:
Dynamic settings = new Dynamic();
settings.SetName("Plugin_Name");
Any plugin then can access this object by:

Code:
Dynamic settings = Dynamic.FindByName("Plugin_Name");
This is an example of how you can set members / settings in the dynamic object taken from the example plugin.

Code:
	// Creating dynamic objects is straight foward
	Dynamic someobj = Dynamic();

	// Setting integers, floats and booleans also
	someobj.SetInt("someint", 1);
	someobj.SetFloat("somefloat", 512.7);
	someobj.SetBool("somebool", true);

	// When dealing with strings...
	// you want to set an appropriate length if the value will change
	someobj.SetString("somestring", "What did you say?", 64);

	// If the value of a string will never change you might as well
	someobj.SetString("our_planets_name", "Earth");

	// Getting integers, floats and booleans is also straight foward
	int someint = someobj.GetInt("someint");
	float somefloat = someobj.GetFloat("somefloat");
	bool somebool = someobj.GetBool("somebool");

	// You can also include default values in case a member doesn't exist
	someint = someobj.GetInt("someint1", -1);
	somefloat = someobj.GetFloat("somefloat2", 7.25);
	somebool = someobj.GetBool("somebool2", false);

	// And the normal "extra" stuff to get a string in sourcespawn
	char somestring[64];
	someobj.GetString("somestring", somestring, sizeof(somestring));

	// You can also get an exact string by size
	int length = someobj.GetStringLength("our_planets_name");
	char[] our_planets_name = new char[length];
	someobj.GetString("our_planets_name", our_planets_name, length);

	// Dynamic supports type conversion!!!!!!!!!!!
	someint = someobj.GetInt("somefloat"); // rounds to floor
	somefloat = someobj.GetFloat("someint");
	someobj.GetString("somefloat", somestring, sizeof(somestring));
	someobj.GetString("somebool", somestring, sizeof(somestring));

	// You can even set dynamic objects within themselves
	Dynamic anotherobj = Dynamic();
	anotherobj.SetInt("someint", 128);
	someobj.SetObject("anotherobj", anotherobj);

	// You can also get and set Handles
	someobj.SetHandle("somehandle", CreateArray());
	Handle somehandle = someobj.GetHandle("somehandle");
	PushArrayCell(somehandle, 1);

	// Vectors are also supported like so
	float somevec[3] = {1.0, 2.0, 3.0};
	someobj.SetVector("somevec", somevec);
	someobj.GetVector("somevec", somevec);
__________________
Neuro Toxin 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 17:14.


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