PDA

View Full Version : User name to real name


Elietje28
23/06/2013, 04:43 PM
Hi everybody!

I'm a noob in samp scripting, but i'm trying to learn it. I can send a client message to all if a player has been connected and I can also use a string to get the user name of the player in that message.

The new thing I'm trying no is to change that user name in their real name. This is the code I've got, and I'm sure it's wrong (because it doesn't work and the compiler gives a fault (warning 211: possibly unintended assignment) ;) ) and I know i'm doing something wrong with the 'return-thing'.

public OnPlayerConnect(playerid)
{
new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
GetPlayerName(playerid, name, sizeof(name));

if(name="Aegidje")
{
name="Aegide";
return 1;
}

if(name="Elietje28")
{
name="Elias";
return 1;
}

if(name="vandenboerseppe")
{
name="Seppe";
return 1;
}

if(name="SmacksCharlie")
{
name="Karel";
return 1;
}

if(name="stabar")
{
name="Steven";
return 1;
}

if(name="Supertoby28")
{
name="Aron";
return 1;
}


format(string, sizeof(string), "%s is ingelogd. (=has been connected)", name);
SendClientMessageToAll(COLOR_GREEN, string);

So what I think what's happening is: there is made a string, called 'name' and the user name is stored in the string. Then, it checks if the string is one of the user names of my friends (Aegidje, Elietje28, vandenboerseppe,...). If that's right, the string changes to their real names. The next part is sending the message with the string.

Each tutorial I watch or read, I don't understand the return-part. Is their someone who can explain me what I did wrong and what those returns exactly are?

Thanks!

Elietje28

NoahF
23/06/2013, 04:59 PM
Wrong section.

Elietje28
23/06/2013, 05:00 PM
Thanks, but what do I have to do then? Do I have to make another callback?

Swyft
23/06/2013, 05:32 PM
Wrong section and


if(name="Aegidje")
{
name="Aegide";
}

else if(name="Elietje28")
{
name="Elias";
}

else if(name="vandenboerseppe")
{
name="Seppe";
}

else if(name="SmacksCharlie")
{
name="Karel";
}

else if(name="stabar")
{
name="Steven";
}

else if(name="Supertoby28")
{
name="Aron";
}

Elietje28
23/06/2013, 05:37 PM
Okay, but what do you mean with wrong section?

Swyft
23/06/2013, 05:58 PM
This should be in scripting help, not bug reports.

Basssiiie
23/06/2013, 06:44 PM
@Swyft: Lol, you're an even bigger noob with Pawn than the topic starter.

@Eliet: You're correct about the names in the string. To compare strings, you need to use strcmp (http://wiki.sa-mp.com/wiki/Strcmp) though. ;) Also, the "return" function stops the whole function. Don't use it too early. Only use it at the end of your function, or if you want to stop the function earlier on.

[MM]IKKE
23/06/2013, 08:11 PM
To compare strings, like ^Basssiiie said, you have to use strcmp (http://wiki.sa-mp.com/wiki/Strcmp)

If you use a comparison of values, you should use '==' instead of "=". That's why the warning says "possibly unintended assignment". One '=' means you apply the value after the equality to the variable in front of it. The if's would set the variable name to what's next to it, instead of comparing it.

Swyft
23/06/2013, 08:24 PM
@Swyft: Lol, you're an even bigger noob with Pawn than the topic starter.

@Eliet: You're correct about the names in the string. To compare strings, you need to use strcmp (http://wiki.sa-mp.com/wiki/Strcmp) though. ;) Also, the "return" function stops the whole function. Don't use it too early. Only use it at the end of your function, or if you want to stop the function earlier on.

Just trying to help, and I don't believe that statement is true, but whatever helps you sleep at night.

xxSwissxx
24/06/2013, 05:58 AM
Just trying to help, and I don't believe that statement is true, but whatever helps you sleep at night.

Fight the power.

Elietje28
24/06/2013, 01:41 PM
Okay, thanks everybody (and also Swyft, he just wants to help ;) )

So this is the code I have now, but then, the string only changes to 'Aegide', even if I log in with 'Elietje28', 'vandenboerseppe',...

public OnPlayerConnect(playerid)
{

new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
GetPlayerName(playerid, name, sizeof(name));

if(strcmp(name,"Aegidje",true))
{
name="Aegide";
}

else if(strcmp(name,"Elietje28",true))
{
name="Elias";
}

else if(strcmp(name,"vandenboerseppe",true))
{
name="Seppe";
}

else if(strcmp(name,"SmacksCharlie",true))
{
name="Karel";
}

else if(strcmp(name,"stabar",true))
{
name="Steven";
}

else if(strcmp(name,"Supertoby28",true))
{
name="Aron";
}

format(string, sizeof(string), "%s is ingelogd.", name);
SendClientMessageToAll(COLOR_GREEN, string);

return 1;
}

[MG]Dimi
24/06/2013, 01:44 PM
if(strcmp([string1],[string2])) This will be processes when they aren't same. Strcmp returns 0 if strings are same so use
if(!strcmp([string1],[string2]))

Read note here (http://wiki.sa-mp.com/wiki/Strcmp)

Elietje28
24/06/2013, 04:05 PM
Okay, thanks to everybody! This is the code I have now, but when I log in as 'Elietje28','vandenboerseppe',... the client message says:'Aegide is ingelogd'; the string has been changed into the first name...

public OnPlayerConnect(playerid)
{
new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
GetPlayerName(playerid, name, sizeof(name));

if(strcmp(name,"Aegidje",true))
{
name="Aegide";
}

else if(strcmp(name,"Elietje28",true))
{
name="Elias";
}

else if(strcmp(name,"vandenboerseppe",true))
{
name="Seppe";
}

else if(strcmp(name,"SmacksCharlie",true))
{
name="Karel";
}

else if(strcmp(name,"stabar",true))
{
name="Steven";
}

else if(strcmp(name,"Supertoby28",true))
{
name="Aron";
}

format(string, sizeof(string), "%s is ingelogd.", name);
SendClientMessageToAll(COLOR_GREEN, string);

return 1;
}

Elietje28

Elietje28
24/06/2013, 04:08 PM
Okay, sorry, I didn't see my message was sent, because it's on the 2nd page... ignore my previous message :)

Elietje28
24/06/2013, 04:14 PM
Okay, thanks to everybody! It works. The admins may close this topic