Jump to content

Save label text


SirniNamaz

Recommended Posts

Posted

i have a label which is a number and it is different for every player.. what i need is script that will save it when players disconnect and load it when players connect

Posted

Well for the client:

  
addEvent("getLabelTxt",true) 
addEventHandler("getLabelTxt",getRootElement(), 
function() 
textt = guiGetText(mylabelnamehere) -- PUT YOUR LABEL NAME HERE 
triggerServerEvent("saveLabelTxt",getLocalPlayer(),getLocalPlayer(),textt) -- we will send it to the server 
end) 
  
  

and the server:

  
function getTextQuit() 
triggerClientEvent(source,"getLabelTxt",getRootElement()) -- trigger client 
end 
addEventHandler("onPlayerQuit",getRootElement(),getTextQuit) 
  
-- save 
addEvent("saveLabelTxt",true) 
addEventHandler("saveLabelTxt",getRootElement(), 
function(player,text) 
playeraccount = getPlayerAccount(player) 
if (playeraccount) and (text) then 
setAccountData(playeraccount,"number",tonumber(text)) -- save it 
end 
end) 
  
-- load 
function loadTextNumb() 
playeraccount = getPlayerAccount(source) 
if (playeraccount) then 
number = getAccountData(playeraccount,"number") 
-- DO WHATEVER YOU WANT WITH THE NUMBER ARGUEMENT 
end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadTextNumb) 
  

The code looks messy and I don't guarantee that it'll work.

Posted

i dont actually understand your code, but can you make the code for the following labels pls:

- lblCannabis

- lblHeroin

- lblCocaine

- lblLSD

- lblEcstasy

- lblOpium

(i will put your name in credits when i post this resource)

every player has different value, and the only thing im asking for is to save that number when player disconnects, and load it when he connects

Posted
i dont actually understand your code, but can you make the code for the following labels pls:

- lblCannabis

- lblHeroin

- lblCocaine

- lblLSD

- lblEcstasy

- lblOpium

(i will put your name in credits when i post this resource)

every player has different value, and the only thing im asking for is to save that number when player disconnects, and load it when he connects

You can figure it out by yourself :)

It's not really that hard.

Posted

Glad you got it working by yourself.

Just edit the server load function like this:

  
  
-- load 
function loadTextNumb() 
playeraccount = getPlayerAccount(source) 
if (playeraccount) then 
number = getAccountData(playeraccount,"number") 
if (number) then 
-- DO WHATEVER YOU WANT WITH THE NUMBER ARGUEMENT 
else 
-- No number found.. New player 
triggerClientEvent(source,"firstTime",getRootElement()) 
end 
end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadTextNumb) 
  
  

and add client:

  
addEvent("firstTime",true) 
addEventHandler("firstTime",getRootElement(), 
function() 
guiSetText(myLabelNameHere,"0") 
end) 
  

Posted
Glad you got it working by yourself.

Just edit the server load function like this:

  
  
-- load 
function loadTextNumb() 
playeraccount = getPlayerAccount(source) 
if (playeraccount) then 
number = getAccountData(playeraccount,"number") 
if (number) then 
-- DO WHATEVER YOU WANT WITH THE NUMBER ARGUEMENT 
else 
-- No number found.. New player 
triggerClientEvent(source,"firstTime",getRootElement()) 
end 
end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadTextNumb) 
  
  

and add client:

  
addEvent("firstTime",true) 
addEventHandler("firstTime",getRootElement(), 
function() 
guiSetText(myLabelNameHere,"0") 
end) 
  

i thought i make it work but i didnt, and i postet the entire script to this theard and i hope you can help me: viewtopic.php?f=91&t=46802

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