Jump to content

Help with distance.


Mrzeerox

Recommended Posts

Anyone can make me script, if player is around 100m from me, then he cant shoot?

function giveblood ( thePlayer )
	if isObjectInACLGroup ( "user." ..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup ( "Admin") ) then
		if not getElementData(thePlayer, "OnDuty") then    
        	outputChatBox ("#1AFF00 Admin "..getPlayerName(thePlayer).."#1AFF00 IS NOW - ON DUTY",root,0,0,255,true)
    		setElementData(thePlayer, "blood",999999999)
    		setElementData(thePlayer, "food",95)
    		setElementData(thePlayer, "thirst",95)
    		setElementData(thePlayer, "temperature",36.5)
    		setElementData(thePlayer, "currentweapon_1",false)
    		setElementData(thePlayer, "currentweapon_2",false)
    		setElementData(thePlayer, "currentweapon_3",false)
    		setElementData(thePlayer, "bleeding",false)
    		setElementData(thePlayer, "brokenbone",false)
    		setElementData(thePlayer, "pain",false)
    		setElementData(thePlayer, "cold",false)
    		setElementData(thePlayer, "bandit",false)
    		setElementData(thePlayer, "humanity",2500)
    		setElementData(thePlayer, "skin",210)
			setElementData(thePlayer, "OnDuty",true)
		end
	end
end
addCommandHandler("duty", giveblood)

function bloodback(thePlayer)
	local account = getAccountName ( getPlayerAccount ( thePlayer ) )
	if isObjectInACLGroup("user." .. account, aclGetGroup("Admin,Moderator,Owner")) then
 
	end
	outputChatBox ("#FF0000 Admin "..getPlayerName(thePlayer).."#FF0000 IS NOW - OFF DUTY",root,255,255,255,true)
	setElementData(thePlayer, "blood",12000)
	setElementData(thePlayer, "OnDuty",false)
end
addCommandHandler("offduty", bloodback)

 

Link to comment

Please try to explain better your problem/request

EDIT : Not tested (Client-Sided script)

function playerOnDamage( attacker, weapon, bodyPart, loss )
  if ( getElementType( attacker ) == "player" ) then
    local pX, pY, pZ = getElementPosition( source )
    local aX, aY, aZ = getElementPosition( attacker )
    local distance = getDistanceBetweenPoints3D( pX, pY, pZ, aX, aY, aZ )
    if ( distance < 50 ) then
      cancelEvent( )
    end 
  end 
end
addEventHandler( "onClientPlayerDamage", getRootElement( ), playerOnDamage )

 

Edited by *BeaT*
Understood the request
Link to comment

Server

function giveBlood( playerSource, inputCommand )
	if ( isObjectInACLGroup ( "user." ..getAccountName( getPlayerAccount( thePlayer ) ), aclGetGroup ( "Admin") ) ) then
		if ( getElementData( playerSource, "OnDuty" ) == true ) then 
			outputChatBox( "You are already On-Duty!", playerSource, 255, 0, 0 )
		else 
			setElementData( playerSource, "OnDuty", true )
			setElementData( playerSource, "food", 95, true )
			setElementData( playerSource, "thirst", 95, true )
			setElementData( playerSource, "temperature", 36.5, true )
			setElementData( playerSource, "currentweapon_1", false, true )
			setElementData( playerSource, "currentweapon_2", false, true )
			setElementData( playerSource, "currentweapon_3", false, true )
			setElementData( playerSource, "bleeding", false, true )
			setElementData( playerSource, "brokenbone", false, true )
			setElementData( playerSource, "pain", false, true )
			setElementData( playerSource, "cold", false, true )
			setElementData( playerSource, "bandit", false, true )
			setElementData( playerSource, "humanity", 2500, true )
			setElementData( playerSource, "skin", 210, true )
		end 
	else 
		
	end 
end
addCommandHandler( "duty", giveBlood )

function bloodBack( playerSource, inputCommand )
	if ( isObjectInACLGroup ( "user." ..getAccountName( getPlayerAccount( playerSource ) ), aclGetGroup ( "Admin") ) ) then
		setElementData( playerSource, "blood", 12000, true )
		setElementData( playerSource, "OnDuty", false, true )
	else 
		--output something
	end 
end 
addCommandHandler( "offduty", bloodBack )

 

Client

function playerOnDamage( attacker, weapon, bodyPart, loss )
  if ( getElementType( attacker ) == "player" and getElementData( source, "OnDuty" ) == true ) then
    local pX, pY, pZ = getElementPosition( source )
    local aX, aY, aZ = getElementPosition( attacker )
    local distance = getDistanceBetweenPoints3D( pX, pY, pZ, aX, aY, aZ )
    if ( distance < 50 ) then -- change the distance if you need
      cancelEvent( )
    end 
  end 
end
addEventHandler( "onClientPlayerDamage", getRootElement( ), playerOnDamage )

 

Not tested!

Edited by *BeaT*
Code mistake
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...