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

Solved First time using natives


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SZOKOZ
Member
Join Date: Jan 2014
Old 07-28-2017 , 08:31   First time using natives
Reply With Quote #1

I'm trying to assign a string to an array provided by the buffer parameter of my native. Trying to get it to work had an unexpected side effect. What is the correct way to do it?

Prototype:
Code:
native int getSecretName(int clientIndex, const char[] buffer, int buffersize=MAX_NAME_LENGTH);
Implementation:
Code:
public int Native_getSecretName(Handle plugin, int numparams){
	
	int clientID;
	int buffersize;
	any name[MAX_NAME_LENGTH];
	clientID = GetNativeCell(1);
	
	if (clientID < 1 || clientID > MAXPLAYERS){
		return -1;
	}
	
	name = view_as<any>(secretNames[clientID]);
	
	buffersize = GetNativeCell(3);
	
	SetNativeArray(2, name, buffersize);
	
	return 0;
}
__________________
May still be available for SM scripting. Just look at my Steam profile regarding my availability.
My Steam

Last edited by SZOKOZ; 07-28-2017 at 08:48. Reason: Solved
SZOKOZ is offline
Deathknife
Senior Member
Join Date: Aug 2014
Old 07-28-2017 , 08:38   Re: First time using natives
Reply With Quote #2

PHP Code:
int SetNativeString(int param, const char[] sourceint maxlengthbool utf8=trueint &bytes=0
PHP Code:
SetNativeString(2namebuffersize); 
Also char[] buffer should not be a constant.
__________________
Deathknife is offline
SZOKOZ
Member
Join Date: Jan 2014
Old 07-28-2017 , 08:44   Re: First time using natives
Reply With Quote #3

Quote:
Originally Posted by Deathknife View Post
Also char[] buffer should not be a constant.
Ooops

Thanks for the help by suggesting setnativestring. I've seen it so many times but it just evaded my mind.
__________________
May still be available for SM scripting. Just look at my Steam profile regarding my availability.
My Steam
SZOKOZ 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 20:47.


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