Jump to content
  • 0

Custom Dynamic Object - FootBall / SoocerBall


XFawkes

Question

Hello, I created a nice big ball for GTA in 3DS MAX. (ball.dff | ball.col | ball.txd) [i would like to script Football map]

It works in GTA, but I would like to make it dynamic (I would like to let it behave/bounce like a real ball)

When I replaced it with normal static object then it was only static, when I replaced it with dyn_quaryrock then it was moving, but I didn't like it. (dyn_quaryrock - is not a sphere and it was not rolling correctly). I was looking for other dynamic objects and I found beachball. When I replaced my ball with it, it was rolling correctly, but It makes me feel that the ball is too heavy (because of this type of dynamic, rolling very slow)

Is there any way to create my own dynamic script?

Link to comment

21 answers to this question

Recommended Posts

  • 0

It's probably possible to script, although I suspect not as simple as it might seem from the outset. GTA SA's physics engine is pretty basic, especially when it comes to interactions with dynamic objects. Vehicle-vehicle interactions are a bit better. As you would've seen yourself, something as simple as a ball doesn't really behave as a ball should. You may not be able to rely on the game's existing physics engine if you wanted a good outcome. Some of the scripting folks here could probably give you a pointer in the right direction, but given GTA SA's physics engine, realistic ball interaction may be a bit tricky to replicate.

Link to comment
  • 0

The mass of the beachball (1000kg apparently) is defined in objects.dat, but I don't think MTA has the ability to load server-side custom .dat files/content yet. I could be wrong on that though.

I don't know whether reducing the mass would really help a whole lot. It might reduce the tendency for vehicles to take damage or lose control when hitting it, but I certainly wouldn't expect it to bounce or behave any more like a real ball than it does currently.

Link to comment
  • 0

I did that once.. i even completed all the script, BUT because of bad syncronation it doesn't work...

(When a player moves the ball, the ball wont move on the screen for every player, it doesn't even look like the player is close to the ball)

Edited by Guest
Link to comment
  • 0

You can make a custom vehicle , like a ball and edit the handling of this vehicle in MTA 1.1

Replacing special objects like dynamic objects or explosive objects like the gaspump can kill easily the MTA Collision client.

Ye I agree the physics engine is pretty basic, I make a big door and replace the default dynamic door and my car go through the collision, but not my ped ...

Link to comment
  • 0
You can make a custom vehicle , like a ball and edit the handling of this vehicle in MTA 1.1

Replacing special objects like dynamic objects or explosive objects like the gaspump can kill easily the MTA Collision client.

Ye I agree the physics engine is pretty basic, I make a big door and replace the default dynamic door and my car go through the collision, but not my ped ...

It's impossible to make a ball with a vehicle, the collisions won't replace.

A way is using attachElements... it would be something like attach the ball to the player, then bind R for detach and give it to another random player (moveObject should be useful too), or spawn a marker attached to the ball, if the player touches the marker attached to the ball, the ball will be attached to the player.

Link to comment
  • 0

SERVER:

Code: (lua)

franceGol = createMarker ( 0, 0, 2.2164173126221, "cylinder", "7", 0, 255, 0, 255, getRootElement() ) 
espagneGol = createMarker ( 50, 50, 2.2164173126221, "cylinder", "7", 0, 255, 0, 255, getRootElement() ) 
balle = createObject ( 1305, 0, -10, 2.9733681678772) 
setElementID( franceGol, "franceGol" ) 
setElementID( espagneGol, "espagneGol" ) 
setElementID( balle, "balle" ) 
  
-- But 
addEvent( "onPlayerGoal", true ) 
function onPlayerGoal( equipe ) 
    ----------------- NE PAS TOUCHER ------------------------ 
    triggerClientEvent( "setGOAL", getRootElement() ) ------- 
    --------------------------------------------------------- 
    outputChatBox( equipe..": GOOOOOOOOOOOOOOOOL", getRootElement(), 255, 255, 0 ) 
    setTimer( playAgain, 4000, 1 ) 
end 
addEventHandler( "onPlayerGoal", getRootElement(), onPlayerGoal ) 
  
function playAgain() 
    ----------------- NE PAS TOUCHER ------------------------ 
    triggerClientEvent( "resetGOAL", getRootElement() ) ----- 
    --------------------------------------------------------- 
    -- ceci est un exemple, à toi de le modifier comme bon te semble 
    setElementPosition( balle, 0, -10, 2.9733681678772 ) 
end 
  

CLIENT:( à ne pas toucher )

Code: (lua) 
GOAL = 0 -- GOAL évite le flood 
function markerHIT() 
    local equipe 
    local balle = getElementByID( "balle" ) 
    local marker = getElementByID( "franceGol" ) 
    local marker2 = getElementByID( "espagneGol" ) 
    local bool = isElementWithinMarker( balle, marker ) 
    local bool2 = isElementWithinMarker( balle, marker2 ) 
    if bool then equipe = "france" elseif bool2 then equipe = "espagne" end 
    if ( (bool or bool2) and GOAL == 0)then 
        GOAL = 1 
        triggerServerEvent( "onPlayerGoal", getLocalPlayer(), equipe ) 
    end 
end 
setTimer( markerHIT, 500, 0 ) 
  
addEvent("resetGOAL", true ) 
function resetGOAL() 
    GOAL = 0 
end 
addEventHandler("resetGOAL", getRootElement(), resetGOAL ) 
  
addEvent("setGOAL", true ) 
function setGOAL() 
    GOAL = 1 
end 
addeventHandler("setGOAL", getRootElement(), setGOAL ) 

Link to comment
  • 0

Fatalterror, please try to talk english here, if you want to speak your native language then you can go to subforums, I didn't understand the comments of examples (I won't use Google Translator this time :)).

