2021-04-10, 02:31 PM
Hello there!
First of all, good morning, it is 11:11 here already.
I would like to clarify that I am ALL NEW on this Pawn scripting thing... I spent the whole night reading documents of variables and strings...
I still can not figure out what am I doing wrong!
Maybe someone here can help?
So, I will explain you what I am trying to do, because it is probably one of the most easiest things in Pawn scripting and if you take the time to *explain* me what I am doing wrong and how to apply it as it should, then I will be one of the happiest person alive!
I am trying to change the skin automatically only if the name of the player connected is equal to: "Luna_Beaule"
I have some custom skins added to the server, and I am trying to figure out how to change them if the X (GetPlayerName I GUESS!?!?!?) is the same as: Luna_Beaule.
I'll leave below the code I wrote *so wrong, please do not laugh, thank you*:
Code: public OnPlayerConnect(playerid)
{
SendClientMessage (playerid, -1, "Servidor oficial de pruebas.");
return 1;
}
if (GetPlayerName(playerid, name) == Luna_Beaule) return SetPlayerSkin(playerid, 20003);
return 1;
}
2021-04-10, 04:00 PM
(This post was last modified: 2021-04-10, 06:53 PM by robertocaribbean.)
(2021-04-10, 02:31 PM)romanstti Wrote: ...
There is a couple of things that I think is wrong with your code:
- I think you only need the "return 1" at the end of the public function.
- GetPlayerName it's being used wrong. You should create a variable and store in it the Skin ID of the player:
https://open.mp/docs/scripting/functions/GetPlayerName (here is how to use it).
PHP Code: new name[MAX_PLAYER_NAME 1];
GetPlayerName(playerid, name, sizeof(name));
if (name == "Luna_Beaule") { ? SetPlayerSkin(playerid, 20003); }
- OnPlayerConnect is called when a player connects to the server, so you can't change their skin because the player is not in the game yet.
You probably should use this code in OnPlayerSpawn:
PHP Code: new name[MAX_PLAYER_NAME 1];
GetPlayerName(playerid, name, sizeof(name));
if (name == "Luna_Beaule") { ? SetPlayerSkin(playerid, 20003); }
instead of:
PHP Code: if (GetPlayerName(playerid, name) == Luna_Beaule) return SetPlayerSkin(playerid, 20003);
I mean the logic it's good, but you need to change how you use GetPlayerName and where you are using SetPlayerSkin. You can't change the player's skin if the player is not spawned in the game before.
- Luna_Beaule needs to go between quotation marks: "Luna_Beaule"
Full code should be:
PHP Code: public OnPlayerConnect(playerid) { ? SendClientMessage (playerid, -1, "Servidor oficial de pruebas."); return 1; }
public OnPlayerSpawn(playerid) { ? new name[MAX_PLAYER_NAME 1];
? GetPlayerName(playerid, name, sizeof(name));
? if (name == "Luna_Beaule") { ??? SetPlayerSkin(playerid, 20003); }
return 1; }
I hope this helps to you, regards!
2021-04-10, 06:51 PM
(This post was last modified: 2021-04-10, 06:55 PM by Snow.)
If you're using a login/registration system, Save the player skin in a variable and load it when player logs in, This will set his skin to the saved skin when he enters the password.
(2021-04-10, 04:00 PM)robertocaribbean Wrote: (2021-04-10, 02:31 PM)romanstti Wrote: ...
There is a couple of things that I think is wrong with your code:
- I think you only need the "return 1" at the end of the public function.
- GetPlayerName it's being used wrong. You should create a variable and store in it the Skin ID of the player:
https://open.mp/docs/scripting/functions/GetPlayerName (here is how to use it).
PHP Code: new name[MAX_PLAYER_NAME 1];
GetPlayerName(playerid, name, sizeof(name));
if (name == "Luna_Beaule") {
? SetPlayerSkin(playerid, 20003);
}
- OnPlayerConnect is called when a player connects to the server, so you can't change their skin because the player is not in the game yet.
You probably should use this code in OnPlayerSpawn:
PHP Code: new name[MAX_PLAYER_NAME 1];
GetPlayerName(playerid, name, sizeof(name));
if (name == "Luna_Beaule") {
? SetPlayerSkin(playerid, 20003);
}
instead of:
PHP Code: if (GetPlayerName(playerid, name) == Luna_Beaule) return SetPlayerSkin(playerid, 20003);
I mean the logic it's good, but you need to change how you use GetPlayerName and where you are using SetPlayerSkin. You can't change the player's skin if the player is not spawned in the game before.
- Luna_Beaule needs to go between quotation marks: "Luna_Beaule"
Full code should be:
PHP Code: public OnPlayerConnect(playerid) {
? SendClientMessage (playerid, -1, "Servidor oficial de pruebas.");
? return 1;
}
public OnPlayerSpawn(playerid) {
? new name[MAX_PLAYER_NAME 1];
? GetPlayerName(playerid, name, sizeof(name));
? if (name == "Luna_Beaule") {
??? SetPlayerSkin(playerid, 20003);
? }
? return 1;
}
I hope this helps to you, regards!
That's completely wrong. You can't directly compare strings like that. You need to use a built-in native/function that is called "strcmp". String-Compare.? https://open.mp/docs/scripting/functions/strcmp?. You firstly store the player name in a variable using "GetPlayerName". It takes two arguments. The first one is the playerid whom you want to get his name. The second argument is where you want to store the player name. (Of course it'll be a variable). Third argument isn't necessary and it's the size of the variable. Then you can check names and set the player skin.
|