Jump to content

im new


MaTrix2

Recommended Posts

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 :D

Link to comment

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

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
  • Administrators
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 by LopSided_
Link to comment

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
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
  • Administrators
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

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