Jump to content

Need some help


Recommended Posts

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 by RandomRambo
Link to comment

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 by Erlkonig
Link to comment
  • 2 weeks later...
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
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
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
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

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 by Tekken
Typo
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...