About the coding, well that just detects when someone did a goal, but how can the player handle the ball?

I guess should be something like this (not tested)

function createBall () 
ball = createObject ( 1097, 0, 0, 5 ) -- just an example the 1097 
ballMarker = createMarker ( 0, 0, 0, "cylinder", 0.5, 0, 0, 0, 0 ) -- set the alpha to 0, note that the size isn't the correct I guess 
attachElements ( ballMarker, ball ) -- attach the marker to the ball 
addEventHandler ( "onMarkerHit", ballMarker, handleBall ) 
end 
  
function handleBall(player) 
attachElements ( ball, player ) 
bindKey ( player, "O", "down", giveball ) 
end 
  
function giveball(player) 
randomp = getRandomPlayer() 
attachElements ( ball, randomp ) 
unbindKey ( player, "O", "down", giveball ) 
end 

This should give the ball to a random player, but well, it's not tested.

Link to comment
  • 0
SERVER:

Code: (lua)

franceGol = createMarker ( 0, 0, 2.2164173126221, "cylinder", "7", 0, 255, 0, 255, getRootElement() ) 
espagneGol = createMarker ( 50, 50, 2.2164173126221, "cylinder", "7", 0, 255, 0, 255, getRootElement() ) 
balle = createObject ( 1305, 0, -10, 2.9733681678772) 
setElementID( franceGol, "franceGol" ) 
setElementID( espagneGol, "espagneGol" ) 
setElementID( balle, "balle" ) 
  
-- But 
addEvent( "onPlayerGoal", true ) 
function onPlayerGoal( equipe ) 
    ----------------- NE PAS TOUCHER ------------------------ 
    triggerClientEvent( "setGOAL", getRootElement() ) ------- 
    --------------------------------------------------------- 
    outputChatBox( equipe..": GOOOOOOOOOOOOOOOOL", getRootElement(), 255, 255, 0 ) 
    setTimer( playAgain, 4000, 1 ) 
end 
addEventHandler( "onPlayerGoal", getRootElement(), onPlayerGoal ) 
  
