Jump to content

onMarkerHit Problem


scolen

Recommended Posts

14 minutes ago, scolen said:

How do you try not to hit the marker when a player is in a vehicle ?

local marker = -- The marker element you want to prevent the player from hitting

function onVehicleCollision(hitElement)
    if hitElement == localPlayer and getElementType(hitElement) == "vehicle" then
        -- Check if the player is in a vehicle
        if isElementWithinMarker(hitElement, marker) then
            -- Player is in a vehicle and colliding with the marker
            -- Do something here (e.g., display a message, play a sound, etc.)
            
            -- To prevent the collision, you can remove the vehicle's speed
            local vehicle = getPedOccupiedVehicle(hitElement)
            setElementVelocity(vehicle, 0, 0, 0)
        end
    end
end
addEventHandler("onClientVehicleCollision", root, onVehicleCollision)

https://wiki.multitheftauto.com/wiki/OnClientVehicleCollision

  • Thanks 1
Link to comment
56 minutes ago, Shady1 said:
local marker = -- The marker element you want to prevent the player from hitting

function onVehicleCollision(hitElement)
    if hitElement == localPlayer and getElementType(hitElement) == "vehicle" then
        -- Check if the player is in a vehicle
        if isElementWithinMarker(hitElement, marker) then
            -- Player is in a vehicle and colliding with the marker
            -- Do something here (e.g., display a message, play a sound, etc.)
            
            -- To prevent the collision, you can remove the vehicle's speed
            local vehicle = getPedOccupiedVehicle(hitElement)
            setElementVelocity(vehicle, 0, 0, 0)
        end
    end
end
addEventHandler("onClientVehicleCollision", root, onVehicleCollision)

https://wiki.multitheftauto.com/wiki/OnClientVehicleCollision

How to do it on the server side?

Link to comment
16 minutes ago, scolen said:

How to do it on the server side?

local marker = -- The marker element you want to prevent the player from hitting

function onVehicleCollision(hitElement, force, bodyPart, collisionX, collisionY, collisionZ, normalX, normalY, normalZ, material1, material2)
    if getElementType(hitElement) == "vehicle" then
        -- Check if the player is in a vehicle
        local player = getVehicleOccupant(hitElement)
        if player and getElementType(player) == "player" then
            -- Player is in a vehicle and colliding with the marker
            if isElementWithinMarker(hitElement, marker) then
                -- Do something here (e.g., cancel the collision, display a message, etc.)
                cancelEvent()
            end
        end
    end
end
addEventHandler("onVehicleCollision", root, onVehicleCollision)

 

  • Thanks 1
Link to comment
8 minutes ago, Shady1 said:
local marker = -- The marker element you want to prevent the player from hitting

function onVehicleCollision(hitElement, force, bodyPart, collisionX, collisionY, collisionZ, normalX, normalY, normalZ, material1, material2)
    if getElementType(hitElement) == "vehicle" then
        -- Check if the player is in a vehicle
        local player = getVehicleOccupant(hitElement)
        if player and getElementType(player) == "player" then
            -- Player is in a vehicle and colliding with the marker
            if isElementWithinMarker(hitElement, marker) then
                -- Do something here (e.g., cancel the collision, display a message, etc.)
                cancelEvent()
            end
        end
    end
end
addEventHandler("onVehicleCollision", root, onVehicleCollision)

 

Can you explain why these things are put?  

(hitElement, force, bodyPart, collisionX, collisionY, collisionZ, normalX, normalY, normalZ, material1, material2)
Link to comment
6 minutes ago, scolen said:

Can you explain why these things are put?  

(hitElement, force, bodyPart, collisionX, collisionY, collisionZ, normalX, normalY, normalZ, material1, material2)

Using these parameters totally depends on your needs and game scripts. If you do not need this additional information, you can omit or pass these parameters.

I added these parameters to trigger onVehicleCollision

hitElement: Collision object. In this case, it will be the object or element the vehicle collides with.
force: The force of collision. This is a numeric value representing the severity of the collision.
bodyPart: The part of the body where the collision occurred. For example, vehicle hood, windshield, rear bumper.
collisionX, collisionY, collisionZ: Coordinates of the point where the collision occurred.
normalX, normalY, normalZ: The normal of the collision surface. This is a vector that indicates which direction the collision surface is in.
material1, material2: Strings representing the material types of the colliding objects.

Edited by Shady1
  • Like 1
Link to comment
2 minutes ago, Shady1 said:

Using these parameters totally depends on your needs and game scripts. If you do not need this additional information, you can omit or pass these parameters.

I added these parameters to trigger onVehicleCollision

thanks brother ❤️

 

Link to comment
On 06/06/2023 at 01:48, Shady1 said:

you're welcome,If you have a new question, please open a new topic and tag me.

It's a bit unclear to me.. Can you add it to the codes I'm giving and show it? 

table = createObject(2008, 444.94051, -1489.07007, 19.85312, 0,0, 85)
tableMarker = createMarker(445.78033, -1489.2584, 19.95312, "cylinder", 1, 0, 255, 0)

addEventHandler("onMarkerHit", tableMarker, function(thePlayer)

   destroyElement(tableMarker)
   setPedFrozen(thePlayer, true)
   setPedAnimation(thePlayer, "ROB_BANK", "CAT_Safe_rob", 1)


   setTimer(function()
     setPedFrozen(thePlayer, false)
     outputChatBox("FINISHED GO TO ROB")

     robMarker1 = createMarker(459.10574, -1488.91870, 19.95312, "cylinder", 1, 255, 0, 0)
     robMarker2 = createMarker(465.99966, -1489.58289, 19.95312, "cylinder", 1, 255, 0, 0)
     robMarker3 = createMarker(467.14240, -1496.33667, 19.95312, "cylinder", 1, 255, 0, 0)
     robMarker4 = createMarker(466.66742, -1499.76660, 19.95312, "cylinder", 1, 255, 0, 0)
     robMarker5 = createMarker(464.44263, -1506.12659, 19.95312, "cylinder", 1, 255, 0, 0)
     robMarker6 = createMarker(457.56961, -1505.49231, 19.95312, "cylinder", 1, 255, 0, 0)
     robMarker7 = createMarker(459.34964, -1495.72119, 19.95312, "cylinder", 1, 255, 0, 0)
     robMarker8 = createMarker(459.04904, -1498.66626, 19.95312, "cylinder", 1, 255, 0, 0)
     robMarker9 = createMarker(461.53482, -1501.73730, 19.95312, "cylinder", 1, 255, 0, 0)
     robMarker10 = createMarker(462.28641, -1493.53491, 19.95312, "cylinder", 1, 255, 0, 0)

     --------------------- HIT MARKERS AREA ----------------------------




     addEventHandler("onMarkerHit", robMarker1, function(thePlayer)
      
       destroyElement(robMarker1)
       setPedFrozen(thePlayer, true)
       setPedAnimation(thePlayer, "CASINO", "cards_win", 1)

       setTimer(function()
         setPedFrozen(thePlayer, false)
         givePlayerMoney(thePlayer, 2000)
         outputChatBox("$2000", thePlayer, 0, 255,0)
       end, 15000, 1)

     end) 

  
   end, 7000, 1)-- starting time rob


end) -- start Rob Marker hit event

 

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