latheesan 15 Posted August 4, 2015 (edited) I have the following script: // Main Script- script L_Test -1,{ // Configuration set .useLastMAC,0; // When player logins into game OnPCLoginEvent: // Load account info setarray @accountInfo$,callfunc("L_GetAccountInfo"); debugmes "[OnPCLoginEvent] account_id = " + @accountInfo$[0]; debugmes "[OnPCLoginEvent] last_ip = " + @accountInfo$[1]; debugmes "[OnPCLoginEvent] last_mac = " + @accountInfo$[2]; end; }// Helper Function: Load Account Info// Returns Array (0 = Account ID | 1 = Last IP | 2 = Last Mac)function script L_GetAccountInfo { setarray .accountInfo$[0],getcharid(3); if (getvariableofnpc(.useLastMAC,"L_Test") == 1) { query_sql("SELECT last_ip, last_mac FROM login WHERE account_id = "+ .accountInfo$[0], .last_ip$, .last_mac$); setarray .accountInfo$[1],.last_ip$,.last_mac$; } else { query_sql("SELECT last_ip FROM login WHERE account_id = "+ .accountInfo$[0], .last_ip$); setarray .accountInfo$[1],.last_ip$,"-"; } debugmes "[L_GetAccountInfo] account_id = " + .accountInfo$[0]; debugmes "[L_GetAccountInfo] last_ip = " + .accountInfo$[1]; debugmes "[L_GetAccountInfo] last_mac = " + .accountInfo$[2]; return .accountInfo$;} With this script enabled, when I login - I get the following output in map server: [Debug]: script debug : 2000000 110034179 : [L_GetAccountInfo] account_id = 2000000[Debug]: script debug : 2000000 110034179 : [L_GetAccountInfo] last_ip = 127.0.0.1[Debug]: script debug : 2000000 110034179 : [L_GetAccountInfo] last_mac = -[Debug]: script debug : 2000000 110034179 : [OnPCLoginEvent] account_id = 2000000[Debug]: script debug : 2000000 110034179 : [OnPCLoginEvent] last_ip =[Debug]: script debug : 2000000 110034179 : [OnPCLoginEvent] last_mac = Basically, within the function L_GetAccountInfo I load account details (account_id, last_ip, last_mac) based on npc config and return it as a array. When I set this function ret val to a array variable, it doesn't seem to be working. Any ideas? Only the first index's value appears to be returned by the function (2nd and 3rd index is empty). Edited August 4, 2015 by latheesan Quote Share this post Link to post Share on other sites
0 Winterfox 83 Posted August 4, 2015 (edited) @@latheesan setarray takes a list of arguments, you just gave him the first element of your accountinfo array. To get a copy of the array in your function into your npc you need to copy it. You also should put config values in a oninit segement in a script that can't be directly called it will never get executed otherwise. // Main Script- script L_Test -1,{ OnInit: // Configuration set .useLastMAC,0; end; // When player logins into game OnPCLoginEvent: // Load account info copyarray @accountInfo$, callfunc("L_GetAccountInfo"), 3; debugmes "[OnPCLoginEvent] account_id = " + @accountInfo$[0]; debugmes "[OnPCLoginEvent] last_ip = " + @accountInfo$[1]; debugmes "[OnPCLoginEvent] last_mac = " + @accountInfo$[2]; end; }// Helper Function: Load Account Info// Returns Array (0 = Account ID | 1 = Last IP | 2 = Last Mac)function script L_GetAccountInfo { setarray .@accountInfo$[0], getcharid( 3 ); if ( getvariableofnpc( .useLastMAC, "L_Test" ) == 1 ) { query_sql( "SELECT last_ip, last_mac FROM login WHERE account_id = " + .@accountInfo$[0], .@last_ip$, .@last_mac$ ); setarray .@accountInfo$[1], .@last_ip$, .@last_mac$; } else { query_sql("SELECT last_ip FROM login WHERE account_id = "+ .@accountInfo$[0], .@last_ip$); setarray .@accountInfo$[1],.@last_ip$, "-"; } debugmes "[L_GetAccountInfo] account_id = " + .@accountInfo$[0]; debugmes "[L_GetAccountInfo] last_ip = " + .@accountInfo$[1]; debugmes "[L_GetAccountInfo] last_mac = " + .@accountInfo$[2]; return .@accountInfo$;} Edited August 4, 2015 by Winterfox Quote Share this post Link to post Share on other sites
0 latheesan 15 Posted August 5, 2015 @@Winterfox Thanks, that did the trick. I forgot about copyarray Quote Share this post Link to post Share on other sites
0 Emistry 145 Posted August 14, 2015 there is no need to use array... and much the script so complicated. this is sufficient. - script sample#ip_mac -1,{ OnInit: .useLastMAC = 1; end; OnPCLoginEvent: @accinfo_aid = getcharid(3); query_sql("SELECT `"+( ( .useLastMAC )?"lasp_mac":"last_ip" )+"` FROM login WHERE account_id = "+ @accinfo_aid , @accinfo_ip_mac$ ); dispbottom "Account ID : "+@accinfo_aid ; dispbottom "Last "+( ( .useLastMAC )? "MAC":"IP" )+" : "+@accinfo_ip_mac$; end;} just save the variable in a char temporary variable that last until your char logout. @accinfo_aid @accinfo_ip_mac$ these 2 variable could store the IP/MAC and AccountID that you need. (accountID is alway available using the [wiki=getcharid](3) tho.) Quote Share this post Link to post Share on other sites
I have the following script:
With this script enabled, when I login - I get the following output in map server:
Basically, within the function L_GetAccountInfo I load account details (account_id, last_ip, last_mac) based on npc config and return it as a array.
When I set this function ret val to a array variable, it doesn't seem to be working.
Any ideas? Only the first index's value appears to be returned by the function (2nd and 3rd index is empty).
Edited by latheesanShare this post
Link to post
Share on other sites