Jump to content
  • 0
Sign in to follow this  
latheesan

Set the array variable value to value returned by a function

Question

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 by latheesan

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

@@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 by Winterfox

Share this post


Link to post
Share on other sites
  • 0

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.)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.