Jump to content

[HELP] Login and Skin select rendering


Recommended Posts

Hello,

my problem is:

When a player is in the login menu he can see the skin select menu.

How I can fix that ?

It looks like that:

mta_screen_2016_05_08_23_52_42.png

This is the client sided skin menu script thats not all but thats basiclly that what appears under the loginpanel.

So how I can fix that? I want that the player can only select a skin when he is logged in! (But checking if he is logged in is server sided)

function createSelector () 
     ped = createPed( homeless[index], unpack( pedPos )); 
     setElementDimension( ped, 1 ); 
     showCursor( true ); 
     btn_next = guiCreateButton ( (sx+length)/2+15, sy-100, 60, 35, ">>>", false); 
     btn_prev = guiCreateButton ( (sx-length)/2-75, sy-100, 60, 35, "<<<", false); 
     btn_enter = guiCreateButton ( sx/2-60, sy-60, 120, 35, "Выбрать", false); 
     guiSetAlpha ( btn_next, 0 ); 
     guiSetAlpha ( btn_prev, 0 ); 
     guiSetAlpha ( btn_enter, 0 ); 
     addEventHandler ( "onClientRender", root, nameSkin ) 
     addEventHandler ( "onClientRender", root, rotSkin ) 
end 
addEvent( "createSelector", true ) 
addEventHandler( "createSelector", root, createSelector ) 

"Выберите персонажа" is the skin name ...

Link to comment
use getPlayerAccount and isGuestAccount then show these.

Like that ? :

function createSelector () 
local account = getPlayerAccount(thePlayer) 
if account then 
     ped = createPed( homeless[index], unpack( pedPos )); 
     setElementDimension( ped, 1 ); 
     showCursor( true ); 
     btn_next = guiCreateButton ( (sx+length)/2+15, sy-100, 60, 35, ">>>", false); 
     btn_prev = guiCreateButton ( (sx-length)/2-75, sy-100, 60, 35, "<<<", false); 
     btn_enter = guiCreateButton ( sx/2-60, sy-60, 120, 35, "Выбрать", false); 
     guiSetAlpha ( btn_next, 0 ); 
     guiSetAlpha ( btn_prev, 0 ); 
     guiSetAlpha ( btn_enter, 0 ); 
     addEventHandler ( "onClientRender", root, nameSkin ) 
     addEventHandler ( "onClientRender", root, rotSkin ) 
end 
addEvent( "createSelector", true ) 
addEventHandler( "createSelector", root, createSelector ) 
end 

I tried that but the hole gamemode didnt work then.

Link to comment
It's a server sided function.

Before triggering the event. also use isGuestAccount.

See the wiki for eg.

Like that ?

addEvent( "onStart", true )  
addEventHandler( "onStart", root, function ( ) 
      local sourceAccount = getPlayerAccount ( playerSource ) 
      if sourceAccount then 
            triggerClientEvent( source, "createSelector", source ); 
            elseif 
             isGuestAccount ( sourceAccount ) then 
      end 
end ) 

its isnt working .. same problem still appears on loginpanel

Link to comment

Use triggerServerEvent check if the player is logged in then send the information to the client side.

Example:

Client side:

triggerServerEvent("isClientReady",resourceRoot) 

Server side:

function isReady() 
    if isPlayerLoggedIn(client) then  
        triggerClientEvent(client,"eventName",client) 
    end  
end  
addEvent("isClientReady",true) 
addEventHandler("isClientReady",resourceRoot,isReady) 
  
-- Check if the player is logged In  
function isPlayerLoggedIn(player) 
    if (not isElement(player) or getElementType(player) ~= "player") then return false end 
    local account = getPlayerAccount(player) 
    if (isGuestAccount(account)) then return false end 
    return true 
end 

Link to comment
Use triggerServerEvent check if the player is logged in then send the information to the client side.

Example:

Client side:

triggerServerEvent("isClientReady",resourceRoot) 

Server side:

function isReady() 
    if isPlayerLoggedIn(client) then  
        triggerClientEvent(client,"eventName",client) 
    end  
end  
addEvent("isClientReady",true) 
addEventHandler("isClientReady",resourceRoot,isReady) 
  
-- Check if the player is logged In  
function isPlayerLoggedIn(player) 
    if (not isElement(player) or getElementType(player) ~= "player") then return false end 
    local account = getPlayerAccount(player) 
    if (isGuestAccount(account)) then return false end 
    return true 
end 

Can you please take a look at this script and change it for me ? Because I tried it like 1000 times and its not working for me.

Sry for asking you if you can change it ))

Skinpanel client sided script

sx, sy = guiGetScreenSize(); 
  
