Jump to content

Need help about scripting...


[DemoN]

Recommended Posts

1) I've created 5 markers (for now). When I hit them they'll be destroyed( i know how to do that) but when all markers are destroyed (random. not in order), I want to give m4 (id: 31) to player and dunno how to do that. Can someone help me? Here is the code:

local myMarker = createMarker( 0, 0, 4, 'cylinder', 1, 255, 0, 0, 150 ) 
local myMarker2 = createMarker( 0, 2, 4, 'cylinder', 1, 255, 0, 0, 150 ) 
local myMarker3 = createMarker( 0, 4, 4, 'cylinder', 1, 255, 0, 0, 150 ) 
local myMarker4 = createMarker( 0, 6, 4, 'cylinder', 1, 255, 0, 0, 150 ) 
local myMarker5 = createMarker( 0, 8, 4, 'cylinder', 1, 255, 0, 0, 150 ) 
  
function MarkerHit( hitElement, matchingDimension ) 
        destroyElement(myMarker) 
end 
addEventHandler( "onMarkerHit", myMarker, MarkerHit ) 
  
function MarkerHit2( hitElement, matchingDimension ) 
        destroyElement(myMarker2) 
end 
addEventHandler( "onMarkerHit", myMarker2, MarkerHit2 ) 
  
  
function MarkerHit3( hitElement, matchingDimension ) 
        destroyElement(myMarker3) 
end 
addEventHandler( "onMarkerHit", myMarker3, MarkerHit3 ) 
  
  
function MarkerHit4( hitElement, matchingDimension ) 
        destroyElement(myMarker4) 
end 
addEventHandler( "onMarkerHit", myMarker4, MarkerHit4 ) 
  
  
function MarkerHit5( hitElement, matchingDimension ) 
        destroyElement(myMarker5) 
end 
addEventHandler( "onMarkerHit", myMarker5, MarkerHit5 ) 

2) Where can i find an example of attaching an object to player's bone?

Edited by Guest
Link to comment

How about this:

local myMarkers =  
{ createMarker( 0, 0, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 2, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 4, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 6, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 8, 4, 'cylinder', 1, 255, 0, 0, 150 ) 
} 
  
function PlayerMarkerHit( markerHit, matchingDimension ) 
      local player = source 
      for k, marker in ipairs(myMarkers) do 
              if marker == markerHit then 
                      destroyElement ( markerHit ) 
                      return 
              end 
      end 
      giveWeapon ( player, 31 ) 
end 
addEventHandler( "onPlayerMarkerHit", root, PlayerMarkerHit ) 

2) Search for "bone" in community or this one https://community.multitheftauto.com/index.php?p= ... ls&id=1823

Link to comment

well... I've created something so silly and it says: bad argument @ attachElements

function myTest() 
  
local x, y, z = getPedBonePosition(getLocalPlayer(), 6) 
local object = createObject(1369, 0, 0, 0) 
attachElements(object, source, x, y, z) 
  
end 
addCommandHandler("testing", myTest) 

Link to comment

Source is not defined.

function myTest() 
  
local x, y, z = getPedBonePosition(getLocalPlayer(), 6) 
local object = createObject(1369, 0, 0, 0) 
attachElements(object, getLocalPlayer(), x, y, z) 
  
end 
addCommandHandler("testing", myTest) 

But this won't do what you want

here is what you want:

function myTest() 
local x, y, z = getPedBonePosition(getLocalPlayer(), 6) 
local object = createObject(1369, x, y, z) 
attachRotationAdjusted(object, getLocalPlayer()) 
end 
addCommandHandler("testing", myTest) 
  
function attachRotationAdjusted ( from, to ) 
    local frPosX, frPosY, frPosZ = getElementPosition( from ) 
    local frRotX, frRotY, frRotZ = getElementRotation( from ) 
    local toPosX, toPosY, toPosZ = getElementPosition( to ) 
    local toRotX, toRotY, toRotZ = getElementRotation( to ) 
    local offsetPosX = frPosX - toPosX 
    local offsetPosY = frPosY - toPosY 
    local offsetPosZ = frPosZ - toPosZ 
    local offsetRotX = frRotX - toRotX 
    local offsetRotY = frRotY - toRotY 
    local offsetRotZ = frRotZ - toRotZ 
    offsetPosX, offsetPosY, offsetPosZ = applyInverseRotation ( offsetPosX, offsetPosY, offsetPosZ, toRotX, toRotY, toRotZ ) 
    attachElements( from, to, offsetPosX, offsetPosY, offsetPosZ, offsetRotX, offsetRotY, offsetRotZ ) 
