Jump to content
  • 0

Set variable for other player?


GreenMagic793

Question


  • Group:  Members
  • Topic Count:  45
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   18
  • Joined:  08/18/15
  • Last Seen:  

Hey guys,

 

I'm trying to make a "Warning Points" NPC where a GM can assign a warning point to a player, as well as remove one. What I'm struggling with, is how to make it so that I can set a point (using a variable) for another player. Here's the relevant part of my script:

W_1:
mes "Enter the name of the player you wish to assign a warning point";
next;
input $@warnplayer$;
next;
mes "Now, please enter a brief reason for why this player is being assigned a warning point.";
next;
input $@warnreason$;
next;
set $@warnplayer$,#warningpoints+1;
mes "The player has been assigned a warning point.";
close;

W_2:
mes "Enter the name of the player you wish to have a warning point removed from.";
next;
input $@unwarnplayer$;
next;
mes "Now, please enter a brief reason for why this player is having a warning point removed.";
next;
input $@unwarnreason$;
next;
set $@unwarnplayer$,#warningpoints-1;
mes "The player has had a warning point removed.";
close;

I'm assuming that I'm just not using the "set" command correctly. Please help me fix my script so that I change variable for other players and not just the invoking player. Thank you.

Edited by greenmagic469
Link to comment
Share on other sites

8 answers to this question

Recommended Posts


  • Group:  Content Moderator
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  639
  • Reputation:   597
  • Joined:  11/25/11
  • Last Seen:  

As said in doc/script_commands.txt:

*set <variable>,<expression>{,<char_id>};
*set(<variable>,<expression>{,<char id>})

This command will set a variable to the value that the expression results in. 
Variables may either be set through this command or directly, much like any
other programming language (refer to the "Assigning variables" section).

This is the most basic script command and is used a lot whenever you try to do 
anything more advanced than just printing text into a message box.

    set @x,100;
    
will make @x equal 100.

    set @x,1+5/8+9;
    
will compute 1+5/8+9 (which is, surprisingly, 10 - remember, all numbers are 
integer in this language) and make @x equal it.

Returns the variable reference (since trunk r12870).

You can add a target character at the end of set, but you need it's CharID:

You're using the function set incorrectly, It's:

set #warningpoints, #warningpoints + 1;

// It means, set a new value to variable #warningpoints.
// The new value is the current value of #warningpoints plus one.

Now, let's target it to a player.
Since you need to get the Char ID and you only have the Char Name, we need to convert it, using getcharid():

*getcharid(<type>{,"<character name>"})

This function will return a unique ID number of the invoking character, or, if a 
character name is specified, of that player.

Type is the kind of associated ID number required:

 0 - Character ID
 1 - Party ID
 2 - Guild ID
 3 - Account ID
 4 - Battle Ground ID

For most purposes other than printing it, a number is better to have than a name 
(people do horrifying things to their character names).

If the character is not in a party or not in a guild, the function will return 0 
if guild or party number is requested. If a name is specified and the character 
is not found, 0 is returned.

If getcharid(0) returns a zero, the script got called not by a character and 
doesn't have an attached RID. Note that this will cause the map server to
print "player not attached!" error messages, so it is preferred to use
"playerattached" to check for the character attached to the script.

if (getcharid(2) == 0)
	mes "Only members of a guild are allowed here!";

Since you got the name via input:

getcharid(0, $@warnplayer$)

Let's attach it to set:

set #warningpoints, #warningpoints + 1, getcharid(0, $@warnplayer$);

// It means, set a new value for #warningpoints.
// The new value is the current value of #warningpoints plus one.
// Set it to the Char ID of the given Char Name via the variable $@warnplayer$ set by input.

A simple look in doc/script_commands.txt could lead you to the solution...

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  45
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   18
  • Joined:  08/18/15
  • Last Seen:  

Thanks a lot for your reply.

 

I actually managed to do what I wanted in a slightly different way but what you said is good to know.

 

Instead of worrying about trying to set a variable for another player directly, I just used attachrid to switch the script over and change the variable as if the target player had invoked the script.

W_1:
mes "Enter the name of the player you wish to assign a warning point";
next;
input @warnplayer$;
next;
mes "Now, please enter a brief reason for why this player is being assigned a warning point.";
next;
input $@warnreason$;
next;
if(isloggedin(@warnplayer$)) goto WarnPoint;
mes "Warning Point send failed, the target player is not online.";
close;

WarnPoint:
mes "The player has been warned.";
close2;
attachrid(getcharid(3,@warnplayer$));
dispbottom "You have been given 1 Warning Point for the following reason: " + $@warnreason$ + "";
set #warningpoints,#warningpoints+1;

I'm not sure if there's some disadvantage to the way I've done it, but it seems to work just fine.

Link to comment
Share on other sites


  • Group:  Content Moderator
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  639
  • Reputation:   597
  • Joined:  11/25/11
  • Last Seen:  

I thought about suggesting it, it's a really fancier way, but, focused on teach you what you wanted to learn.
Glad you made it.

Edited by Haziel
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  45
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   18
  • Joined:  08/18/15
  • Last Seen:  

I thought of another question for you regarding this matter...

 

So now that I know how to set a variable for another player, how do I call on that variable to view it myself?

 

For example, let's say I award 3 warning points to a player. What command would I use to call that variable so that I can view it myself? So something like this...

 

mes "Would you like to see a player's warning points?";

menu "Yes.",A_1,"No.",A_2;

 

 

A_1:

mes "Please input the name of the player you wish to see points for.";

next;

input @playersearchname$;

next;

mes "This player has " + #warningpoints(@playersearchname$) + " warning points.";

close;

 

A_2:

close;

 

Would it be something like that? Or is it more complicated?

Link to comment
Share on other sites


  • Group:  Content Moderator
  • Topic Count:  22
  • Topics Per Day:  0.00
  • Content Count:  639
  • Reputation:   597
  • Joined:  11/25/11
  • Last Seen:  

For that matter, you'll need to do a query_sql, otherwise, it'll only works when the character is online.

set .@accid, "SELECT `account_id` FROM `char` WHERE `name` =" + @playersearchname;
set .@wp, "SELECT `value` FROM `acc_reg_num` WHERE `key` = "#warningpoints" AND account_id = " + .@accid;

mes .@wp + " points.";
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  45
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   18
  • Joined:  08/18/15
  • Last Seen:  

Thanks for your reply.

 

I'm using a TXT server so an sql query isn't really possible for me. Can you help me understand the commands you've written? I've actually never used the 'SELECT' function, ive always used menu so im a little foggy on where exactly that bit you posted goes in relation to my script. I really appreciate your continued help.

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2350
  • Joined:  10/28/11
  • Last Seen:  

input .@charname$;
.@target = getcharid(3,.@charname$);
.@origin = getcharid(3);
if ( attachrid( .@target ) ) {
	.@warningpoints = #warningpoints;
	attachrid( .@origin );
	mes "Warning = "+.@warningpoints;
	if ( select( "Set new value","Cancel" ) == 1 ) {
		input .@value;
		close2;
		if ( attachrid( .@target ) ) {
			#warningpoints = .@value;
			dispbottom "Warning Point updated to "+#warningpoints;
		}
		else {
			dispbottom "Char not found.";
		}
		end;
	}
} 
else {
	mes "Char not found.";
}
close;

since you're using TXT there's no way for you set update the data using SQL for offline char.

Link to comment
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.   Paste as plain text instead

  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.

×
×
  • Create New...