function playAgain() 
    ----------------- NE PAS TOUCHER ------------------------ 
    triggerClientEvent( "resetGOAL", getRootElement() ) ----- 
    --------------------------------------------------------- 
    -- ceci est un exemple, à toi de le modifier comme bon te semble 
    setElementPosition( balle, 0, -10, 2.9733681678772 ) 
end 
  

CLIENT:( à ne pas toucher )

Code: (lua) 
GOAL = 0 -- GOAL évite le flood 
function markerHIT() 
    local equipe 
    local balle = getElementByID( "balle" ) 
    local marker = getElementByID( "franceGol" ) 
    local marker2 = getElementByID( "espagneGol" ) 
    local bool = isElementWithinMarker( balle, marker ) 
    local bool2 = isElementWithinMarker( balle, marker2 ) 
    if bool then equipe = "france" elseif bool2 then equipe = "espagne" end 
    if ( (bool or bool2) and GOAL == 0)then 
        GOAL = 1 
        triggerServerEvent( "onPlayerGoal", getLocalPlayer(), equipe ) 
    end 
end 
setTimer( markerHIT, 500, 0 ) 
  
addEvent("resetGOAL", true ) 
function resetGOAL() 
    GOAL = 0 
end 
addEventHandler("resetGOAL", getRootElement(), resetGOAL ) 
  
addEvent("setGOAL", true ) 
function setGOAL() 
    GOAL = 1 
end 
addeventHandler("setGOAL", getRootElement(), setGOAL ) 

"Unfortunately this idea won't work since the ball isn't synchronized between players. It will end up in a different place on everyone's screen."

written by a super moderator long ago, but its still the same. It doesn't work.

Link to comment
  • 0
@ diegofkda

onMarkerHit event dont work with attached markers

Ooops :):) so, actualize the marker every 50 ms

# function createBall () 
 ball = createObject ( 1097, 0, 0, 5 ) -- just an example the 1097 
 ballMarker = createMarker ( 0, 0, 0, "cylinder", 0.5, 0, 0, 0, 0 ) -- set the alpha to 0, note that the size isn't the correct I guess 
 setTimer ( 
   function () 
    local x, y, z = getElementPosition ( ball ) 
    setElementPosition ( ball, x, y, z ) 
   end, 50, 0 ) 
 addEventHandler ( "onMarkerHit", ballMarker, handleBall ) 
 end 
   
 function handleBall(player) 
 attachElements ( ball, player ) 
 bindKey ( player, "O", "down", giveball ) 
 end 
   
 function giveball(player) 
 randomp = getRandomPlayer() 
 attachElements ( ball, randomp ) 
 unbindKey ( player, "O", "down", giveball ) 
 end 

Link to comment
  • 0

Ehemmm... so

function createBall () 
  ball = createObject ( 1097, 0, 0, 5 ) -- just an example the 1097 
  ballMarker = createMarker ( 0, 0, 0, "cylinder", 0.5, 0, 0, 0, 0 ) -- set the alpha to 0, note that the size isn't the correct I guess 
  setTimer ( 
    function () 
     local x, y, z = getElementPosition ( ball ) 
     setElementPosition ( ballMarker, x, y, z ) 
    end, 50, 0 ) 
  addEventHandler ( "onMarkerHit", ballMarker, handleBall ) 
  end 
   
  function handleBall(player) 
  attachElements ( ball, player ) 
 bindKey ( player, "O", "down", giveball ) 
  end 
  
  function giveball(player) 
  randomp = getRandomPlayer() 
  setElementFrozen ( randomp ) 
  local x, y, z = getElementPosition ( randomp ) 
  moveObject ( ball, 500, x, y, z ) 
  setTimer ( function () 
  attachElements ( ball, randomp ) end, 600, 1 ) 
  unbindKey ( player, "O", "down", giveball ) 
  end 

Hey check that, its a good idea

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