end 
  
function applyInverseRotation ( x,y,z, rx,ry,rz ) 
    local DEG2RAD = (math.pi * 2) / 360 
    rx = rx * DEG2RAD 
    ry = ry * DEG2RAD 
    rz = rz * DEG2RAD 
    local tempY = y 
    y =  math.cos ( rx ) * tempY + math.sin ( rx ) * z 
    z = -math.sin ( rx ) * tempY + math.cos ( rx ) * z 
    local tempX = x 
    x =  math.cos ( ry ) * tempX - math.sin ( ry ) * z 
    z =  math.sin ( ry ) * tempX + math.cos ( ry ) * z 
    tempX = x 
    x =  math.cos ( rz ) * tempX + math.sin ( rz ) * y 
    y = -math.sin ( rz ) * tempX + math.cos ( rz ) * y 
    return x, y, z 
end 

Link to comment

Thanks. but still dunno that:

local myMarkers = 
{ createMarker( 0, 0, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 2, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 4, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 6, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 8, 4, 'cylinder', 1, 255, 0, 0, 150 ) 
} 
  
function PlayerMarkerHit( markerHit, matchingDimension ) 
      local player = source 
      for k, marker in ipairs(myMarkers) do 
              if marker == markerHit then 
                      destroyElement ( markerHit ) 
                      return 
              end 
      end 
      giveWeapon ( player, 31 ) 
end 
addEventHandler( "onPlayerMarkerHit", root, PlayerMarkerHit ) 

It creates markers but when all markers are destroyed, it doesn't give me m4
Link to comment
local myMarkers = 
{ createMarker( 0, 0, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 2, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 4, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 6, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 8, 4, 'cylinder', 1, 255, 0, 0, 150 ) 
} 
  
function PlayerMarkerHit( markerHit, matchingDimension ) 
      local player = source 
      for k, marker in ipairs(myMarkers) do 
              if marker == markerHit then 
                      table.remove(myMarkers, markerHit) 
                      destroyElement ( markerHit ) 
                      break 
              end 
      end 
      if #myMarkers == 0 then 
            giveWeapon ( player, 31 ) 
      end 
end 
addEventHandler( "onPlayerMarkerHit", root, PlayerMarkerHit ) 

Link to comment
  • 3 weeks later...

22 Days later ...

What's happens? any errors?

local myMarkers = 
{ createMarker( 0, 0, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 2, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 4, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 6, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 8, 4, 'cylinder', 1, 255, 0, 0, 150 ) 
} 
  
function PlayerMarkerHit( markerHit, matchingDimension ) 
      for k, marker in ipairs(myMarkers) do 
              if marker == markerHit then 
                      table.remove(myMarkers, markerHit) 
                      destroyElement ( markerHit ) 
                      break 
              end 
      end 
      if #myMarkers == 0 then 
            giveWeapon ( source, 31 ) 
      end 
end 
addEventHandler( "onPlayerMarkerHit", root, PlayerMarkerHit ) 

Link to comment
local myMarkers = 
{ createMarker( 0, 0, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 2, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 4, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 6, 4, 'cylinder', 1, 255, 0, 0, 150 ), 
createMarker( 0, 8, 4, 'cylinder', 1, 255, 0, 0, 150 ) 
} 
  
function PlayerMarkerHit( markerHit, matchingDimension ) 
      for k, marker in ipairs(myMarkers) do 
              if marker == markerHit then 
                      marker = nil 
                      destroyElement ( markerHit ) 
                      break 
              end 
      end 
      if #myMarkers == 0 then 
            giveWeapon ( source, 31 ) 
      end 
end 
addEventHandler( "onPlayerMarkerHit", root, PlayerMarkerHit ) 

Link to comment

I fixed it:

addEventHandler("onMarkerHit", root, 
    function(hitElement) 
        for k, marker in ipairs(myMarkers) do 
            if marker == source then 
                table.remove(myMarkers, k) 
                destroyElement (source) 
                if #myMarkers == 0 then 
                    giveWeapon(hitElement, 31, 300, true) 
                end 
            end 
        end 
    end 
) 

Tested.

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