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

[HELP] Passing a string to native function that returns an int


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
imindfreak
Senior Member
Join Date: Oct 2007
Location: 127.0.0.1
Old 10-14-2017 , 08:06   [HELP] Passing a string to native function that returns an int
Reply With Quote #1

Greetings!

I'm having trouble passing a string to a native function that returns an int.
When I run the example usage, I get an argument type mismatch (argument 1).
The native function takes a string and I pass a string to it but it doesn't work.
Basically, I want to lookup a user's bank balance using SteamID from another plugin (not by index).
The reason for this is because if a player is offline, I want to add/remove from their balance by SteamID, which is saved by nvault.

.inc
PHP Code:
#pragma reqlib "mylib"

native get_user_balance_steamid(const sid[]) 
main .sma
PHP Code:
public plugin_natives()
{
    
register_library("mylib")
    
    
register_native("get_user_balance_steamid","_get_user_balance_steamid")
}

public 
_get_user_balance_steamid(iPlugin,iParams)
{
    if(
iParams != 1)
        return 
PLUGIN_CONTINUE
    
    
//copy the new string over
    
new sid[35];
    
set_string1sidcharsmax(sid))
    
    
//in case the string is empty
    
if(!sid[0])
        return 
PLUGIN_CONTINUE
    
    
//if it's valid and doesn't return -1, go ahead and return the amount    
    
if(get_balance_steamid(sid))
        
//This calls a function that takes a string (the steam id) and looks into nvault for a     matching vaultkey with that steamid and returns the vaultdata (the balance, an int).
        
return get_balance_steamid(sid
    
    return -
1

Example usage
PHP Code:
public AddMoney(sid[], amount)
{
    
//argument type mismatch (argument 1) error here
    
new balance get_user_balance_steamid(sid);
    
client_print(idprint_chat"%s"balance);

Thank you for your help!
__________________
BeastGaming Community - Map Maker & Coder.

Last edited by imindfreak; 10-14-2017 at 08:08.
imindfreak is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-14-2017 , 08:35   Re: [HELP] Passing a string to native function that returns an int
Reply With Quote #2

You want to retrieve a string, so you should use get_string.
__________________
Arkshine is offline
imindfreak
Senior Member
Join Date: Oct 2007
Location: 127.0.0.1
Old 10-14-2017 , 16:21   Re: [HELP] Passing a string to native function that returns an int
Reply With Quote #3

I changed it to get_string(1, sid, charsmax(sid)) but I'm still getting an argument type mismatch (argument 1) on AddMoney function when I use the get_user_balance_steamid or set_user_balance_steamid. I'm not sure what the issue is because I'm passing a string to a native function that takes a string param...
__________________
BeastGaming Community - Map Maker & Coder.
imindfreak is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 10-14-2017 , 17:56   Re: [HELP] Passing a string to native function that returns an int
Reply With Quote #4

In your example there is no id for client_print.
Anyway it works for me without errors.
Code:
#include <amxmodx> native get_user_balance_steamid(const sid[])  public AddMoney(id, sid[], amount) {     new balance = get_user_balance_steamid(sid);     client_print(id, print_chat, "%s", balance); }
Try to compile this code and look there is no errors.
KiLLeR. is offline
imindfreak
Senior Member
Join Date: Oct 2007
Location: 127.0.0.1
Old 10-14-2017 , 19:25   Re: [HELP] Passing a string to native function that returns an int
Reply With Quote #5

Quote:
Originally Posted by KiLLeR. View Post
In your example there is no id for client_print.
Anyway it works for me without errors.
Code:
#include <amxmodx> native get_user_balance_steamid(const sid[])  public AddMoney(id, sid[], amount) {     new balance = get_user_balance_steamid(sid);     client_print(id, print_chat, "%s", balance); }
Try to compile this code and look there is no errors.
The client_print was just an example for the thread, but I actually don't need the player's index.
I didn't specify in my main plugin that sid[] is a string not an integer lol.

In main plugin -
PHP Code:
//I had this
native get_user_balance_steamid(sid);
//I should've had this
native get_user_balance_steamid(sid[]); 
Thank you for your help everyone!
__________________
BeastGaming Community - Map Maker & Coder.
imindfreak is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 10-15-2017 , 11:24   Re: [HELP] Passing a string to native function that returns an int
Reply With Quote #6

@imindfreak
Code:
native get_user_balance_steamid(sid[]);
->
Code:
native get_user_balance_steamid(const sid[]);

Also:
Code:
    //if it's valid and doesn't return -1, go ahead and return the amount        if(get_balance_steamid(sid))         //This calls a function that takes a string (the steam id) and looks into nvault for a     matching vaultkey with that steamid and returns the vaultdata (the balance, an int).         return get_balance_steamid(sid)         return -1
Code:
if(get_balance_steamid(sid))
It's an alternative of this:
Code:
if(get_balance_steamid(sid) != 0)
So, it doesn't check for != -1.
You can write just:
Code:
return get_balance_steamid(sid);
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
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 08:02.


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