Mr.Loki Posted April 15, 2017 Share Posted April 15, 2017 @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... Link to comment
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 I'm testing here, a moment. Link to comment
Mr.Loki Posted April 15, 2017 Share Posted April 15, 2017 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
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 (edited) 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 April 15, 2017 by DNL291 Link to comment
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 (edited) He's not even giving a bug now, but he's only calling 2 and not 2x [INFO] Você matou: 7Theroii || Arma: Sniper || Distância: 2m || Exp: 300 2 Edited April 15, 2017 by AnnaBelle Link to comment
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 (edited) 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 April 15, 2017 by DNL291 Link to comment
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 (edited) thank you Edited April 15, 2017 by AnnaBelle Link to comment
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 (edited) 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 April 15, 2017 by DNL291 Link to comment
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 But I tested it on vps and I could not get the xp of the weekend caught during the week But let's say it can end up happening, what should I do? You know how I can ta making a button to buy experience in double or triple Link to comment
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 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
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 addEvent("2x",true) addEventHandler("2x",getRootElement(),function(source) setElementData(source,"experience",expvalue*mult) end) It would be like this? Link to comment
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 You should use mult as parameter instead. Like this: addEvent("onRequestXP",true) addEventHandler("onRequestXP",root,function( m ) setElementData( source,"experience",expvalue * m ) end) Link to comment
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 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
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 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
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 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
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 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
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 [2017-04-15 04:30:10] ERROR: [addon]\HMT-Arena\server.lua:419: attempt to perform arithmetic on global 'expvalue' (a nil value) It looks like he is not reading this function setElementData( source,"experience",expvalue * m ) Link to comment
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 Like I said, you need to replace it with the default value of XP you will get. Link to comment
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 I made the change, but xp is coming the same thing Link to comment
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 Replace: setElementData( source,"experience",expvalue * m ) With: setElementData( source, "experience", (getElementData( source,"experience" ) or 0) + (expvalue * m) ) Link to comment
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 I understand, every time you buy, you get exp, but it should be every time you kill a player you win but exp I think I should add the exp. Example: you won 254 per kill a thief + item that gives more exp Link to comment
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 So buying 2x XP will increase the experience you get when you kill a player? If so, you can use getAccountData to check if player has it stored when he kills other players. Link to comment
DNL291 Posted April 15, 2017 Share Posted April 15, 2017 ? 5 minutes ago, DNL291 said: So buying 2x XP will increase the experience you get when you kill a player? Is that what you want? Link to comment
AnnaBelle Posted April 15, 2017 Author Share Posted April 15, 2017 yes sorry my English is very bad 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