Jump to content

Проверка залогинился ли игрок на сервер или играет unregiste


Recommended Posts

У меня есть система save'a денег и оружия, которая сохраняет все по аккаунту. Я сделал на сервере режим игры без регистрации (Guest). При таком режиме все кто заходят за Guests получают деньги и оружия сохраненные предшественниками. Как сделать проверку залогинился ли игрок или нет. Если залогинился то сохранять данные.

Скрипт save системы:

function onPlayerQuit ( ) 
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local x,y,z = getElementPosition (source) 
            setAccountData ( playeraccount, "s.HandMoney", getPlayerMoney ( source ) ) 
            setAccountData (playeraccount, "s.weap0", getPedWeapon ( source, 0 )) 
            setAccountData (playeraccount, "s.weap1", getPedWeapon ( source, 1 )) 
            setAccountData (playeraccount, "s.weap2", getPedWeapon ( source, 2 )) 
            setAccountData (playeraccount, "s.ammo2", getPedTotalAmmo ( source, 2 )) 
            setAccountData (playeraccount, "s.weap3", getPedWeapon ( source, 3 )) 
            setAccountData (playeraccount, "s.ammo3", getPedTotalAmmo ( source, 3 )) 
            setAccountData (playeraccount, "s.weap4", getPedWeapon ( source, 4 )) 
            setAccountData (playeraccount, "s.ammo4", getPedTotalAmmo ( source, 4 )) 
            setAccountData (playeraccount, "s.weap5", getPedWeapon ( source, 5 )) 
            setAccountData (playeraccount, "s.ammo5", getPedTotalAmmo ( source, 5 )) 
            setAccountData (playeraccount, "s.weap6", getPedWeapon ( source, 6 )) 
            setAccountData (playeraccount, "s.ammo6", getPedTotalAmmo ( source, 6 )) 
            setAccountData (playeraccount, "s.weap7", getPedWeapon ( source, 7 )) 
            setAccountData (playeraccount, "s.ammo7", getPedTotalAmmo ( source, 7 )) 
            setAccountData (playeraccount, "s.weap8", getPedWeapon ( source, 8 )) 
            setAccountData (playeraccount, "s.ammo8", getPedTotalAmmo ( source, 8 )) 
            setAccountData (playeraccount, "s.weap9", getPedWeapon ( source, 9 )) 
            setAccountData (playeraccount, "s.ammo9", getPedTotalAmmo ( source, 9 )) 
            setAccountData (playeraccount, "s.weap10", getPedWeapon ( source, 10 )) 
            setAccountData (playeraccount, "s.weap11", getPedWeapon ( source, 11 )) 
            setAccountData (playeraccount, "s.weap12", getPedWeapon ( source, 12 )) 
      end 
end 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
  
function onPlayerWasted ( ) 
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local x,y,z = getElementPosition (source) 
            setAccountData ( playeraccount, "s.HandMoney", getPlayerMoney ( source ) ) 
            setAccountData (playeraccount, "s.weap0", getPedWeapon ( source, 0 )) 
            setAccountData (playeraccount, "s.weap1", getPedWeapon ( source, 1 )) 
            setAccountData (playeraccount, "s.weap2", getPedWeapon ( source, 2 )) 
            setAccountData (playeraccount, "s.ammo2", getPedTotalAmmo ( source, 2 )) 
            setAccountData (playeraccount, "s.weap3", getPedWeapon ( source, 3 )) 
            setAccountData (playeraccount, "s.ammo3", getPedTotalAmmo ( source, 3 )) 
            setAccountData (playeraccount, "s.weap4", getPedWeapon ( source, 4 )) 
            setAccountData (playeraccount, "s.ammo4", getPedTotalAmmo ( source, 4 )) 
            setAccountData (playeraccount, "s.weap5", getPedWeapon ( source, 5 )) 
            setAccountData (playeraccount, "s.ammo5", getPedTotalAmmo ( source, 5 )) 
            setAccountData (playeraccount, "s.weap6", getPedWeapon ( source, 6 )) 
            setAccountData (playeraccount, "s.ammo6", getPedTotalAmmo ( source, 6 )) 
            setAccountData (playeraccount, "s.weap7", getPedWeapon ( source, 7 )) 
            setAccountData (playeraccount, "s.ammo7", getPedTotalAmmo ( source, 7 )) 
            setAccountData (playeraccount, "s.weap8", getPedWeapon ( source, 8 )) 
            setAccountData (playeraccount, "s.ammo8", getPedTotalAmmo ( source, 8 )) 
            setAccountData (playeraccount, "s.weap9", getPedWeapon ( source, 9 )) 
            setAccountData (playeraccount, "s.ammo9", getPedTotalAmmo ( source, 9 )) 
            setAccountData (playeraccount, "s.weap10", getPedWeapon ( source, 10 )) 
            setAccountData (playeraccount, "s.weap11", getPedWeapon ( source, 11 )) 
            setAccountData (playeraccount, "s.weap12", getPedWeapon ( source, 12 )) 
      end 
end 
addEventHandler ( "onPlayerWasted", getRootElement ( ), onPlayerWasted ) 
  
local root = getRootElement() 
addEventHandler("onPlayerSpawn", root, 
  function() 
     local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getAccountData ( playeraccount, "s.HandMoney" ) 
            if ( playermoney ) then 
                  setPlayerMoney ( source, playermoney ) 
            end 
            local weap0 = getAccountData(playeraccount, "s.weap0") 
            local weap1 = getAccountData(playeraccount, "s.weap1") 
            local weap2 = getAccountData(playeraccount, "s.weap2") 
            local ammo2 = getAccountData(playeraccount, "s.ammo2") 
            local weap3 = getAccountData(playeraccount, "s.weap3") 
            local ammo3 = getAccountData(playeraccount, "s.ammo3") 
            local weap4 = getAccountData(playeraccount, "s.weap4") 
            local ammo4 = getAccountData(playeraccount, "s.ammo4") 
            local weap5 = getAccountData(playeraccount, "s.weap5") 
            local ammo5 = getAccountData(playeraccount, "s.ammo5") 
            local weap6 = getAccountData(playeraccount, "s.weap6") 
            local ammo6 = getAccountData(playeraccount, "s.ammo6") 
            local weap7 = getAccountData(playeraccount, "s.weap7") 
            local ammo7 = getAccountData(playeraccount, "s.ammo7") 
            local weap8 = getAccountData(playeraccount, "s.weap8") 
            local ammo8 = getAccountData(playeraccount, "s.ammo8") 
            local weap9 = getAccountData(playeraccount, "s.weap9") 
            local ammo9 = getAccountData(playeraccount, "s.ammo9") 
            local weap10 = getAccountData(playeraccount, "s.weap10") 
            local weap11 = getAccountData(playeraccount, "s.weap11") 
            local weap12 = getAccountData(playeraccount, "s.weap12") 
            giveWeapon ( source, weap0, 1 ) 
            giveWeapon ( source, weap1, 1 ) 
            giveWeapon ( source, weap2, ammo2 ) 
            giveWeapon ( source, weap3, ammo3 ) 
            giveWeapon ( source, weap4, ammo4 ) 
            giveWeapon ( source, weap5, ammo5 ) 
            giveWeapon ( source, weap6, ammo6 ) 
            giveWeapon ( source, weap7, ammo7 ) 
            giveWeapon ( source, weap8, ammo8 ) 
            giveWeapon ( source, weap9, ammo9 ) 
            giveWeapon ( source, weap10, 1 ) 
            giveWeapon ( source, weap11, 1 ) 
            giveWeapon ( source, weap12, 1 )         
      end 
  end 
) 
  
  

P.S. По идеи "if ( playeraccount ) then" должна проверять наличие аккаунта, но както не очень работает((

Скрипт нажатия кнопки играть за Guest (На всякий случай):

-- Guest mode 
function onClickGuest(button,state) 
    if(button == "left" and state == "up") then 
        if (source == btnPlayAsGuest) then 
            guiSetVisible(GUIEditor_Window[1], false) 
            guiSetInputEnabled(false) 
            showCursor(false) 
            outputChatBox("#0000FF* #FFFFFFYou've chosen to play as a #ABCDEFGUEST#FFFFFF!",255,255,255,true) 
            triggerServerEvent("onRequestGuest",getLocalPlayer(), "Guest mode") 
            if blackLoginScreen == true then 
                fadeCamera(true,removeBlackScreenTime) 
            end 
        end 
    end 
end 

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