Jump to content

[HELP-ME] Patent / level


AnnaBelle

Recommended Posts

Updated the code, try this:


addEvent("onRequestXP",true)
addEventHandler("onRequestXP",root,function( m )
	local acc = getPlayerAccount(source)
	if isGuestAccount ( acc ) ~= true then
		setAccountData( acc, "tempEXPBoostTS", toJSON( { tostring(getRealTime().timestamp), m  } ) )
	end
end)

addEventHandler( "onResourceStop", resourceRoot,
	function()
		for i,p in pairs(getElementsByType("player")) do
			if not isGuestAccount ( getPlayerAccount(p) ) then
				local acc = getPlayerAccount(p)
				local eTimestamp = getAccountEXPBoostValue( acc, "timestamp" )
				if eTimestamp then setAccountData( acc, "tempEXPBoostTS", nil ) end;
			end
		end
	end
)

function checkEXPTime()
	for i,p in pairs(getElementsByType("player")) do
		if not isGuestAccount ( getPlayerAccount(p) ) then
			local acc = getPlayerAccount(p)
			local eTimestamp = getAccountEXPBoostValue( acc, "timestamp" )
			if eTimestamp and (getRealTime().timestamp - eTimestamp) > 86400 then
				outputChatBox("Your exp boost has expired", p)
				setAccountData( acc, "tempEXPBoostTS", nil )
			end
		end
	end
end
-- check every 10 mins
setTimer(checkEXPTime, (60*10) *1000, 0)

addEventHandler( "onPlayerLogin", root,
	function( _, acc )
		local eTimestamp = getAccountEXPBoostValue( acc, "timestamp" )
		if eTimestamp and (getRealTime().timestamp - eTimestamp) > 86400 then
			outputChatBox("Your exp boost has expired", source)
			setAccountData( acc, "tempEXPBoostTS", nil )
		end
end)

addEventHandler ( "onPlayerWasted", root,
	function( ammo, killer, weapon, bodypart )
		if killer and (getElementType(killer) == "player") and killer ~= source then
			if not getElementData(source,"bandit") then
				addPlayerStats (killer,"humanity",math.random(-2500,-1000))
			else
				addPlayerStats (killer,"humanity",math.random(1000,2500))
			end
			setElementData(killer,"murders", (getElementData(killer,"murders") or 0) +1)
			
			local acc = getPlayerAccount(killer)
			local m = getAccountEXPBoostValue( acc, "multiplier" ) or 1
			if not isGuestAccount(acc) and m then
				local addedExp = math.random(200,300) * m
				setElementData(killer,"experience", (getElementData(killer,"experience") or 0) + addedExp)
			end
			
			if getElementData(killer,"humanity") < 0 then
				setElementData(killer,"bandit",true)
			end
			if getElementData(source,"bandit") == true then
				setElementData(killer,"banditskilled", (getElementData(killer,"banditskilled") or 0) +1)
			end
			if bodypart == 9 then
				setElementData(killer,"headshots", (getElementData(killer,"headshots") or 0) +1)
			end
			local xX,yY,zZ = getElementPosition(source)
			local xk,yk,zk = getElementPosition(killer)
			local Distancia = getDistanceBetweenPoints3D(xX,yY,zZ,xk,yk,zk)
			--outputChatBox("@Distancia: "..tostring(Distancia))
			outputChatBox("[INFO]#FFFFFF Você matou: #32FF32"..getPlayerName(source):gsub('#%x%x%x%x%x%x','').."#FFFFFF || Arma: #32FF32"..(weapon or "Unknown").."#FFFFFF || Distância: #32FF32"..tostring(math.floor(Distancia)).."m #FFFFFF || Exp: #32FF32"..addedExp.." ".. (tostring(m).."x"),killer,0,128,255,true)
			outputChatBox("[INFO]#FFFFFF Você foi morto por: #32FF32"..getPlayerName(killer):gsub('#%x%x%x%x%x%x','').."#FFFFFF || Arma: #32FF32"..(weapon or "Unknown").."#FFFFFF || Distância: #32FF32"..tostring(math.floor(Distancia)).."m",source,0,128,255,true)
			--setTimer(function(source,killer)end,6000,1,source)
			triggerClientEvent("onRollMessageStart",getRootElement(),getPlayerName(source):gsub('#%x%x%x%x%x%x','').." foi morto por "..getPlayerName(killer):gsub('#%x%x%x%x%x%x',''),255,255,255, "died")
		else
			triggerClientEvent("onRollMessageStart",getRootElement(),getPlayerName(source):gsub('#%x%x%x%x%x%x','').." morreu.",255,255,255, "died")
		end
	end
)

function getAccountEXPBoostValue( acc, v )
	if isGuestAccount(acc) then return false end;
	
	local t = fromJSON(getAccountData( acc, "tempEXPBoostTS" ) or "")
	if (type(t) ~= "table") then return false end;
	if v == "timestamp" then
		return tonumber(t[1])
	elseif v == "multiplier" then
		return tonumber(t[2])
	end
	return false
end

Haven't tested so if you get errors, see what debugscript shows. 

Edited by DNL291
Link to comment
  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

9 hours ago, DNL291 said:

I understood. But it wasn't what I said. @AnnaBelle said in his/her previous post, that these chat messages should be shown only during weekend, not sure though.

@AnnaBelle show what debugscript (/debugscript 3) shows when you get bugs with the code.

Edit:

I don't understand why dividing 'experiences' with 'modifier' since the actual value isn't being that.

Also, modifier will still return number and not "x2" or "x3"

 
 

Yeah, the rate var would only return text during the weekend.

I'm dividing by the modifier because the actual experience value was already altered by the modifier so im returning the value that was altered.

The last code I gave still had an error because I forgot to use the rate var instead of modifier so it would have been be:

outputChatBox("[INFO]#FFFFFF Você matou: #32FF32"..getPlayerName(source):gsub('#%x%x%x%x%x%x','').."#FFFFFF || Arma: #32FF32"..(weapon or "Unknown").."#FFFFFF || Distância: #32FF32"..tostring(math.floor(Distancia)).."m #FFFFFF || Exp: #32FF32"..experiences/modifier.." "..rate,killer,0,128,255,true)

just to clear up what i did lol

Edited by Mr.Loki
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...