---id скинов бомжей 
local homeless = { 
[1] = 77, 
[2] = 78, 
[3] = 79, 
[4] = 95, 
[5] = 134, 
[6] = 135, 
[7] = 137, 
[8] = 200, 
[9] = 212, 
[10] = 213, 
[11] = 230 
} 
---Названия скинов 
local skins = { ---лучше использовать латиницу 
[1] = "Выберите персонажа", 
[2] = "Выберите персонажа", 
[3] = "Выберите персонажа", 
[4] = "Выберите персонажа", 
[5] = "Выберите персонажа", 
[6] = "Выберите персонажа", 
[7] = "Выберите персонажа", 
[8] = "Выберите персонажа", 
[9] = "Выберите персонажа", 
[10] = "Выберите персонажа", 
[11] = "Выберите персонажа" 
} 
  
local rN, gN, bN = 79, 19, 232;---цвет имён скинов 
local rBn, gBn, bBn = 79, 19, 232;---цвет кнопки следующий 
local rBp, gBp, bBp = 79, 19, 232;---цвет кнопки предыдущий 
local rBe, gBe, bBe = 79, 19, 232;---цвет кнопки выбрать 
---Цвета по умолчанию (должны быть такие же, как выше) 
local rBn1, gBn1, bBn1 = 79, 19, 232;---цвет имён скинов 
local rBp1, gBp1, bBp1 = 79, 19, 232; 
local rBe1, gBe1, bBe1 = 79, 19, 232; 
---Цвета кнопок при наведении 
local rBn2, gBn2, bBn2 = 255, 255, 255; 
local rBp2, gBp2, bBp2 = 255, 255, 255; 
local rBe2, gBe2, bBe2 = 255, 255, 255; 
---Цвета кнопок при нажатии 
local rBn3, gBn3, bBn3 = 255, 255, 255; 
local rBp3, gBp3, bBp3 = 255, 255, 255; 
local rBe3, gBe3, bBe3 = 255, 255, 255; 
---Дальше лучше не редактировать 
  
local index = 1; 
local maxIndex = #homeless; 
local font = "arial"; 
local size = 2; 
local length = dxGetTextWidth( skins[index], size, font ); 
  
local pedPos = {1571.37, 2159.07, 10.8, -45}; 
local camPos = {1574.87, 2162.29, 12, 1503.79, 2094.29, -6.29}; 
  
local ped 
local btn_next 
local btn_prev 
local btn_enter 
  
function createSelector (username, password) 
     ped = createPed( homeless[index], unpack( pedPos )); 
     setElementDimension( ped, 1 ); 
     showCursor( true ); 
     btn_next = guiCreateButton ( (sx+length)/2+15, sy-100, 60, 35, ">>>", false); 
     btn_prev = guiCreateButton ( (sx-length)/2-75, sy-100, 60, 35, "<<<", false); 
     btn_enter = guiCreateButton ( sx/2-60, sy-60, 120, 35, "Выбрать", false); 
     guiSetAlpha ( btn_next, 0 ); 
     guiSetAlpha ( btn_prev, 0 ); 
     guiSetAlpha ( btn_enter, 0 ); 
     addEventHandler ( "onClientRender", root, nameSkin ) 
     addEventHandler ( "onClientRender", root, rotSkin ) 
end 
addEvent( "createSelector", true ) 
addEventHandler( "createSelector", root, createSelector ) 
  
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()), 
function() 
    triggerServerEvent( "onStart", localPlayer ); 
end ) 
  
function updateBtns( ) 
     destroyElement( btn_next ); 
     destroyElement( btn_prev ); 
     btn_next = guiCreateButton ( (sx+length)/2+15, sy-100, 60, 35, ">>>", false); 
     btn_prev = guiCreateButton ( (sx-length)/2-75, sy-100, 60, 35, "<<<", false); 
     guiSetAlpha ( btn_next, 0 ); 
     guiSetAlpha ( btn_prev, 0 ); 
end 
  
