Jump to content

Set skin when player joining - doesn't work


Dzemous

Recommended Posts

Hello guys, I'm beginners in LUA. Why this code doesn't work? 0 DB

When player joined, server giving he skin about ID 0 

C-side
function SskinC ()
triggerServerEvent ("SetSkinPlayerJoin", resourceRoot) 
end
addEventHandler  ("onClientPlayerJoin", getRootElement(), SskinC)

S-side
function UstawSkina()
setElementModel(client, 0)
end
addEvent("SetSkinPlayerJoin", true)
addEventHandler("SetSkinPlayerJoin", resourceRoot, UstawSkina)

I don't know when I must write resourceRoot, root, getRootElement, etc. and this is my problem :/ (Sorry for my english, but i can't pefrect his :/)

Link to comment
C-side
function SskinC ()
triggerServerEvent ("SetSkinPlayerJoin", root) 
end
addEventHandler  ("onClientPlayerJoin", root, SskinC)

S-side
function UstawSkina()
setElementModel(client, 0)
end
addEvent("SetSkinPlayerJoin", true)
addEventHandler("SetSkinPlayerJoin", root, UstawSkina)

even there is a event for player join you can use but for not change your scipt here it is i hope works not tested

Edited by Dimos7
Link to comment
-- client side
function changeSkinUponSpawn(team)
-- The source of this event is the player that spawned --
if isElement(source) and getElementType(source) == "player" then
triggerServerEvent("setSkinUponSpawning", source)
end
end
addEventHandler ("onClientPlayerSpawn", getRootElement(), changeSkinUponSpawn)

-- server side
function setSkinUponSpawningCall()
if source then
setElementModel(source, 0)
end
end
addEvent("setSkinUponSpawning", true)
addEventHandler("setSkinUponSpawning", resourceRoot, setSkinUponSpawningCall)


Keep in mind, you can only change a player's skin is when he's successfully spawned with the spawnPlayer event.

"onClientPlayerJoin" is called as soon as the player join the server, you can't change his model as he hasn't been spawned yet. So we make it when the player spawns, to change his skin to 0. Can be changed from server side.

Here is an example of what onClientPlayerJoin can be used for. (From MTA wiki)

function remotePlayerJoin()
outputChatBox("* " .. getPlayerName(source) .. " has joined the server")
end
addEventHandler("onClientPlayerJoin", getRootElement(), remotePlayerJoin)


 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...