Jump to content

[help] onPlayerRegister


ice_brasil

Recommended Posts

 

I want my panel to selession skin, only open once per account, or just when registering, I already tried to use several codes, I could not, can do that part for me?

Client:



femaleSkins = {9, 31, 38, 190, 218}

maleSkins = {0, 1, 21, 29, 19}

--------**--------
-------//\\-------
------//  \\------
-----//	   \\-----
----//		\\----
---//		 \\---
--//		  \\--
--\\ Settings //--
local defaultSex = "male" -- Set the default sex (Can be "male" or "female")
-- Please note that any of the timers below are in milliseconds (ms)
local skinCamTimer = 100 -- Timer to switch the camera to the selected skin (Change to a higher value if the camera doesn't switch to the Ped Selection Screen)
local playerCamTimer = 100 -- Timer to switch the camera back to the player (Change to a higher value if the camera doesn't switch back to the player)
local setSkinTimer = 50 -- Timer to override any skin change done by other scripts (Change to a higher value if the player's skin doesn't change)
-- Scroll settings
local autoScrollStart = 200 -- Set the time it takes in ms to enable auto scroll when holding down your arrow keys (cannot be lower than 50)
local autoScrollSpeed = 80 -- Set the time it takes in ms to switch between skins when holding down your arrow keys (cannot be lower than 50)
--//		  \\--
--\\		  //--
---\\        //---
----\\      //----
-----\\    //-----
------\\  //------
-------\\//-------
--------**--------

local sWidth,sHeight = guiGetScreenSize()
local origWidth,origHeight = 1280,960
local isScreenVisible = false
local skinRequested = false
function text(text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI)
	dxDrawText(text, x/origWidth*sWidth+1.5, y/origHeight*sHeight+1.5, w/origWidth*sWidth+1.5, h/origHeight*sHeight+1.5, tocolor(0,0,0,255), scale/origWidth*sWidth, font, alignX, alignY, clip, wordBreak, postGUI)
	dxDrawText(text, x/origWidth*sWidth, y/origHeight*sHeight, w/origWidth*sWidth, h/origHeight*sHeight, color, scale/origWidth*sWidth, font, alignX, alignY, clip, wordBreak, postGUI)
end
function image(x, y, w, h, image, rotation, rotationCenterOffsetX, rotationCenterOffsetY, color, postGUI)
	dxDrawImage(x/origWidth*sWidth, y/origHeight*sHeight, w/origWidth*sWidth, h/origHeight*sHeight, image, rotation, rotationCenterOffsetX, rotationCenterOffsetY, color, postGUI)
end
function mainScreen()
	dxDrawImage(0,0,sWidth,sHeight,"img/bg.png",0,0,0,tocolor(255,255,255,255),true)
	text("Skin: "..selectedSkin.."/"..totalSkins, 290, 198, 440, 249, tocolor(255, 255, 255, 255), 2.50, "default", "left", "top", false, false, true, false, false)	
	text("Pressione [enter] para escolher sua skin.", 322, 837, 1042, 875, tocolor(255, 255, 255, 255), 2.00, "default", "center", "center", false, false, true, false, false)
	image(473, 419, 96, 140, "img/arrow.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
	image(767.75, 419, 96, 140, "img/arrow.png", 180, 0, 0, tocolor(255, 255, 255, 255), true)
	image(72, 207, 130, 131, "img/male.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
	image(55, 380, 130, 131, "img/female.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
end
function prevArrowBlink()
	image(473, 419, 96, 140, "img/arrow-blink.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
end
function nextArrowBlink()
	image(767.75, 419, 96, 140, "img/arrow-blink.png", 180, 0, 0, tocolor(255, 255, 255, 255), true)
end
function maleActivated()
	image(54, 187, 169, 174, "img/male-active.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
end
function femaleActivated()
	image(45, 363, 155, 170, "img/female-active.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
end

local prevButtonClickable = guiCreateStaticImage(0.36, 0.44, 0.08, 0.15, "img/transparent.png", true)
local nextButtonClickable = guiCreateStaticImage(0.62, 0.44, 0.07, 0.15, "img/transparent.png", true)
local maleButtonClickable = guiCreateStaticImage(0.06, 0.21, 0.10, 0.14, "img/transparent.png", true)
local femaleButtonClickable = guiCreateStaticImage(0.06, 0.40, 0.07, 0.14, "img/transparent.png", true)
function showClickables(isScreenVisible)
	guiSetVisible(prevButtonClickable,isScreenVisible)
	guiSetVisible(nextButtonClickable,isScreenVisible)
	guiSetVisible(maleButtonClickable,isScreenVisible)
	guiSetVisible(femaleButtonClickable,isScreenVisible)
end
showClickables(isScreenVisible)

function toggleScreen()
	if isScreenVisible then
		closeScreen()
	else
		addEventHandler("onClientRender",root,mainScreen)
		if defaultSex == "male" then
			addEventHandler("onClientRender",root,maleActivated)
		elseif defaultSex == "female" then
			addEventHandler("onClientRender",root,femaleActivated)
		end
		isScreenVisible = true
		showClickables(isScreenVisible)
		showCursor(true)
		setTimer(function()showChat(false)end,200,1)
		setPlayerHudComponentVisible("all",false)
		bindKey("enter","down",changePlayerSkin)
	end
end

function closeScreen()
	skinRequested = false
	firstTime = false
	setTimer(function()setCameraTarget(localPlayer)end,playerCamTimer,1)
	triggerServerEvent("setElemDimen",localPlayer,localPlayer,0)
	removeEventHandler("onClientRender",root,mainScreen)
	removeEventHandler("onClientRender",root,femaleActivated)
	removeEventHandler("onClientRender",root,maleActivated)
	isScreenVisible = false
	showClickables(isScreenVisible)
	showCursor(false)
	setTimer(function()showChat(true)end,200,1)
	setPlayerHudComponentVisible("all",true)
	unbindKey("enter","down",changePlayerSkin)
end

function onSpawn(firstTime)
	if skinRequested == true or firstTime == true then
		toggleScreen()
		triggerServerEvent("setElemDimen",localPlayer,localPlayer,2)
		triggerServerEvent("setElemFrozen",localPlayer,localPlayer,true)
		setTimer(function()setCameraMatrix(955.8608, -1265.3856, 21.5138, 956.1688, -1265.3699, 21.5041)end,skinCamTimer,1)
	elseif firstTime == true then
		addEventHandler("onClientPlayerSpawn",localPlayer,onSpawn)
	end
	firstTime = false
end
addEvent("onRegister",true)
addEventHandler("onRegister",root,onSpawn)


function changePlayerSkin()
	toggleScreen()
	setPlayerTheirSkin()
	skinChosen = true
	triggerServerEvent("setElemFrozen",localPlayer,localPlayer,false)
	removeEventHandler("onClientPlayerSpawn",localPlayer,onSpawn)
end

function setChosenSkinOnSpawn()
	if skinChosen == true then
		setTimer(function()setPlayerTheirSkin()end,50,1)
	end
end
addEventHandler("onClientPlayerSpawn",localPlayer,setChosenSkinOnSpawn)

local ped = createPed(0,960.05999755859, -1265.2800292969, 21.440000534058,90.0041198)

setElementDimension(ped,2)
local tune = playSFX3D("radio","Ambience",11,960.05999755859, -1265.2800292969, 21.440000534058,true)
setSoundVolume(tune,1)
setSoundMaxDistance(tune,50)
setElementDimension(tune,2)

function getSelectedSkinID()
	local ID = skinTable[selectedSkin]
	return ID
end

function setMenuPedSkin()
	local ID = getSelectedSkinID()
	setElementModel(ped,ID)
end

function changeSex(sex)
	if source == maleButtonClickable or sex == "male" then
		defaultSex = "male"
		setPedAnimation(ped,"DANCING","dnce_M_c",_,_,false,false,_)
		skinTable = maleSkins
		totalSkins = #skinTable
		selectedSkin = 1
		setMenuPedSkin()
		if isScreenVisible then
			removeEventHandler("onClientRender",root,femaleActivated)
			addEventHandler("onClientRender",root,maleActivated)
		end
	elseif source == femaleButtonClickable or sex == "female" then
		defaultSex = "female"
		setPedAnimation(ped,"STRIP","STR_Loop_A",_,_,false,false,_)
		skinTable = femaleSkins
		totalSkins = #skinTable
		selectedSkin = 1
		setMenuPedSkin()
		if isScreenVisible then
			removeEventHandler("onClientRender",root,maleActivated)
			addEventHandler("onClientRender",root,femaleActivated)
		end
	end
end
addEventHandler("onClientGUIClick",resourceRoot,changeSex)
changeSex(defaultSex)

function selectNextSkin()
	if selectedSkin == totalSkins then
		selectedSkin = 1
	else
		selectedSkin = selectedSkin+1
	end
end

function selectPrevSkin()
	if selectedSkin == 1 then
		selectedSkin = totalSkins
	else
		selectedSkin = selectedSkin-1
	end
end

function setPlayerTheirSkin()
	local ID = getSelectedSkinID()
	setTimer(function()triggerServerEvent("changePlayerSkin",localPlayer,ID,selectedSkin)end,setSkinTimer,1)
end

-- Button prev <
local renderprev = true
function prevPedButton()
	if isScreenVisible then
		playSound("scroll.mp3")
		if renderprev == true then addEventHandler("onClientRender",root,prevArrowBlink) renderprev = false end
		setTimer(function()removeEventHandler("onClientRender",root,prevArrowBlink) renderprev = true end,50,1)
		selectPrevSkin()
		setMenuPedSkin()
	end
end
addEventHandler("onClientGUIClick",prevButtonClickable,prevPedButton,false)
bindKey("arrow_l","down",prevPedButton)

-- Button next >
local rendernext = true
function nextPedButton()
	if isScreenVisible then
		playSound("scroll.mp3")
		if rendernext == true then addEventHandler("onClientRender",root,nextArrowBlink) rendernext = false end
		setTimer(function()removeEventHandler("onClientRender",root,nextArrowBlink) rendernext = true end,50,1)
		selectNextSkin()
		setMenuPedSkin()
	end
end
addEventHandler("onClientGUIClick",nextButtonClickable,nextPedButton,false)
bindKey("arrow_r","down",nextPedButton)

-- Scroll functions
function nextPed_scroll()
	timernext = setTimer(
		function()
			timernext2 = setTimer(
				function()
					nextPedButton()
				end
			,autoScrollSpeed,0)
		end
	,autoScrollStart,1)
end
bindKey("arrow_r","down",nextPed_scroll)

function prevPed_scroll()
	timerprev = setTimer(
		function()
			timerprev2 = setTimer(
				function()
					prevPedButton()
				end
			,autoScrollSpeed,0)
		end
	,autoScrollStart,1)
end
bindKey("arrow_l","down",prevPed_scroll)

function killAutoScroll_next()
	if isTimer(timerprev) then
		killTimer(timerprev)
	elseif isTimer(timerprev2) then
		killTimer(timerprev2)
	end
end
bindKey("arrow_l","up",killAutoScroll_next)

function killAutoScroll_prev()
	if isTimer(timernext) then
		killTimer(timernext)
	elseif isTimer(timernext2) then
		killTimer(timernext2)
	end
end
bindKey("arrow_r","up",killAutoScroll_prev)

 

ServeR::

function changePlayerSkin(ID,selectedSkin)
	setElementModel(source,ID)
end
addEvent("changePlayerSkin",true)
addEventHandler("changePlayerSkin",root,changePlayerSkin)

function setElemDimen(source,ID)
	setElementDimension(source,ID)
end
addEvent("setElemDimen",true)
addEventHandler("setElemDimen",root,setElemDimen)

function setElemFrozen(source,bool)
	setElementFrozen(source,bool)
end
addEvent("setElemFrozen",true)
addEventHandler("setElemFrozen",root,setElemFrozen)

firstTime = true
function onSpawnFirstTime()
	triggerClientEvent(source,"onRegister",source,firstTime)
end
addEventHandler("onPlayerLogin",root,onSpawnFirstTime)

 

Link to comment

Maybe you can set account data the first time the player logs in and use that to check whether they have been in the server or not.

  1. on player login getAccountData "regularPlayer"
  2. if false then show the skin selection screen
  3. set the account data for regularPlayer to true
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...