• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[HELP] Changing the skin when OnPlayerConnect
#4
(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(playeridnamesizeof(name));



if (
name == "Luna_Beaule") {

SetPlayerSkin(playerid20003);





- 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(playeridnamesizeof(name));



if (
name == "Luna_Beaule") {

SetPlayerSkin(playerid20003);





instead of:



PHP Code:
if (GetPlayerName(playeridname) == Luna_Beaule) return SetPlayerSkin(playerid20003); 



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(playeridnamesizeof(name));



? if (
name == "Luna_Beaule") {

??? 
SetPlayerSkin(playerid20003);

? }



? 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.
  Reply


Messages In This Thread
RE: [HELP] Changing the skin when OnPlayerConnect - by ImOver - 2021-04-15, 12:45 PM

Forum Jump: