zezim Posted August 25, 2022 Share Posted August 25, 2022 Hey whats up? Could you help me how I could do to save the ID in the player when he leaves the game? The system works perfectly, but when I exit the game I lose the random ID. Could you help me teach how I could finish this code to save with my autosave or could you help me by giving the code? Quote function genRandomID() local rnumber = "" local chars = "1234567890" for i = 1, 5 do -- Here you define the number of digits, here a number with 5 digits will be generated local rand = math.random(#chars) rnumber = rnumber .. chars:sub(rand, rand) end return rnumber end local randomID = genRandomID() function Start_Id ( _, acc ) if eventName == "onPlayerLogin" then setElementData(source, "ID", randomID or "N/A" ) outputChatBox ( "#838B83➲ #ff0000LOGIN #838B83➲ Nick: #ff0000 ( ".. getPlayerName(source) .." #ff0000) ID: ( "..(getAccountID(acc) or "N/A") .." )", root, 255,255,255,true) elseif eventName == "onPlayerLogout" then removeElementData( source, "ID" ) outputChatBox ( "#838B83➲ #ff0000LOGIN #838B83➲ Nick: #ff0000 ( ".. getPlayerName(source) .." #ff0000) Deslogou.", root, 255,255,255,true) elseif eventName == "onResourceStart" then for _, player in pairs(getElementsByType("player")) do local acc = getPlayerAccount(player) if not isGuestAccount(acc) then setElementData(source, "ID", randomID or "N/A" ) end end end end addEventHandler("onResourceStart", resourceRoot, Start_Id) addEventHandler("onPlayerLogout", root, Start_Id) addEventHandler("onPlayerLogin", root, Start_Id) function getPlayerID(id) v = false for i, player in ipairs (getElementsByType("player")) do if getElementData(player, "ID") == id then v = player break end end return v end --============================================================================================================================-- --=============================-- ----------- ID PLAYER ------------ --=============================-- function getnick(player, command, id, ...) if(id) then local playerID = tonumber(id) if(playerID) then local Player2 = getPlayerID(playerID) if(Player2) then outputChatBox ( "#838B83➲ #ff0000INFO #ff0000 ➲ #ff0000 Player name #ff0000" .. getPlayerName(Player2) .."", player, 255,255,255,true) else outputChatBox ( "#838B83➲ #ff0000ERRO #ff0000 ➲ #ff0000 The Player of ID: #ff0000( " .. id .. " ) #ff0000Was not found!", player, 255,255,255,true) end else outputChatBox ( "#838B83➲ #ff0000ERRO #ff0000 ➲ #ff0000 ID: #ff0000( " .. id .. " ) #ff0000Invalid!", player, 255,255,255,true) end else outputChatBox ( "#838B83➲ #ff0000 Use /id #ff0000[#ffffffID#00ff00]", player, 255,255,255,true) end end addCommandHandler("id", getnick) This is my autosave system that I use: Quote function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) if not (isGuestAccount (getPlayerAccount (source))) then local accountData = getAccountData (theCurrentAccount, "funmodev2-money") if (accountData) then local playerMoney = getAccountData (theCurrentAccount, "funmodev2-money") local playerSkin = getAccountData (theCurrentAccount, "funmodev2-skin") local playerHealth = getAccountData (theCurrentAccount, "funmodev2-health") local playerArmor = getAccountData (theCurrentAccount, "funmodev2-armor") local R = getAccountData (theCurrentAccount, "funmodev2-R") local G = getAccountData (theCurrentAccount, "funmodev2-G") local B = getAccountData (theCurrentAccount, "funmodev2-B") local playerX = getAccountData (theCurrentAccount, "funmodev2-x") local playerY = getAccountData (theCurrentAccount, "funmodev2-y") local playerZ = getAccountData (theCurrentAccount, "funmodev2-z") local playerInt = getAccountData (theCurrentAccount, "funmodev2-int") local playerDim = getAccountData (theCurrentAccount, "funmodev2-dim") local playerWanted = getAccountData (theCurrentAccount, "funmodev2-wantedlevel") local playerTeam = getAccountData (theCurrentAccount, "funmodev2-Team") local playerWeaponID0 = getAccountData (theCurrentAccount, "funmodev2-weaponID0") local playerWeaponID1 = getAccountData (theCurrentAccount, "funmodev2-weaponID1") local playerWeaponID2 = getAccountData (theCurrentAccount, "funmodev2-weaponID2") local playerWeaponID3 = getAccountData (theCurrentAccount, "funmodev2-weaponID3") local playerWeaponID4 = getAccountData (theCurrentAccount, "funmodev2-weaponID4") local playerWeaponID5 = getAccountData (theCurrentAccount, "funmodev2-weaponID5") local playerWeaponID6 = getAccountData (theCurrentAccount, "funmodev2-weaponID6") local playerWeaponID7 = getAccountData (theCurrentAccount, "funmodev2-weaponID7") local playerWeaponID8 = getAccountData (theCurrentAccount, "funmodev2-weaponID8") local playerWeaponID9 = getAccountData (theCurrentAccount, "funmodev2-weaponID9") local playerWeaponID10 = getAccountData (theCurrentAccount, "funmodev2-weaponID10") local playerWeaponID11 = getAccountData (theCurrentAccount, "funmodev2-weaponID11") local playerWeaponID12 = getAccountData (theCurrentAccount, "funmodev2-weaponID12") local playerWeaponAmmo0 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo0") local playerWeaponAmmo1 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo1") local playerWeaponAmmo2 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo2") local playerWeaponAmmo3 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo3") local playerWeaponAmmo4 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo4") local playerWeaponAmmo5 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo5") local playerWeaponAmmo6 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo6") local playerWeaponAmmo7 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo7") local playerWeaponAmmo8 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo8") local playerWeaponAmmo9 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo9") local playerWeaponAmmo10 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo10") local playerWeaponAmmo11 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo11") local playerWeaponAmmo12 = getAccountData (theCurrentAccount, "funmodev2-weaponAmmo12") spawnPlayer (source, playerX, playerY, playerZ +1, 0, playerSkin, playerInt, playerDim) setPlayerMoney (source, playerMoney) setTimer (setElementHealth, 50, 1, source, playerHealth) setTimer (setPedArmor, 50, 1, source, playerArmor) setTimer (setPlayerWantedLevel, 50, 1, source, playerWanted) giveWeapon(source, playerWeaponID0, playerWeaponAmmo0, true) giveWeapon(source, playerWeaponID1, playerWeaponAmmo1, false) giveWeapon(source, playerWeaponID2, playerWeaponAmmo2, false) giveWeapon(source, playerWeaponID3, playerWeaponAmmo3, false) giveWeapon(source, playerWeaponID4, playerWeaponAmmo4, false) giveWeapon(source, playerWeaponID5, playerWeaponAmmo5, false) giveWeapon(source, playerWeaponID6, playerWeaponAmmo6, false) giveWeapon(source, playerWeaponID7, playerWeaponAmmo7, false) giveWeapon(source, playerWeaponID8, playerWeaponAmmo8, false) giveWeapon(source, playerWeaponID9, playerWeaponAmmo9, false) giveWeapon(source, playerWeaponID10, playerWeaponAmmo10, false) giveWeapon(source, playerWeaponID11, playerWeaponAmmo11, false) giveWeapon(source, playerWeaponID12, playerWeaponAmmo12, false) setCameraTarget (source, source) fadeCamera(source, true, 2.0) setPlayerNametagColor (source, R, G, B) else spawnPlayer (source, 1481.0855712891, -1771.2996826172, 18.795753479004, 0,137, 0, 0) --[[setPlayerMoney (source, 200) setCameraTarget (source, source) fadeCamera(source, true, 2.0) ]]-- setPlayerNametagColor (source, 255, 255, 255) end end end addEventHandler ("onPlayerLogin", getRootElement(), playerLogin) function onLogout () kickPlayer (source, nil, "Logging out is disallowed.") end addEventHandler ("onPlayerLogout", getRootElement(), onLogout) function onQuit (quitType, reason, responsibleElement) if not (isGuestAccount (getPlayerAccount (source))) then account = getPlayerAccount (source) if (account) then local x,y,z = getElementPosition (source) local r,g,b = getPlayerNametagColor (source) setAccountData (account, "funmodev2-money", tostring (getPlayerMoney (source))) setAccountData (account, "funmodev2-skin", tostring (getPedSkin (source))) setAccountData (account, "funmodev2-health", tostring (getElementHealth (source))) setAccountData (account, "funmodev2-armor", tostring (getPedArmor (source))) setAccountData (account, "funmodev2-R", r) setAccountData (account, "funmodev2-G", g) setAccountData (account, "funmodev2-B", b) setAccountData (account, "funmodev2-x", x) setAccountData (account, "funmodev2-y", y) setAccountData (account, "funmodev2-z", z) setAccountData (account, "funmodev2-int", getElementInterior (source)) setAccountData (account, "funmodev2-dim", getElementDimension (source)) setAccountData (account, "funmodev2-wantedlevel", getPlayerWantedLevel (source)) setAccountData (account, "funmodev2-weaponID0", getPedWeapon (source, 0)) setAccountData (account, "funmodev2-weaponID1", getPedWeapon (source, 1)) setAccountData (account, "funmodev2-weaponID2", getPedWeapon (source, 2)) setAccountData (account, "funmodev2-weaponID3", getPedWeapon (source, 3)) setAccountData (account, "funmodev2-weaponID4", getPedWeapon (source, 4)) setAccountData (account, "funmodev2-weaponID5", getPedWeapon (source, 5)) setAccountData (account, "funmodev2-weaponID6", getPedWeapon (source, 6)) setAccountData (account, "funmodev2-weaponID7", getPedWeapon (source, 7)) setAccountData (account, "funmodev2-weaponID8", getPedWeapon (source, 8)) setAccountData (account, "funmodev2-weaponID9", getPedWeapon (source, 9)) setAccountData (account, "funmodev2-weaponID10", getPedWeapon (source, 10)) setAccountData (account, "funmodev2-weaponID11", getPedWeapon (source, 11)) setAccountData (account, "funmodev2-weaponID12", getPedWeapon (source, 12)) setAccountData (account, "funmodev2-weaponAmmo0", getPedTotalAmmo (source, 0)) setAccountData (account, "funmodev2-weaponAmmo1", getPedTotalAmmo (source, 1)) setAccountData (account, "funmodev2-weaponAmmo2", getPedTotalAmmo (source, 2)) setAccountData (account, "funmodev2-weaponAmmo3", getPedTotalAmmo (source, 3)) setAccountData (account, "funmodev2-weaponAmmo4", getPedTotalAmmo (source, 4)) setAccountData (account, "funmodev2-weaponAmmo5", getPedTotalAmmo (source, 5)) setAccountData (account, "funmodev2-weaponAmmo6", getPedTotalAmmo (source, 6)) setAccountData (account, "funmodev2-weaponAmmo7", getPedTotalAmmo (source, 7)) setAccountData (account, "funmodev2-weaponAmmo8", getPedTotalAmmo (source, 8)) setAccountData (account, "funmodev2-weaponAmmo9", getPedTotalAmmo (source, 9)) setAccountData (account, "funmodev2-weaponAmmo10", getPedTotalAmmo (source, 10)) setAccountData (account, "funmodev2-weaponAmmo11", getPedTotalAmmo (source, 11)) setAccountData (account, "funmodev2-weaponAmmo12", getPedTotalAmmo (source, 12)) end end end addEventHandler ("onPlayerQuit", getRootElement(), onQuit) --[[function onWasted(totalAmmo, killer, killerWeapon, bodypart, stealth) if not( isGuestAccount (getPlayerAccount(source)) ) then local theWeapon = getPedWeapon (source) local weaponAmmo = getPedTotalAmmo (source) fadeCamera (source, false) setTimer (spawnPlayer, 1000, 1, source, 2036.1735839844, -1413.0563964844, 16.9921875, 0, getPedSkin (source), 0, 0, getPlayerTeam(source)) setTimer (setCameraTarget, 1250, 1, source, source) setTimer (fadeCamera, 2000, 1, source, true) setTimer (giveWeapon, 2000, 1, source, theWeapon, weaponAmmo, true) end end addEventHandler ("onPlayerWasted", getRootElement(), onWasted)]]-- --- function setTeam() local account = getPlayerAccount(source) -- gets players account local team = getAccountData (account, "team") -- gets players team if (team) and getTeamFromName(team) then setPlayerTeam(source, getTeamFromName(team)) -- sets players team end end addEventHandler("onPlayerLogin",root,setTeam) -- sets players team on login function save() local team = getPlayerTeam(source) -- Gets the players team local account = getPlayerAccount(source) if (team) and not isGuestAccount(account) then -- Checks to see if the player is a guest or not setAccountData(account, "team", getTeamName(team)) --saves team end end addEventHandler("onPlayerQuit", getRootElement(), save) -- saves team on quit Link to comment
Vampire Posted August 25, 2022 Share Posted August 25, 2022 Hello @zezim I've moved your topic to the Scripting section as it's more suitable. The General Multi Language discussion section used to make requests for the multi language boards not to get help with your code. Link to comment
fxl Posted August 25, 2022 Share Posted August 25, 2022 setAccountData(account, "ID", randomID) ? Link to comment
zezim Posted August 26, 2022 Author Share Posted August 26, 2022 8 hours ago, fxl said: setAccountData(account, "ID", randomID) ? Thanks so much i gonna tryna 8 hours ago, fxl said: setAccountData(account, "ID", randomID) ? I put it on autosave. Do you think I should put in the random id system too? Link to comment
zezim Posted August 26, 2022 Author Share Posted August 26, 2022 local playerID = tostring(id) Link to comment
mafioz Posted August 26, 2022 Share Posted August 26, 2022 (edited) function genRandomID() local rnumber = "" local chars = "1234567890" for i = 1, 5 do -- Here you define the number of digits, here a number with 5 digits will be generated local rand = math.random(#chars) rnumber = rnumber .. chars:sub(rand, rand) end return tonumber(rnumber) end function Start_Id ( _, acc ) if eventName == "onPlayerLogin" then local my_id = getAccountData(getPlayerAccount(source),"ID") if not my_id then my_id = genRandomID() setAccountData(getPlayerAccount(source),"ID",my_id) end setElementData(source, "ID", my_id or "N/A" ) outputChatBox ( "#838B83➲ #ff0000LOGIN #838B83➲ Nick: #ff0000 ( ".. getPlayerName(source) .." #ff0000) ID: ( "..(my_id or "N/A") .." )", root, 255,255,255,true) elseif eventName == "onPlayerLogout" then removeElementData( source, "ID" ) outputChatBox ( "#838B83➲ #ff0000LOGIN #838B83➲ Nick: #ff0000 ( ".. getPlayerName(source) .." #ff0000) Deslogou.", root, 255,255,255,true) --[[elseif eventName == "onResourceStart" then for _, player in pairs(getElementsByType("player")) do local acc = getPlayerAccount(player) if not isGuestAccount(acc) then setElementData(source, "ID", randomID or "N/A" ) end end--]] end end addEventHandler("onResourceStart", resourceRoot, Start_Id) addEventHandler("onPlayerLogout", root, Start_Id) addEventHandler("onPlayerLogin", root, Start_Id) function getPlayerID(id) v = false for i, player in ipairs (getElementsByType("player")) do if getElementData(player, "ID") == id then v = player break end end return v end --============================================================================================================================-- --=============================-- ----------- ID PLAYER ------------ --=============================-- function getnick(player, command, id, ...) if(id) then local playerID = tonumber(id) if(playerID) then local Player2 = getPlayerID(playerID) if(Player2) then outputChatBox ( "#838B83➲ #ff0000INFO #ff0000 ➲ #ff0000 Player name #ff0000" .. getPlayerName(Player2) .."", player, 255,255,255,true) else outputChatBox ( "#838B83➲ #ff0000ERRO #ff0000 ➲ #ff0000 The Player of ID: #ff0000( " .. id .. " ) #ff0000Was not found!", player, 255,255,255,true) end else outputChatBox ( "#838B83➲ #ff0000ERRO #ff0000 ➲ #ff0000 ID: #ff0000( " .. id .. " ) #ff0000Invalid!", player, 255,255,255,true) end else outputChatBox ( "#838B83➲ #ff0000 Use /id #ff0000[#ffffffID#00ff00]", player, 255,255,255,true) end end addCommandHandler("id", getnick) Try this * If you are already in the game, then you should re-sign in to get an ID Edited August 26, 2022 by shishani Link to comment
AngelAlpha Posted August 27, 2022 Share Posted August 27, 2022 On 25/08/2022 at 21:23, zezim said: Hey whats up? Could you help me how I could do to save the ID in the player when he leaves the game? The system works perfectly, but when I exit the game I lose the random ID. Could you help me teach how I could finish this code to save with my autosave or could you help me by giving the code? This is my autosave system that I use: function Start_Id ( _, acc ) if eventName == "onPlayerLogin" then local my_id = getAccountID(acc) setElementData(source, "ID", my_id or "N/A" ) outputChatBox ( "#838B83➲ #ff0000LOGIN #838B83➲ Nick: #ff0000 ( ".. getPlayerName(source) .." #ff0000) ID: ( "..(my_id or "N/A") .." )", root, 255,255,255,true) elseif eventName == "onResourceStart" then for _, player in pairs(getElementsByType("player")) do local acc = getPlayerAccount(player) if not isGuestAccount(acc) then local my_id = getAccountID(acc) setElementData(player, "ID", my_id or "N/A" ) end end end end addEventHandler("onResourceStart", resourceRoot, Start_Id) addEventHandler("onPlayerLogin", root, Start_Id) function getPlayerID(id) for i, player in ipairs (getElementsByType("player")) do if getElementData(player, "ID") and tonumber(getElementData(player, "ID")) == tonumber(id) then return player end end end function getnick(player, command, id, ...) if id then local playerID = tonumber(id) if(playerID) then local Player2 = getPlayerID(playerID) if(Player2) then outputChatBox ( "#838B83➲ #ff0000INFO #ff0000 ➲ #ff0000 Player name #ff0000" .. getPlayerName(Player2) .."", player, 255,255,255,true) else outputChatBox ( "#838B83➲ #ff0000ERRO #ff0000 ➲ #ff0000 The Player of ID: #ff0000( " .. id .. " ) #ff0000Was not found!", player, 255,255,255,true) end else outputChatBox ( "#838B83➲ #ff0000ERRO #ff0000 ➲ #ff0000 ID: #ff0000( " .. id .. " ) #ff0000Invalid!", player, 255,255,255,true) end else outputChatBox ( "#838B83➲ #ff0000 Use /id #ff0000[#ffffffID#00ff00]", player, 255,255,255,true) end end addCommandHandler("id", getnick) Account already have ID (getAccountID) Link to comment
zezim Posted August 29, 2022 Author Share Posted August 29, 2022 Thank you so much guys, from my heart! On 8/26/2022 at 8:10 PM, shishani said: function genRandomID() local rnumber = "" local chars = "1234567890" for i = 1, 5 do -- Here you define the number of digits, here a number with 5 digits will be generated local rand = math.random(#chars) rnumber = rnumber .. chars:sub(rand, rand) end return tonumber(rnumber) end function Start_Id ( _, acc ) if eventName == "onPlayerLogin" then local my_id = getAccountData(getPlayerAccount(source),"ID") if not my_id then my_id = genRandomID() setAccountData(getPlayerAccount(source),"ID",my_id) end setElementData(source, "ID", my_id or "N/A" ) outputChatBox ( "#838B83➲ #ff0000LOGIN #838B83➲ Nick: #ff0000 ( ".. getPlayerName(source) .." #ff0000) ID: ( "..(my_id or "N/A") .." )", root, 255,255,255,true) elseif eventName == "onPlayerLogout" then removeElementData( source, "ID" ) outputChatBox ( "#838B83➲ #ff0000LOGIN #838B83➲ Nick: #ff0000 ( ".. getPlayerName(source) .." #ff0000) Deslogou.", root, 255,255,255,true) --[[elseif eventName == "onResourceStart" then for _, player in pairs(getElementsByType("player")) do local acc = getPlayerAccount(player) if not isGuestAccount(acc) then setElementData(source, "ID", randomID or "N/A" ) end end--]] end end addEventHandler("onResourceStart", resourceRoot, Start_Id) addEventHandler("onPlayerLogout", root, Start_Id) addEventHandler("onPlayerLogin", root, Start_Id) function getPlayerID(id) v = false for i, player in ipairs (getElementsByType("player")) do if getElementData(player, "ID") == id then v = player break end end return v end --============================================================================================================================-- --=============================-- ----------- ID PLAYER ------------ --=============================-- function getnick(player, command, id, ...) if(id) then local playerID = tonumber(id) if(playerID) then local Player2 = getPlayerID(playerID) if(Player2) then outputChatBox ( "#838B83➲ #ff0000INFO #ff0000 ➲ #ff0000 Player name #ff0000" .. getPlayerName(Player2) .."", player, 255,255,255,true) else outputChatBox ( "#838B83➲ #ff0000ERRO #ff0000 ➲ #ff0000 The Player of ID: #ff0000( " .. id .. " ) #ff0000Was not found!", player, 255,255,255,true) end else outputChatBox ( "#838B83➲ #ff0000ERRO #ff0000 ➲ #ff0000 ID: #ff0000( " .. id .. " ) #ff0000Invalid!", player, 255,255,255,true) end else outputChatBox ( "#838B83➲ #ff0000 Use /id #ff0000[#ffffffID#00ff00]", player, 255,255,255,true) end end addCommandHandler("id", getnick) Try this * If you are already in the game, then you should re-sign in to get an ID I LOVE U BROTHERRRRRRRRRRRRRRRRR IF U WANNA 3 DOLLARS GIVE ME YOUR DISCORD, THANKS SO MUCH! Link to comment
mafioz Posted August 29, 2022 Share Posted August 29, 2022 2 hours ago, zezim said: Thank you so much guys, from my heart! I LOVE U BROTHERRRRRRRRRRRRRRRRR IF U WANNA 3 DOLLARS GIVE ME YOUR DISCORD, THANKS SO MUCH! No problem mafioz#2825 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now