Raised This Month: $32 Target: $400
 8% 

return string[ id ] from native


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JocAnis
Veteran Member
Join Date: Jun 2010
Old 08-18-2019 , 19:00   return string[ id ] from native
Reply With Quote #1

hello guys..i know topics with this name already exists, i was searching through them and i couldnt make it to work...any help is welcomed...what im tryting to do:

plugin1: print player's country (from plugin2)

client_print( id, print_chat, "he is from %s", player_country( id ) )

so what should plugin2 do with set_string, i cant get these get_params, no matter which stype i try to use, too confusing to me...tryed almost every combination, and no good results

plugins2 has that string which is storing every player's country:
g_szCountry[ 33 ][ 32 ]

thanks in advance!
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-18-2019 , 19:16   Re: return string[ id ] from native
Reply With Quote #2

You can't just return strings, you have to pass them byref.
PHP Code:
#define MAX_PLAYERS 32

new g_szCountryMAX_PLAYERS ][ 32 ];

// get_player_country( id, szOutPut[ ], iSize )
public YourNativeiPluginiParams )
{
    
set_string2g_szCountryget_param) ], get_param) );

PHP Code:
public plugin_init( )
{
    
register_clcmd"say /country""MyCountry" );
}

public 
MyCountryid )
{
    new 
szCountry32 ];
    
get_player_countryidszCountrycharsmaxszCountry ) );

    
client_printidprint_chat"My country is: %s"szCountry );

__________________

Last edited by edon1337; 08-18-2019 at 19:22.
edon1337 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-18-2019 , 19:23   Re: return string[ id ] from native
Reply With Quote #3

player_country() should be the same as all other functions that are used to get strings e.g. get_user_name(), get_user_authid(), etc. I.e. it should be player_country(id, szString, iLengthOfString) then you would do this:

Code:
new szCountry[32]
player_country(id, szCountry, charsmax(szCountry))
client_print(id, print_chat, "%s", szCountry)
So, in your custom native, you need to populate szString with no more than iLengthOfString characters.
__________________

Last edited by fysiks; 08-18-2019 at 19:24.
fysiks is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 08-18-2019 , 19:26   Re: return string[ id ] from native
Reply With Quote #4

...thanks edon, its working well now

thanks to fysiks also, but i cant think deep to it

i must bookmark this topic..if i start to think again how is it working i will have a headache again
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-18-2019 , 19:28   Re: return string[ id ] from native
Reply With Quote #5

Quote:
Originally Posted by JocAnis View Post
i must bookmark this topic..if i start to think again how is it working i will have a headache again
It's simple, you simply set your variable's values to your native's parameters and then use the native to retrieve that value.
__________________
edon1337 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 06:38.


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