SirniNamaz Posted August 17, 2012 Share Posted August 17, 2012 CLIENT: function trolo() x,y = guiGetScreenSize() guiDrugs = guiCreateWindow(x-285-20,y-253-20,285,253,"F3 - Drug Manager",false) lblDrug = guiCreateLabel(17,31,32,16,"Drug:",false,guiDrugs) lblAmount = guiCreateLabel(203,31,50,15,"Amount:",false,guiDrugs) rdoCannabis = guiCreateRadioButton(15,55,135,17,"Cannabis",false,guiDrugs) guiRadioButtonSetSelected(rdoCannabis,true) rdoHeroin = guiCreateRadioButton(15,79,135,17,"Heroin",false,guiDrugs) rdoCocaine = guiCreateRadioButton(15,104,135,17,"Cocaine",false,guiDrugs) rdoLSD = guiCreateRadioButton(15,129,135,17,"LSD",false,guiDrugs) rdoEcstasy = guiCreateRadioButton(15,154,135,17,"Ecstasy",false,guiDrugs) rdoOpium = guiCreateRadioButton(15,180,135,17,"Opium",false,guiDrugs) btnTakeHit = guiCreateButton(39,208,96,30,"Take a Hit",false,guiDrugs) btnSell = guiCreateButton(145,208,96,30,"Sell",false,guiDrugs) lblCannabis = guiCreateLabel(200,54,54,14,"0",false,guiDrugs) guiLabelSetVerticalAlign(lblCannabis,"center") guiLabelSetHorizontalAlign(lblCannabis,"center",false) lblHeroin = guiCreateLabel(200,76,54,14,"0",false,guiDrugs) guiLabelSetVerticalAlign(lblHeroin,"center") guiLabelSetHorizontalAlign(lblHeroin,"center",false) lblCocaine = guiCreateLabel(200,102,54,14,"0",false,guiDrugs) guiLabelSetVerticalAlign(lblCocaine,"center") guiLabelSetHorizontalAlign(lblCocaine,"center",false) lblLSD = guiCreateLabel(200,127,54,14,"0",false,guiDrugs) guiLabelSetVerticalAlign(lblLSD,"center") guiLabelSetHorizontalAlign(lblLSD,"center",false) lblEcstasy = guiCreateLabel(200,153,54,14,"0",false,guiDrugs) guiLabelSetVerticalAlign(lblEcstasy,"center") guiLabelSetHorizontalAlign(lblEcstasy,"center",false) lblOpium = guiCreateLabel(200,179,54,14,"0",false,guiDrugs) guiLabelSetVerticalAlign(lblOpium,"center") guiLabelSetHorizontalAlign(lblOpium,"center",false) guiSetVisible(guiDrugs,false) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),trolo) function drugShowHide () if (guiGetVisible(guiDrugs)==false) then guiSetVisible(guiDrugs,true) showCursor(true) else guiSetVisible(guiDrugs,false) showCursor(false) end end bindKey("F3","down",drugShowHide) function oncQuit() amountCannabis = guiGetText(lblCannabis) amountHeroin = guiGetText(lblHeroin) amountCocaine = guiGetText(lblCocaine) amountLSD = guiGetText(lblLSD) amountEcstasy = guiGetText(lblEcstasy) amountOpium = guiGetText(lblOpium) triggerServerEvent("saveDrugAmount",getLocalPlayer(),getLocalPlayer(),amountCannabis,amountHeroin,amountCocaine,amountLSD,amountEcstasy,amountOpium) end addEventHandler("onClientPlayerQuit",getRootElement(),oncQuit) function outputDrug (var1, var2, var3, var4, var5, var6) guiSetText ( lblCannabis,var1) guiSetText ( lblHeroin,var2) guiSetText ( lblCocaine,var3) guiSetText ( lblLSD,var4) guiSetText ( lblEcstasy,var5) guiSetText ( lblOpium,var6) end addEvent( "outputDrug2", true ) addEventHandler( "outputDrug2", getRootElement(), outputDrug ) addEvent("firstTime",true) addEventHandler("firstTime",getRootElement(), function() outputChatBox ("Test Measage") guiSetText(lblCannabis,"0") guiSetText(lblHeroin,"0") guiSetText(lblCocaine,"0") guiSetText(lblLSD,"0") guiSetText(lblEcstasy,"0") guiSetText(lblOpium,"0") end) SERVER: addEvent("saveDrugAmount",true) addEventHandler("saveDrugAmount",getRootElement(), function(player,amountCannabisS,amountHeroinS,amountCocaineS,amountLSDS,amountEcstasyS,amountOpiumS) playeraccount = getPlayerAccount(player) if (playeraccount) then setAccountData(playeraccount,"amountCannabis",tonumber(amountCannabisS)) setAccountData(playeraccount,"amountHeroin",tonumber(amountHeroinS)) setAccountData(playeraccount,"amountCocaine",tonumber(amountCocaineS)) setAccountData(playeraccount,"amountLSDS",tonumber(amountLSDS)) setAccountData(playeraccount,"amountEcstasy",tonumber(amountEcstasyS)) setAccountData(playeraccount,"amountOpium",tonumber(amountOpiumS)) end end) function loadDrugAmount() playeraccount = getPlayerAccount(source) if (playeraccount) then amountCannabis2 = getAccountData(playeraccount,"amountCannabis") amountHeroin2 = getAccountData(playeraccount,"amountHeroin") amountCocaine2 = getAccountData(playeraccount,"amountCocaine") amountLSD2 = getAccountData(playeraccount,"amountLSDS") amountEcstasy2 = getAccountData(playeraccount,"amountEcstasy") amountOpium2 = getAccountData(playeraccount,"amountOpium") if (amountCannabis2) then triggerClientEvent (source, "outputDrug2", getRootElement(), amountCannabis2, amountHeroin2, amountCocaine2, amountLSD2, amountEcstasy2, amountOpium2 ) else triggerClientEvent(source,"firstTime",getRootElement()) end end end addEventHandler("onPlayerLogin",getRootElement(),loadDrugAmount) it doesnt work, someone said i need to put something in a database (internal.db) but i dont know how.. Link to comment
AMARANT Posted August 17, 2012 Share Posted August 17, 2012 setAccountData puts data into that database. What exactly doesn't work? Link to comment
SirniNamaz Posted August 17, 2012 Author Share Posted August 17, 2012 setAccountData puts data into that database. What exactly doesn't work? well it doesnt save my drug amount Link to comment
AMARANT Posted August 17, 2012 Share Posted August 17, 2012 You passed to the server function saveDrugAmount unnecessary player element and tried to save it in account data as drug amount. Maybe it's your mistake. Correct this: triggerServerEvent("saveDrugAmount",getLocalPlayer(),getLocalPlayer(),amountCannabis,amountHeroin,amountCocaine,amountLSD,amountEcstasy,amountOpium) To this: triggerServerEvent("saveDrugAmount",getLocalPlayer(),amountCannabis,amountHeroin,amountCocaine,amountLSD,amountEcstasy,amountOpium) Link to comment
SirniNamaz Posted August 17, 2012 Author Share Posted August 17, 2012 You passed to the server function saveDrugAmount unnecessary player element and tried to save it in account data as drug amount. Maybe it's your mistake.Correct this: triggerServerEvent("saveDrugAmount",getLocalPlayer(),getLocalPlayer(),amountCannabis,amountHeroin,amountCocaine,amountLSD,amountEcstasy,amountOpium) To this: triggerServerEvent("saveDrugAmount",getLocalPlayer(),amountCannabis,amountHeroin,amountCocaine,amountLSD,amountEcstasy,amountOpium) thanks i think it fixed it, but there is also problem with this: if (amountCannabis2) then triggerClientEvent (source, "outputDrug2", getRootElement(), amountCannabis2, amountHeroin2, amountCocaine2, amountLSD2, amountEcstasy2, amountOpium2 ) else triggerClientEvent(source,"firstTime",getRootElement()) end when i have 0 cannabis computer thinks its false and he resets my resources Link to comment
AMARANT Posted August 17, 2012 Share Posted August 17, 2012 That's what I told you. You passed to the function where you store drugs data that 'player' element and server was trying to convert it to number and of course it eventually returned false. And then when you login into the game, the server retrieves account data and it again returns false meaning that it's empty there. So you have to save data in account correctly. Link to comment
SirniNamaz Posted August 17, 2012 Author Share Posted August 17, 2012 That's what I told you. You passed to the function where you store drugs data that 'player' element and server was trying to convert it to number and of course it eventually returned false. And then when you login into the game, the server retrieves account data and it again returns false meaning that it's empty there. So you have to save data in account correctly. but how Link to comment
AMARANT Posted August 17, 2012 Share Posted August 17, 2012 In-game by debug messages or check internal.db by opening it and see for yourself the data. Try to put debug message in this part of the code: amountCannabis2 = getAccountData(playeraccount,"amountCannabis") amountHeroin2 = getAccountData(playeraccount,"amountHeroin") amountCocaine2 = getAccountData(playeraccount,"amountCocaine") amountLSD2 = getAccountData(playeraccount,"amountLSDS") amountEcstasy2 = getAccountData(playeraccount,"amountEcstasy") amountOpium2 = getAccountData(playeraccount,"amountOpium") outputChatBox(tostring(amountCannabis2)..", "..tostring(amountHeroin2)..", "..tostring(amountCocaine2)..", "..tostring(amountLSD2)..", "..tostring(amountEcstasy2)..", "..tostring(amountOpium2)) Link to comment
SirniNamaz Posted August 17, 2012 Author Share Posted August 17, 2012 In-game by debug messages or check internal.db by opening it and see for yourself the data. Try to put debug message in this part of the code: amountCannabis2 = getAccountData(playeraccount,"amountCannabis") amountHeroin2 = getAccountData(playeraccount,"amountHeroin") amountCocaine2 = getAccountData(playeraccount,"amountCocaine") amountLSD2 = getAccountData(playeraccount,"amountLSDS") amountEcstasy2 = getAccountData(playeraccount,"amountEcstasy") amountOpium2 = getAccountData(playeraccount,"amountOpium") outputChatBox(tostring(amountCannabis2)..", "..tostring(amountHeroin2)..", "..tostring(amountCocaine2)..", "..tostring(amountLSD2)..", "..tostring(amountEcstasy2)..", "..tostring(amountOpium2)) result: false,false,fasle,fasle,fasle,false Link to comment
AMARANT Posted August 17, 2012 Share Posted August 17, 2012 Your data wasn't saved. Have you done what I told you in my previous posts? I mean removing unnecessary getLocalPlayer() from client-side trigger event? If you have then try to check what data passes to the server by another debug message: addEvent("saveDrugAmount",true) addEventHandler("saveDrugAmount",getRootElement(), function(amountCannabisS,amountHeroinS,amountCocaineS,amountLSDS,amountEcstasyS,amountOpiumS) -- Removed 'player' from arguments playeraccount = getPlayerAccount(source) -- Here was 'player' if (playeraccount) then setAccountData(playeraccount,"amountCannabis",tonumber(amountCannabisS)) setAccountData(playeraccount,"amountHeroin",tonumber(amountHeroinS)) setAccountData(playeraccount,"amountCocaine",tonumber(amountCocaineS)) setAccountData(playeraccount,"amountLSDS",tonumber(amountLSDS)) setAccountData(playeraccount,"amountEcstasy",tonumber(amountEcstasyS)) setAccountData(playeraccount,"amountOpium",tonumber(amountOpiumS)) outputChatBox(tostring(amountCannabisS)..", "..tostring(amountHeroinS)..", "..tostring(amountCocaineS)..", "..tostring(amountLSDS)..", "..tostring(amountEcstasyS)..", "..tostring(amountOpiumS)) end end) Link to comment
AMARANT Posted August 17, 2012 Share Posted August 17, 2012 Ohh and change 'player' value in that function to 'source'. I marked it with a comment in the post above. Link to comment
SirniNamaz Posted August 17, 2012 Author Share Posted August 17, 2012 Ohh and change 'player' value in that function to 'source'. I marked it with a comment in the post above. same thing Link to comment
AMARANT Posted August 17, 2012 Share Posted August 17, 2012 Now I've finally noticed what is your problem. "onClientPlayerQuit" doesn't pass the data to the server because the local player is already went offline. I don't recommend using this function. You have to find another way to save your data or use server-side analog of this function. Link to comment
SirniNamaz Posted August 17, 2012 Author Share Posted August 17, 2012 Now I've finally noticed what is your problem. "onClientPlayerQuit" doesn't pass the data to the server because the local player is already went offline. I don't recommend using this function. You have to find another way to save your data or use server-side analog of this function. so what should i use Link to comment
AMARANT Posted August 17, 2012 Share Posted August 17, 2012 Just save your drugs data via setElementData function and set it into account with onPlayerQuit server-side event. 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