function nameSkin () 
        setCameraMatrix( unpack( camPos ) ); 
    dxDrawText ( skins[index], (sx-length)/2, sy-95, length, sy, tocolor ( 0, 0, 0, 255 ), size, font ) 
    dxDrawText ( skins[index], (sx-length)/2, sy-96, length, sy, tocolor ( rN, gN, bN, 255 ), size, font ) 
        ---Buttons--- 
    dxDrawText ( ">>>", (sx+length)/2+28, sy-94, sx, sy, tocolor ( 0, 0, 0, 255 ), 2.1, font ) 
    dxDrawText ( ">>>", (sx+length)/2+28, sy-95, sx, sy, tocolor ( rBn, gBn, bBn, 255 ), 2.1, font ) 
    dxDrawText ( "<<<", (sx-length)/2-67, sy-94, sx, sy, tocolor ( 0, 0, 0, 255 ), 2.1, font ) 
    dxDrawText ( "<<<", (sx-length)/2-67, sy-95, sx, sy, tocolor ( rBp, gBp, bBp, 255 ), 2.1, font ) 
        ---dxDrawRectangle ( sx/2-60, sy-60, 120, 35, tocolor ( 0, 0, 0, 150 ) ) 
    dxDrawText ( "Выбрать", sx/2-32, sy-53, sx, sy, tocolor ( 0, 0, 0, 255 ), 1.3, font ) 
    dxDrawText ( "Выбрать", sx/2-32, sy-54, sx, sy, tocolor ( rBe, gBe, bBe, 255 ), 1.3, font ) 
end 
  
function onGuiClick ( ) 
     if (source == btn_next) then 
          b_next ( ); 
          updateBtns ( ); 
     end 
     if (source == btn_prev) then 
          b_prev ( ); 
          updateBtns ( ); 
     end 
     if (source == btn_enter) then 
          triggerServerEvent( "setSkinHomeless", localPlayer, homeless[index] ); 
          setCameraTarget(localPlayer); 
          outputChatBox( "#FF8800[skins] #00FF00Скин успешно выбран", 255, 255, 255, true ); 
          removeEventHandler ( "onClientRender", root, nameSkin ) 
          removeEventHandler ( "onClientRender", root, rotSkin ) 
          if isElement( ped ) then destroyElement( ped ) end 
          rBe, gBe, bBe = rBn3, gBn3, bBn3; 
          destroyElement( btn_next ); 
          destroyElement( btn_prev ); 
          destroyElement( btn_enter ); 
          showCursor( false ); 
     end 
end 
addEventHandler ( "onClientGUIClick", root, onGuiClick ) 
  
function closeSelector( ) 
          triggerServerEvent( "closeSelector", localPlayer ); 
          setCameraTarget(localPlayer); 
          removeEventHandler ( "onClientRender", root, nameSkin ) 
          removeEventHandler ( "onClientRender", root, rotSkin ) 
          if isElement( ped ) then destroyElement( ped ) end 
          rBe, gBe, bBe = rBn3, gBn3, bBn3; 
          destroyElement( btn_next ); 
          destroyElement( btn_prev ); 
          destroyElement( btn_enter ); 
          showCursor( false ); 
end 
addEvent ( "closeSelector", true ) 
addEventHandler ( "closeSelector", localPlayer, closeSelector ) 
  
addEventHandler ("onClientMouseEnter", root, function ( ) 
     if (source == btn_next) then 
         rBn, gBn, bBn = rBn2, gBn2, bBn2;   
     end 
     if (source == btn_prev) then 
         rBp, gBp, bBp = rBp2, gBp2, bBp2;  
     end 
     if (source == btn_enter) then 
         rBe, gBe, bBe = rBe2, gBe2, bBe2;  
     end 
end ) 
  
addEventHandler ("onClientMouseLeave", root, function ( ) 
     if (source == btn_next) then 
         rBn, gBn, bBn = rBn1, gBn1, bBn1;   
     end 
     if (source == btn_prev) then 
         rBp, gBp, bBp = rBp1, gBp1, bBp1;  
     end 
     if (source == btn_enter) then 
         rBe, gBe, bBe = rBe1, gBe1, bBe1;  
     end 
end ) 
  
function b_next( ) 
     if ( index == maxIndex ) then 
          index = 1; 
      else 
          index = index + 1; 
     end 
     rBn, gBn, bBn = rBn3, gBn3, bBn3; 
     setTimer( function ( )  
          rBn, gBn, bBn = rBn2, gBn2, bBn2; 
     end, 100, 1 ) 
     setElementModel( ped, homeless[index] ); 
     length = dxGetTextWidth( skins[index], size, font ); 
end 
  
function b_prev( ) 
     if ( index == 1 ) then 
          index = maxIndex; 
      else 
          index = index - 1; 
     end 
     rBp, gBp, bBp = rBp3, gBp3, bBp3; 
     setTimer( function ( )  
          rBp, gBp, bBp = rBp2, gBp2, bBp2; 
     end, 100, 1 ) 
     setElementModel( ped, homeless[index] ); 
     length = dxGetTextWidth( skins[index], size, font ); 
end  
  
local rot = -45; 
  
function rotSkin () 
     if ( rot == 360 ) then rot = 0 end 
     rot = rot + 1; 
     setElementRotation( ped, 0, 0, rot ) 
end 

Here is the server sided script

