MrKAREEM

[Help] Car Ball Testing

Recommended Posts

Hello Guis I Want Make Carball Testing :D

o.O So What The Codes That I Need?

I Whish Any one Help Me -_-

Share this post


Link to post
9 minutes ago, DABL said:

?????????????????????????????

Car Ball dont is to use Garage Car balls ?

Share this post


Link to post
On ١٧‏/٢‏/٢٠١٨ at 02:31, raynner said:

Car Ball dont is to use Garage Car balls ?

As Neon carball? :lol::lol::lol::lol:

Share this post


Link to post
On ١٧‏/٢‏/٢٠١٨ at 02:31, raynner said:

Car Ball dont is to use Garage Car balls ?

I Want Know How To Move The Ball When The Ped Hit it With The Car Do You Know ?

Share this post


Link to post
6 hours ago, MrKAREEM said:

I Want Know How To Move The Ball When The Ped Hit it With The Car Do You Know ?

The ball isn't an object, it's a vehicle with a spherical shape and custom .col file.

  • Like 1

Share this post


Link to post

i have an problem when i shoot the ball

it fall down and didnot bumb on ground

any help pls

Edited by Dutchman101
removed useless nickmentions

Share this post


Link to post
20 hours ago, MisterQuestions said:

Learn some maths and create your own physics, detect once it hits ground then apply force to make it bounce.

any example pls ??

  • Haha 1

Share this post


Link to post

ok whats problem here or how let it falls ??

-- client --

addEvent("onCarballPosUpdate", true)
addEvent("onClientVehicleCollision", true)

local hit_ball = function(hitElement, force)
	if(isPedInVehicle(localPlayer)) then
		setVehicleDamageProof(getPedOccupiedVehicle(localPlayer), true)
	end
	if(hitElement) and (getElementDimension(hitElement) == getElementDimension(localPlayer)) then
		if(isBall(hitElement)) then
			local x, y, z = getElementPosition(hitElement)
			local throw = false
			local s = playSound3D("kick.mp3", x, y, z, false)
			setElementDimension(s, getElementDimension(hitElement))
			setSoundMaxDistance(s, 100)
			setSoundVolume(s, 0.5)
			x, y, z = getElementVelocity(hitElement)
			if(force > 500) then
				throw = true
			end
			if(force > 100) then
				force = 100
				
			end
			local nx, ny, nz = x*(force/30), y*(force/30), z+((force/300)*1.01)
			if(source == getPedOccupiedVehicle(localPlayer)) then
				x, y, z = getElementPosition(hitElement)
				triggerServerEvent("onCarballBallUpdate", localPlayer, hitElement, x, y, z, nx, ny, nz)
				
				if(throw == true) then
				end
			end
			setElementVelocity(hitElement, nx, ny, nz)
		end
	end
end
addEventHandler("onClientVehicleCollision", getRootElement(), hit_ball)

isBall = function(ball)
	return getElementData(ball, "ball")
end

local sync_ball = function(last_syncher, ball, x, y, z, x2, y2, z2)
	if(last_syncher ~= localPlayer) then
setElementPosition(ball, x, y, z)
setElementVelocity(ball, x2, y2, z2)
end
end
addEventHandler("onCarballPosUpdate", getRootElement(), sync_ball)

 

-- server --

Ball = {}

addCommandHandler('ball',
function(player)
if isElement(Ball[player]) then return outputChatBox('u have one', source) end
local x,y,z = getElementPosition(player)
Ball[player] = createObject(2912, x + 3, y, z)
outputChatBox('done', player)
setElementData(Ball[player], 'ball', true)
end)

addEvent('onCarballBallUpdate',true)
local carball_update = function(ball, x, y, z, x2, y2, z2)
triggerClientEvent("onCarballPosUpdate", getRootElement(), source, ball, x, y, z, x2, y2, z2)
end
addEventHandler("onCarballBallUpdate", getRootElement(), carball_update)

 

any one help me resource 97% completely :| 

Share this post


Link to post
7 hours ago, MisterQuestions said:

I don't think that will even set a direction to ball

how to get that ??

and how to apply physics to ball or object ??

if there was functions or what give me pls ??

and i want learn can some one help me ??

or give me code and help me pls

Share this post


Link to post
17 hours ago, MisterQuestions said:

I did the same mistake as you time ago.



 

  1. -- "ball" is the ball element
  2. -- "vehicle" is the vehicle element that collided with the ball
  3.  
  4. local x, y, z = getElementPosition(ball)
  5. local x2, y2, z2 = getElementPosition(vehicle)
  6. local velX, velY, velZ = getElementVelocity(vehicle)
  7. local vel = math.sqrt(velX*velX + velY*velY + velZ*velZ) -- equal to getDistanceBetweenPoints3D(0, 0, 0, velX, velY, velZ)
  8.  
  9. local dirX, dirY, dirZ = x - x2, y - y2, z - z2
  10. local dist = math.sqrt(dirX*dirX + dirY*dirY + dirZ*dirZ) -- equal to getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
  11. dirX, dirY, dirZ = dirX / dist, dirY / dist, dirZ / dist
  12.  
  13. -- To change velocity of the ball now, i guess you might want to do:
  14. -- setElementVelocity(ball, dirX * vel, dirY * vel, dirZ * vel)

thats work ??

  • Sad 1

Share this post


Link to post

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.