MaTrix2 Posted August 22, 2017 Share Posted August 22, 2017 function OutputChatbox(thePlayer) outputChatBox ("Kill "..getPlayerName(thePlayer).." to get 2500 Tokens!") end addCommandHandler ("bounty",OutputChatbox) I run an MTA dayz server and wrote a bounty script which has a bounty on a player who has a certain humanity ... my problem is only that I would like to send a message to the server as soon as a player gets a bounty .. Is there a possibility to write this code so that this message is sent as soon as a player bounty gets? P.S sorry for my bad english Link to comment
Ben_Sherman Posted August 22, 2017 Share Posted August 22, 2017 (edited) Is the bounty automatically done or done via a command? From the looks of things you've only made it so that when ever you write the command it outputs the text, however, there is no extra data behind it in which you'd determine if the player has a bounty or not Edited August 22, 2017 by Ben_Sherman Link to comment
MaTrix2 Posted August 23, 2017 Author Share Posted August 23, 2017 the bounty is automatically done... and thats my problem with this massage... the bounty works via humanity like.. u have 2500 humanity and after killing someone like 1300 or something and with -6000 humanity u get this bounty... and i want that this massage pops up if someone reach -6000 humanity Link to comment
Malone. Posted August 23, 2017 Share Posted August 23, 2017 (edited) function OutputChatbox(thePlayer) outputChatBox ("Kill "..getPlayerName(thePlayer).." to get 2500 Tokens!") end addCommandHandler ("bounty", OutputChatbox) try this if it's won't work notice me. Edited August 23, 2017 by Malone. Link to comment
Administrators Lpsd Posted August 23, 2017 Administrators Share Posted August 23, 2017 (edited) 51 minutes ago, Malone. said: function OutputChatbox(thePlayer) outputChatBox ("Kill "..getPlayerName(thePlayer).." to get 2500 Tokens!") end addCommandHandler ("bounty", OutputChatbox) try this if it's won't work notice me. What? You added a space between the arguments to addCommandHandler... that won't change anything. Anyway, what the OP is trying to explain is that he already has a 'bounty' system and he wants to create a chatbox message when someone reaches 'x' score on the bounty script. @MaTrix2 you'll need to edit the bounty script, search through the code and find where a bounty is set on a player. Here you'll be able to add the outputChatBox line. If you need any further help then you should post some code from your bounty script, at the part where a bounty is set on a player. Edited August 23, 2017 by LopSided_ Link to comment
Mr.Loki Posted August 23, 2017 Share Posted August 23, 2017 This isn't tested but I think it should work if you are using the default Dayz event names. If not just change it to match your gamemode. This code does not need to go directly into the Dayz gamemode so just create a new resource with it. I explained every step so it should be easy to follow along and understand what's happening. This is SERVER sided. Been a while since I made anything for Dayz so don't kill me if it doesn't work. Not saying that you SHOULD use this code just giving you an idea of how I'd do it. function manageBounty( ) -- Create a table with all the players in the server. local plrs = getElementsByType "player" -- Go through each player in the table. for i=1,#plrs do local p=plrs[i] local logedin = getPlayerAccount( p ) -- Check if player is loged in.(No need to check guest acc because dayz...) if logedin then local hasBounty = getElementData( p, "Bounty" ) local humanity = getElementData( p, "humanity" ) -- If the player's humanity is less than or equals -6000 and does not have a bointy on his head give him 1 then announce it to the server. if not hasBounty and humanity <= -6000 then setElementData(p, "Bounty", true) outputChatBox ("Kill "..getPlayerName(p).." to get 2500 Tokens!") end end end end -- execute the manageBounty function every 7 seconds.(Do not go lower than 2 seconds.) setTimer( manageBounty, 7000, 0) function rewardBounty( killer,headshot,weapon ) -- Check if "killer" is a player. if killer and type(killer) == "player" then local hasBounty = getElementData( source, "Bounty" ) -- Check if player who died had a bounty. if hasBounty then --Your code here to reward "killer" with tokens! -- Send a message to the server that someone has collected the bounty. outputChatBox (getPlayerName(killer).." collected the bounty on "..getPlayerName(source).."'s head.") -- Remove the bounty from the dead player. setElementData(source, "Bounty", false) end end end addEventHandler("kilLDayZPlayer",root,rewardBounty) -- Command to list all the players that have a bounty and the current humanity. addCommandHandler( "bounty", function( plr ) local plrs = getElementsByType "player" for i=1,#plrs do local p=plrs[i] if getElementData(p, "Bounty") then outputChatBox( getPlayerName(p).." #ffffffHumanity:"..getElementData(p, "humanity"), plr, 255, 255, 255, true ) end end end ) Link to comment
Manticore Posted August 23, 2017 Share Posted August 23, 2017 1 hour ago, Mr.Loki said: This isn't tested but I think it should work if you are using the default Dayz event names. If not just change it to match your gamemode. This code does not need to go directly into the Dayz gamemode so just create a new resource with it. I explained every step so it should be easy to follow along and understand what's happening. This is SERVER sided. Been a while since I made anything for Dayz so don't kill me if it doesn't work. Not saying that you SHOULD use this code just giving you an idea of how I'd do it. function manageBounty( ) -- Create a table with all the players in the server. local plrs = getElementsByType "player" -- Go through each player in the table. for i=1,#plrs do local p=plrs[i] local logedin = getPlayerAccount( p ) -- Check if player is loged in.(No need to check guest acc because dayz...) if logedin then local hasBounty = getElementData( p, "Bounty" ) local humanity = getElementData( p, "humanity" ) -- If the player's humanity is less than or equals -6000 and does not have a bointy on his head give him 1 then announce it to the server. if not hasBounty and humanity <= -6000 then setElementData(p, "Bounty", true) outputChatBox ("Kill "..getPlayerName(p).." to get 2500 Tokens!") end end end end -- execute the manageBounty function every 7 seconds.(Do not go lower than 2 seconds.) setTimer( manageBounty, 7000, 0) function rewardBounty( killer,headshot,weapon ) -- Check if "killer" is a player. if killer and type(killer) == "player" then local hasBounty = getElementData( source, "Bounty" ) -- Check if player who died had a bounty. if hasBounty then --Your code here to reward "killer" with tokens! -- Send a message to the server that someone has collected the bounty. outputChatBox (getPlayerName(killer).." collected the bounty on "..getPlayerName(source).."'s head.") -- Remove the bounty from the dead player. setElementData(source, "Bounty", false) end end end addEventHandler("kilLDayZPlayer",root,rewardBounty) -- Command to list all the players that have a bounty and the current humanity. addCommandHandler( "bounty", function( plr ) local plrs = getElementsByType "player" for i=1,#plrs do local p=plrs[i] if getElementData(p, "Bounty") then outputChatBox( getPlayerName(p).." #ffffffHumanity:"..getElementData(p, "humanity"), plr, 255, 255, 255, true ) end end end ) That's wrong one. Link to comment
Mr.Loki Posted August 23, 2017 Share Posted August 23, 2017 (edited) @Mohamed Asad What's wrong? I think you are going to have to be more specific about this.. Edited August 23, 2017 by Mr.Loki Link to comment
Manticore Posted August 23, 2017 Share Posted August 23, 2017 ERROR: Bounty\Server.lua:14: attempt to compare boolean with number Link to comment
Administrators Lpsd Posted August 23, 2017 Administrators Share Posted August 23, 2017 8 minutes ago, Mohamed Asad said: ERROR: Bounty\Server.lua:14: attempt to compare boolean with number For a start you're quoting the wrong line number from the code example, you mean line 17 Secondly, are you using default dayz resource? Link to comment
Manticore Posted August 23, 2017 Share Posted August 23, 2017 Actually, I don't using Dayz resource. Link to comment
Mr.Loki Posted August 23, 2017 Share Posted August 23, 2017 5 minutes ago, Mohamed Asad said: Actually, I don't using Dayz resource. This is for dayz... please read the topic carefully Link to comment
Manticore Posted August 23, 2017 Share Posted August 23, 2017 Oh, I'm wrong. I'm so sorry. Link to comment
Mr.Loki Posted August 23, 2017 Share Posted August 23, 2017 10 minutes ago, Mohamed Asad said: Oh, I'm wrong. I'm so sorry. It's fine i'll pm you. 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