GTA Connected

Scripting => Scripting Help => Topic started by: DRACH on January 05, 2021, 07:20:15 AM

Title: skin changer
Post by: DRACH on January 05, 2021, 07:20:15 AM
hi sir can you give me a script for skin changer for my server ? without using trainer ., please help me thank you
Title: Re: skin changer
Post by: djebzer on August 08, 2021, 07:21:08 PM
Hey, sorry for the late answer but it might help others.

If you want to do that on GTA III, GTA Vice City or GTA San Andreas you can simply edit the player skin by doing the code below.

I will use a skin ID from GTA:SA that you can find  .



I will make a simple function triggered when you join the server:



Client-side (JavaScript)
[spoiler] (https://wiki.gtaconnected.com/Resources/GTASA/PedSkinshere%5B/url)
Code (js) Select

// The 'OnPlayerJoined' event is triggered once the player joined the game. (See][/spoiler]

If you want to do it for GTA:IV, it is kinda different since the model has to be requested & loaded to the engine first.

You can use native functions to do that, I will use Niko Bellic's skin ID (hash) for this example that you can find  [url=https://wiki.gtaconnected.com/Resources/GTAIV/PedSkinshere[/url].



[i]Client-side (JavaScript)[/i]
[spoiler][code=js]
// This function creates a command handler that will let you trigger this function uppon writing '/skin' in-game. (See][/spoiler]

If you want to expand the skin changer for larger uses, you can store all skins in a variable as a table and loop through it to search entries. Here is a small example:



[i]Client-side (JavaScript)[/i]
[spoiler][code=js]
const SKINS_LIST = [
   'Carl Johnson',
   'The Truth',
   'Maccer',
   'Taxi Driver',
];

function setSkin(id, name) {
   let skinId = Number(id);
   localPlayer.skin = skinId;
   message('Your skin has been changed to ' + name + '!', COLOUR_LIME);
}

addCommandHandler('skin', (cmd, params) => {
   // Find the skin by ID (number)
   let id = parseInt(params);
   if (SKINS_LIST[id]) {
      let skinName = SKINS_LIST[id];
      return setSkin(id, skinName);
   }
   
   // Find the skin by the name
   for (const skin of SKINS_LIST) {
      if (params.toLowerCase() === skin.toLowerCase()) {
         let skinId = SKINS_LIST.indexOf(skin);
         return setSkin(skinId, skin);
      }
   }
   
   message('Invalid ID/Name!', COLOUR_RED);
});
[/spoiler]

GTA Connected's Discord server[/url] if you want quick responses for further help![/b][/size]