Jump to content

cancelEvent in client


Recommended Posts

Spoiler

function block(source)
dano = 1
setTimer(unblock,8000,1,source)
end
addEventHandler ( "onClientPlayerDamage", root, block )

function unblock(source)
dano = 0
end


function clientPickupHit(thePlayer,pickup, matchingDimension)
	local pickupType = getPickupType( source )
if (dano == 1) then
	if (pickupType == 0) or (pickupType == 1) then      
		outputChatBox("Não é possivel pegar pickup em combate!",source, 255, 0, 0)
		cancelEvent()
end
end
end
addEventHandler("onClientPickupHit", root, clientPickupHit)

 

this script should work: when the player receives damage, stay blocked from picking up pickups for 8 seconds, after that, it is possible.

however, after the player takes damage and receives "dano = 1", it is still possible to get the pickup as if the cancelEvent () was not there.

it only works on the  severside, changing events to the server, but it block all players pickups...

what's wrong?

Edited by '~DaLesTe^'
code error, invalid function name, fixed**
Link to comment
  • Moderators
3 hours ago, '~DaLesTe^' said:

what's wrong?

Wiki doesn't indicates that the client version of the event can be cancelled.

https://wiki.multitheftauto.com/wiki/OnClientPickupHit

 

While on serverside there is an indication:

Cancel effect

If this event is canceled, the pickup does not disappear and the player does not receive its bonus.

https://wiki.multitheftauto.com/wiki/OnPickupHit

 


 

So you will have to create it on serverside.

 

dano = {}

 

local player = source -- ...


dano[player] = true -- block


dano[player] = nil -- unblock / clear

 

if dano[player] then
  
  
end

 

 

 

 

Link to comment

code 

dano = {}
local player = source

function bloquear(source)
dano[player] = 1
setTimer(tirar,8000,1,source)
end
addEventHandler ( "onPlayerDamage", root, bloquear )

function tirar(source)
dano[player] = 0
end


function clientPickupHit(thePlayer,pickup, matchingDimension)
	local pickupType = getPickupType( source )
if (dano[player] == 1) then
	if (pickupType == 0) or (pickupType == 1) then      
outputChatBox("Não é possivel pegar pickup em combate!",player, 255, 0, 0)
		cancelEvent()
end
end
end
addEventHandler("onPickupHit", root, clientPickupHit)

error: table index is nil

thx for help, i finished.

Edited by '~DaLesTe^'
Link to comment
  • Moderators
	dano = {}
   

	function bloquear(source)
		dano[source] = 1
		setTimer(tirar,8000,1,source)
	end
	addEventHandler ( "onPlayerDamage", root, bloquear )

	function tirar(source)
		dano[source] = 0
	end

	function clientPickupHit(thePlayer,pickup, matchingDimension)
		local pickupType = getPickupType( source )
		if (dano[player] == 1) then
			if (pickupType == 0) or (pickupType == 1) then      
				outputChatBox("Não é possivel pegar pickup em combate!",player, 255, 0, 0)
				cancelEvent()
			end
		end
	end
	addEventHandler("onPickupHit", root, clientPickupHit)

 

7 hours ago, '~DaLesTe^' said:

thx for help, i finished.

 

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