---в скобках id, после равно цена 
local prices = { 
[1] = 500, 
[20] = 800, 
[7] = 1000, 
[41] = 1200, 
[22] = 1500, 
[93] = 1800 
  
  
} 
  
function buySkin( id ) 
  local c_skin = getElementData( source, "skin" ); 
  if c_skin and ( c_skin == id ) then 
       outputChatBox ( "#ff8800[Магазин] #e32636У вас уже имеется этот скин", source, 255,255,255, true); 
       return; 
   else 
       if ( getPlayerMoney( source ) >= tonumber(prices[id]) ) then 
            triggerClientEvent( source, "closeShop", source ); 
            setElementModel( source, id ); 
            setElementData( source, "skin", id ); 
            takePlayerMoney ( source, tonumber( prices[id] ) ); 
            outputChatBox ( "#ff8800[Магазин] #00ff00Вы успешно приобрели скин", source, 255,255,255, true) 
            triggerClientEvent(source, "onPlayerJoinBind", source); 
            setElementDimension ( source, 0 ); 
            setElementFrozen ( source, false ); 
            setElementInterior( source, 0 ); 
         else 
            outputChatBox ( "#ff8800[Магазин] #e32636У вас недостаточно денег для приобретения этого скина", source, 255,255,255, true) 
        end 
   end 
end 
addEvent( "buySkin", true ) 
addEventHandler( "buySkin", getRootElement(), buySkin ) 
  
addEventHandler ( "onPlayerSpawn", root, function ( ) 
      local skin = getElementData( source, "skin" ); 
      if not skin and ( getElementDimension ( source ) == 0 ) then 
            setElementFrozen ( source, true ); 
            setElementDimension ( source, 1 ); 
      end 
end ) 
  
addEvent( "onStart", true )  
addEventHandler( "onStart", root, function ( ) 
      local skin = getElementData( source, "skin" ); 
      if not skin then 
            triggerClientEvent( source, "createSelector", source ); 
      end 
end ) 
  
function onPlayerLogin() 
      local playerAccount = getPlayerAccount( source ); 
      if ( playerAccount ) then 
            local playerSkin = getAccountData( playerAccount, "skin" ); 
            if ( playerSkin ) then 
                  setElementData( source, "skin", playerSkin ); 
                  setElementModel( source, playerSkin ); 
                  triggerClientEvent( source, "closeSelector", source ); 
            end 
      end 
end 
addEventHandler("onPlayerLogin", root, onPlayerLogin) 
  
function onPlayerQuit() 
      local playerAccount = getPlayerAccount( source ); 
      if ( playerAccount ) then 
            local playerSkin = getElementData( source, "skin" ); 
            if ( playerSkin ) then 
                 setAccountData( playerAccount, "skin", playerSkin); 
            end 
      end 
end 
addEventHandler("onPlayerQuit", root, onPlayerQuit) 
  
addEvent( "setSkinHomeless", true )  
addEventHandler( "setSkinHomeless", root, function ( id ) 
      setElementModel ( source, id ); 
      setElementDimension ( source, 0 ); 
      setElementFrozen ( source, false ); 
end ) 
  
addEvent( "closeSelector", true )  
addEventHandler( "closeSelector", root, function ( ) 
      setElementDimension ( source, 0 ); 
      setElementFrozen ( source, false ); 
end ) 
  
addEvent( "shopHit", true )  
addEventHandler( "shopHit", root, function ( ) 
     setElementFrozen ( source, true ); 
     setElementDimension ( source, 1 ); 
     setElementInterior( source, 18 ); 
end ) 
  
addEvent( "shopLeave", true )  
addEventHandler( "shopLeave", root, function ( ) 
     setElementFrozen ( source, false ); 
     setElementDimension ( source, 0 ); 
     setElementInterior( source, 0 ); 
     local x, y, z = getElementPosition( source ); 
     setElementPosition( source, x, y, z ); 
end ) 

Take a look at the function "createSelector"

Link to comment
Use triggerServerEvent check if the player is logged in then send the information to the client side.

Example:

Client side:

triggerServerEvent("isClientReady",resourceRoot) 

Server side:

function isReady() 
    if isPlayerLoggedIn(client) then  
        triggerClientEvent(client,"eventName",client) 
    end  
end  
addEvent("isClientReady",true) 
addEventHandler("isClientReady",resourceRoot,isReady) 
  
-- Check if the player is logged In  
function isPlayerLoggedIn(player) 
    if (not isElement(player) or getElementType(player) ~= "player") then return false end 
    local account = getPlayerAccount(player) 
    if (isGuestAccount(account)) then return false end 
    return true 
end 

Tried it again but it isnt working, I dont know why ...

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