Jump to content

[HELP-ME] Patent / level


AnnaBelle

Recommended Posts

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

oops made an error use this instead

local rate = modifier == 2 and "x2" or modifier == 3 and "x3" or ""
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.." "..modifier,killer,0,128,255,true)

 

Link to comment
  • Moderators
19 minutes ago, Mr.Loki said:

@DNL291 the rate var is using the day modifier var so if the modifier is 1 the text will be empty if the modifier is 2 the text will be 2x etc...

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:

11 minutes ago, Mr.Loki said:

oops made an error use this instead


local rate = modifier == 2 and "x2" or modifier == 3 and "x3" or ""
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.." "..modifier,killer,0,128,255,true)

 

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"

Edited by DNL291
Link to comment
  • Moderators

Try this:

		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 modifier = 1
			local day = getRealTime().weekday
			if day == 0 then 
				modifier = 3
			elseif day == 6 then -- 0 = sun 6 = sat
				modifier = 2
			end
			local experiences = math.random(200,300)*modifier
			setElementData(killer,"experience", (getElementData(killer,"experience") or 0) + experiences)
			
			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 headshot == true 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))
			if day == 0 or day == 6 then	
				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"..tostring(experiences).." ".. (tostring(modifier).."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)
			end
			--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

Show what debugscript says you if you have any errors.

Edited by DNL291
Link to comment
  • Moderators

I can't understand what you mean...

What week system do you mean? Or you're setting 'day' to another day just to test it? It will depend on what 'day' variable returns, it should return 0 or 6 in order to messages be shown.

BTW, this system isn't ideal since players can change their computer's date and it will give x3 XP even if it isn't weekend.

Edited by DNL291
Link to comment
  • Moderators
29 minutes ago, AnnaBelle said:

But let's say it can end up happening, what should I do?

Nevermind about computer's time, it'll be the current Server time since that script is server-side..

 

29 minutes ago, AnnaBelle said:

You know how I can ta making a button to buy experience in double or triple

Just create a function attached to the buttons and in the function parameter, checks if it's x2 or 3 then use setElementData( player, "experience", expvalue * mult). Thats the basic ofc.

Link to comment

Let's say that this is a shooting game, and the store has the option for the player to buy
3x experience and 2x experience for 1 day.
How can I ta doing this for a button on a shop panel.

addEvent("addVIP",true)
addEventHandler("addVIP",getRootElement(),function(source)
    local account = getPlayerAccount(source)
    local accName = getAccountName(account)
    aclGroupAddObject(aclGetGroup("VIP"),"user."..accName)
    local currentDate = getRealTime().timestamp
	setAccountData(account,"VIPPurchaseDate",currentDate)
	outputChatBox("#FF0000[ARENA]#FFFFFFType '#01DF01/checktime#FFFFFF', to check the time of vip.", thePlayer,46,255,46,true)
end)

function checkPlayersVIP()
	local plrs = getElementsByType"player"
	for i=1,#plrs do
	local account = getPlayerAccount(plrs[i])
	local purchaseDate = getAccountData(account,"VIPPurchaseDate")
		if purchaseDate then
		local currentDate = getRealTime().timestamp
			if currentDate - purchaseDate >= 3600*24 then
				aclGroupRemoveObject(aclGetGroup("VIP"),"user."..getAccountName(account))
				outputChatBox("#FF0000[ARENA]#FFFFFFYour VIP has expired.",plrs[i],255,100,100,true)
				setAccountData(account,"VIPPurchaseDate",false)
			end
		end
	end
end
setTimer(checkPlayersVIP,10*60*1000,0)
addEventHandler("onPlayerLogin",getRootElement(),checkPlayersVIP)

addCommandHandler("checktime", function(thePlayer)
	local purchaseDate = getAccountData(getPlayerAccount(thePlayer), "VIPPurchaseDate")
	if purchaseDate then
		local realTime = getRealTime().timestamp
		local remainingTime = purchaseDate + 86400 - realTime
		local minutesLeft = remainingTime/60
		local hoursLeft = minutesLeft/60
		outputChatBox("#FF0000[ARENA]#FFFFFFYour VIP expires in #32FF32"..string.format("%02d",math.floor(hoursLeft)).."#FFFFFF:#32FF32"..string.format("%02d",math.floor(minutesLeft)%60),thePlayer,46,255,46,true)
	else
		outputChatBox("#FF0000[ARENA]#FFFFFFYou did not buy VIP.", thePlayer,46,255,46,true)
	end
end)

Like this example with VIP

Link to comment
  • Moderators

Use getRealTime().timestamp and store the value in player's account after he bought it. And you can set a timer to check when it's finished.

You can calculate the Timestamp which the 2x/3x xp will expire by using the Timestamp stored with setAccountData + 86400 (which is one day in seconds).

Link to comment
addEvent("onRequestXP",true)
addEventHandler("onRequestXP",root,function( m )
	setElementData( source,"experience",expvalue * m ) -- I did not understand how to use this function.
	local currentDate = getRealTime().timestamp
	setAccountData(account,"DUPXP",currentDate)
end)

addEventHandler("onPlayerLogin",getRootElement(),function()
	local xpDup = getElementsByType"player"
	for i=1,#xpDup do
	local account = getPlayerAccount(xpDup[i])
	local purchaseDate = getAccountData(account,"DUPXP")
		if purchaseDate then
		local currentDate = getRealTime().timestamp
			if currentDate - purchaseDate >= 3600*24 then
				setAccountData(account,"DUPXP",false)
			end
		end
	end
end)

I think it should be like this. I do not know.

Link to comment
  • Moderators

Try this:


addEvent("onRequestXP",true)
addEventHandler("onRequestXP",root,function( m )
	setElementData( source,"experience",expvalue * m )
	local acc = getPlayerAccount(source)
	if isGuestAccount ( acc ) ~= true then
		setAccountData( acc, "tempEXPBoostTS", tostring(getRealTime().timestamp) )
	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 = tonumber( (getAccountData( acc, "tempEXPBoostTS") or 0) )
				if eTimestamp ~= 0 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 = tonumber( (getAccountData( acc, "tempEXPBoostTS") or 0) )
			if eTimestamp ~= 0 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 = tonumber( (getAccountData( acc, "tempEXPBoostTS") or 0) )
		if eTimestamp ~= 0 and (getRealTime().timestamp - eTimestamp) > 86400 then
			outputChatBox("Your exp boost has expired", source)
			setAccountData( acc, "tempEXPBoostTS", nil )
		end
end)

-- Make sure the player has enough money (do it client side)
-- 'expvalue' : The default xp given
-- You call it this way: triggerServerEvent( "onRequestXP", localPlayer, 2)
-- 2: 2x and 3: 3x
-- * You don't need to modify 'm'

I haven't tested that code.

Read the comments that are in the code so you can understand some things.

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