RandomRambo Posted May 22, 2021 Share Posted May 22, 2021 (edited) Hello guys. I want to make script on server side but it doesn't work,help me please. function bp() gnrl = getElementData(source,"Money") or 0 if getElementData(source,"opexp") == 2500 then setElementData(source, "Money",gnrl+1000) --outputChatBox("u got it", source, 255, 0, 0) end end Money just doesn't add when I get 2500 "opexp" . (DayZ mode) Edited May 22, 2021 by RandomRambo Link to comment
Erlkonig Posted May 22, 2021 Share Posted May 22, 2021 (edited) Try this. function bp() gnrl = getElementData(source,"Money") or 0 -- if gnrl is new and uses only here use local gnrl = ... if getElementData(source,"opexp") == "2500" then local new_money = tonumber(gnrl) + 1000 -- you should be sure that "Money" is number. setElementData(source, "Money", tostring(new_money)) outputChatBox("u got it", source, 255, 0, 0) end end I am not sure that is will help you because I am sure that on the new lua versions you can use "string" + number. Also, you can try to debug it. addCommandHandler("debugmoney", function(thePlayer) local money_data = getElementData(thePlayer, "Money" -- only in the case where the player is element with "money" if money_data then outputChatBox("Element Data of Money is "..money_data..".", thePlayer, 255, 255, 255) end end) Edited May 22, 2021 by Erlkonig Link to comment
RandomRambo Posted May 30, 2021 Author Share Posted May 30, 2021 Doesn't help. Still need help please guys Link to comment
SpecT Posted May 31, 2021 Share Posted May 31, 2021 20 hours ago, RandomRambo said: Doesn't help. Still need help please guys What exactly doesn't work ? Is it expected to get money if your EXP is 2500 or more ? Please be more specific on what's wrong so we could understand and help you. Link to comment
RandomRambo Posted May 31, 2021 Author Share Posted May 31, 2021 2 hours ago, SpecT said: What exactly doesn't work ? Is it expected to get money if your EXP is 2500 or more ? Please be more specific on what's wrong so we could understand and help you. It's for dayz mode.Yea,i need to check if opexp is 2500 then it should give once reward and check how much player have money and set +value like this setElementData(source, "Money",+1000) Link to comment
SpecT Posted May 31, 2021 Share Posted May 31, 2021 2 hours ago, RandomRambo said: It's for dayz mode.Yea,i need to check if opexp is 2500 then it should give once reward and check how much player have money and set +value like this setElementData(source, "Money",+1000) Well then keep in mind that the check for opexp is if its EXACTLY 2500 (not more not less). The code @Erlkonig posted should work just fine except the setElementData part where it converts the money (number) to string which doesn't make sense to save money as string. So maybe something like this: function bp() local gnrl = getElementData(source,"Money") or 0 -- if gnrl is new and uses only here use local gnrl = ... local opexp = getElementData(source,"opexp") or 0 if tonumber(opexp) == 2500 then -- if opexp can be more than 2500 then replace == with >= local new_money = tonumber(gnrl) + 1000 -- you should be sure that "Money" is number. setElementData(source, "Money", new_money) outputChatBox("u got it", source, 255, 0, 0) end end Link to comment
RandomRambo Posted May 31, 2021 Author Share Posted May 31, 2021 On 22/05/2021 at 04:07, Erlkonig said: Try this. function bp() gnrl = getElementData(source,"Money") or 0 -- if gnrl is new and uses only here use local gnrl = ... if getElementData(source,"opexp") == "2500" then local new_money = tonumber(gnrl) + 1000 -- you should be sure that "Money" is number. setElementData(source, "Money", tostring(new_money)) outputChatBox("u got it", source, 255, 0, 0) end end I am not sure that is will help you because I am sure that on the new lua versions you can use "string" + number. Also, you can try to debug it. addCommandHandler("debugmoney", function(thePlayer) local money_data = getElementData(thePlayer, "Money" -- only in the case where the player is element with "money" if money_data then outputChatBox("Element Data of Money is "..money_data..".", thePlayer, 255, 255, 255) end end) Idk,just nothing happens I just reached 2500 opexp and nothing happened.Money didn't change Link to comment
SpecT Posted June 1, 2021 Share Posted June 1, 2021 7 hours ago, RandomRambo said: Idk,just nothing happens I just reached 2500 opexp and nothing happened.Money didn't change Do you at least get the "u got it" message ? Link to comment
Tekken Posted June 1, 2021 Share Posted June 1, 2021 (edited) When you trigger bp() function in your script ? To me it looks like you just pasted that function there but you don’t even call it at all! you have the onElementDataChange event to check whenever an elements data changed you should use that event to check whether the opexp have changed and then call the function to give potential reward. You may check my simple level system if you still don’t get it working, it’s in my signature. Good luck. Edited June 1, 2021 by Tekken Typo Link to comment
RandomRambo Posted June 1, 2021 Author Share Posted June 1, 2021 8 hours ago, SpecT said: Do you at least get the "u got it" message ? nope Link to comment
Tekken Posted June 1, 2021 Share Posted June 1, 2021 2 minutes ago, RandomRambo said: nope Have you seen my message? Link to comment
RandomRambo Posted June 1, 2021 Author Share Posted June 1, 2021 22 minutes ago, Tekken said: Have you seen my message? Ye,I will try later 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