Small doubt
#1

I made this command to set a value for certain player's variable (Variable here is PlayerPassword)
Код:
	if(strcmp(cmd, "/pass", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(gPlayerLogged[playerid] == 0)
	        {
	            SendClientMessage(playerid, COLOR_GREY, "   You are not Logged in !");
	            return 1;
	        }
	        new tmppass[64];
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_WHITE, "USAGE: /pass [password]");
				return 1;
			}
			format(string, sizeof(string), "You have entered the gate password to %s.", tmp);
			SendClientMessage(playerid, COLOR_YELLOW, string);
			PlayerPassword(playerid) =
			strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
		}
		return 1;
	}
The line i marked with red is the line which changes to value to the value that a player specifies in the command /pass (password), So if im doing PlayerPassword(playerid) = tmp, It is just changing value of PlayerPassword to tmp, But what i need is to change it to the password he entered, How to do this, and tell me if i went anything wrong in this script, Thnx in advance
Reply
#2

Quote:
Originally Posted by Swiftz
Посмотреть сообщение
The line i marked with red is the line which changes to value to the value that a player specifies in the command /pass (password), So if im doing PlayerPassword(playerid) = tmp, It is just changing value of PlayerPassword to tmp, But what i need is to change it to the password he entered, How to do this, and tell me if i went anything wrong in this script, Thnx in advance
pawn Код:
PlayerPassword(playerid) = tmp;
Should be correct, if you ask me. I did not work with strtok for a very long time, I'm currently using sscanf.

Doesn't it do what you want it to do?
Reply
#3

I actually didnt try it, I thought it would set it to "tmp" instead of ...
Reply
#4

I tried it but on that line i marked with red "Invalid Function call, not a valid address" Comes up, I guess im wrong in defining PlayerPassword, I defined it as new PlayerPassword[128];, How to change it, I put [128] so as it has to store password, Am i wrong please solve
Reply
#5

Quote:
Originally Posted by Swiftz
Посмотреть сообщение
I tried it but on that line i marked with red "Invalid Function call, not a valid address" Comes up, I guess im wrong in defining PlayerPassword, I defined it as new PlayerPassword[128];, How to change it, I put [128] so as it has to store password, Am i wrong please solve
Yea, sorry I did not see the (playerid) stuff. It's correct like you said now, it has to be an array, thats why it should look like:
pawn Код:
new PlayerPassword[128];
PlayerPassword=tmp;
Then his password should be stored in the variable PlayerPassword.
Reply
#6

first of all:
it would store "tmp" if you would use:
PlayerPassword = "tmp";

in your case.. try out:
format(PlayerPassword(playerid), 128, tmp);
maybe it works ... no clue though as I don't know your exact code
Reply
#7

Does no-one notice that you cannot store a value in a function? Round parentheses indicate a function.

Quote:
Originally Posted by DeathOnaStick
Посмотреть сообщение
pawn Код:
new PlayerPassword[128];
PlayerPassword=tmp;
Then his password should be stored in the variable PlayerPassword.
I'm fairly confident that'll give an 'Array sizes do not match' error. Use this to copy strings:

pawn Код:
// strcpy(dest[], const src[]);
#define strcpy(%0,%1) strcat((%0[0]=EOS,%0),%1)
Reply
#8

@Sascha it again gives me "Invalid function call" error for the same line format(PlayerPassword(playerid), 128, tmp);, Any ideas? Ok ill explain what its function is, When some player does /pass (His desired password) , the password (maybe in words and also letters) must be stored in the variable PlayerPassword, and we need to use (playerid) because each player uses unique password (maybe not if same team uses same password) , So i hope you understand, What do you now?
Reply
#9

pawn Код:
// This is a FUNCTION
PlayerPassword(playerid);

// This an an ARRAY
new PlayerPassword[MAX_PLAYERS][128];
Variables cannot under any circumstance be stored in a function. Furthermore, strings (letters and numbers) can only be stored in arrays.
Reply
#10

@Vince, When i used this new PlayerPassword[MAX_PLAYERS][128];, I got Some function should be arrayed or some error, any ideaS? but when i did PlayerPassword[MAX_PLAYERS], it compiled fine
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)