Jump to content

Trip mine script


Xwad

Recommended Posts

i made it but only the createObject is working:/

  
function Mine(thePlayer, matchingDimension) 
createColSphere ( -1467, -1467, 99.15, 1 ) 
local pX, pY, pZ = getElementPosition ( source )   -- get the player's position 
createExplosion ( pX, pY, pZ, 6, source )   -- and create an explosion there 
outputChatBox("You stepped on a Mine!",thePlayer,255,109 ,109 ) -- outputs a chatbox 
end 
addEventHandler("onColShapeHit",root,Mine) 
  
  
function Object ( name ) 
createObject ( 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 ) -- this creates an object 
end 
addEventHandler ( "onResourceStart", resourceRoot, Object ) 
  

Link to comment

the col shape should be out the hit function

function Object ( name ) 
createObject ( 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 ) -- this creates an object 
colShape = createColSphere ( -1467, -1467, 99.15, 1 ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, Object ) 
  
function Mine(thePlayer, matchingDimension) 
local pX, pY, pZ = getElementPosition ( source )   -- get the player's position 
createExplosion ( pX, pY, pZ, 6, source )   -- and create an explosion there 
outputChatBox("You stepped on a Mine!",colShape,255,109 ,109 ) -- outputs a chatbox 
end 
addEventHandler("onColShapeHit",colShape,Mine) 

Link to comment
function Object ( name ) 
createObject ( 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 ) -- this creates an object 
colShape = createColSphere ( -1467, -1467, 99.15, 1 ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, Object ) 
  
function Mine(thePlayer, matchingDimension) 
    if source == colShape then 
    local pX, pY, pZ = getElementPosition ( thePlayer )   -- get the player's position 
    createExplosion ( pX, pY, pZ, 6, source )   -- and create an explosion there 
    outputChatBox("You stepped on a Mine!",colShape,255,109 ,109 ) -- outputs a chatbox 
    end 
end 
addEventHandler("onColShapeHit",root,Mine) 

Link to comment

the command is working but you cant see the colshape because the colshape position is worng and you cannot choose the width and high

you have used sphere colshaope

anyway try that code it should works fine

function Object ( name ) 
createObject ( 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 ) -- this creates an object 
colShape = createColSphere ( -1467, -1287.6701, 99.15, 2 ) -- the last argument is the size of the colshape 
end 
addEventHandler ( "onResourceStart", resourceRoot, Object ) 
  
function Mine(thePlayer, matchingDimension) 
    if source == colShape then 
    local pX, pY, pZ = getElementPosition ( thePlayer )   -- get the player's position 
    createExplosion ( pX, pY, pZ, 6, source )   -- and create an explosion there 
    outputChatBox("You stepped on a Mine!",colShape,255,109 ,109 ) -- outputs a chatbox 
    end 
end 
addEventHandler("onColShapeHit",root,Mine) 

Link to comment
local mines = { { 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 } }; -- all mines over here! 
  
addEventHandler( "onResourceStart", resourceRoot, -- if resource started the function starts to work! 
function() 
for i, v in ipairs( mines ) do -- loop the table above. you can add more mines if you add more data { { id, x, y, z, rx, ry, rz }, { same here and so on } } 
    local mine = createObject( v[1], v[2], v[3], v[4], v[5], v[6], v[7] ); -- lets create it 
    setElementData( mine, "mine", true ); -- lets set a data to remember it is a mine 
    end 
    setTimer( 
function() 
for i, p in ipairs( getElementsByType( "player" ) ) do -- loop through all players and check position 
    pX, pY, pZ = getElementPosition( p ); -- get position 
for i, o in ipairs( getElementsByType( "object" ) ) do -- loop through all objects and check position 
if ( getElementData( o, "mine" ) == true ) then -- check if it really a mine and not for example fence 
    oX, oY, oZ = getElementPosition( o ); -- get position 
if ( getDistanceBetweenPoints3D( pX, pY, pZ, oX, oY, oZ ) < 2 ) then -- now lets see if player is near enough 
    outputChatBox( "Kaboooohm! Mine over here!", p, 255, 0, 0 ); 
    createExplosion( oX, oY, oZ, 6 ); -- more realistic if explosion comes from mine. 
                    end 
                end 
            end 
        end 
    end, 1000, 0 ); -- lets check every second if someone is near mine. 
end ) 

untested but should work :)

Link to comment

it work perfectly. (tested)

function Object ( name ) 
setElementCollisionsEnabled(createObject ( 1211, -1467.2827, -1287.6701, 99.1, 0, 0, 0 ), false) -- this creates an object 
colShape = createColSphere ( -1467.2827, -1287.6701, 99.1, 2) 
end 
addEventHandler ( "onResourceStart", resourceRoot, Object ) 
  
function Mine(thePlayer, matchingDimension) 
    if getElementType ( thePlayer ) == "player" then 
        if source == colShape then 
            local pX, pY, pZ = getElementPosition ( thePlayer )   -- get the player's position 
            createExplosion ( pX, pY, pZ, 6, thePlayer )   -- and create an explosion there 
            outputChatBox("You stepped on a Mine!",thePlayer,255,109 ,109 ) -- outputs a chatbox 
        end 
    end 
end 
addEventHandler("onColShapeHit",root,Mine) 

Link to comment
local mines = { { 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 } }; -- all mines over here! 
  
addEventHandler( "onResourceStart", resourceRoot, -- if resource started the function starts to work! 
function() 
for i, v in ipairs( mines ) do -- loop the table above. you can add more mines if you add more data { { id, x, y, z, rx, ry, rz }, { same here and so on } } 
    local mine = createObject( v[1], v[2], v[3], v[4], v[5], v[6], v[7] ); -- lets create it 
    setElementData( mine, "mine", true ); -- lets set a data to remember it is a mine 
    end 
    setTimer( 
function() 
for i, p in ipairs( getElementsByType( "player" ) ) do -- loop through all players and check position 
    pX, pY, pZ = getElementPosition( p ); -- get position 
for i, o in ipairs( getElementsByType( "object" ) ) do -- loop through all objects and check position 
if ( getElementData( o, "mine" ) == true ) then -- check if it really a mine and not for example fence 
    oX, oY, oZ = getElementPosition( o ); -- get position 
if ( getDistanceBetweenPoints3D( pX, pY, pZ, oX, oY, oZ ) < 2 ) then -- now lets see if player is near enough 
    outputChatBox( "Kaboooohm! Mine over here!", p, 255, 0, 0 ); 
    createExplosion( oX, oY, oZ, 6 ); -- more realistic if explosion comes from mine. 
                    end 
                end 
            end 
        end 
    end, 1000, 0 ); -- lets check every second if someone is near mine. 
end ) 

untested but should work

for i, v in ipairs( mines ) do 
-- code 
end 

'ipairs' only works if the table has string, as fair i know. you must use:

pairs 

Link to comment

yes its becaouse my spawn script!! So i used SetElementHealth for the script but dosent work

  
function Object ( name ) 
setElementCollisionsEnabled(createObject ( 1211, -1467.2827, -1287.6701, 99.1, 0, 0, 0 ), false) -- this creates an object 
colShape = createColSphere ( -1746, -1743, 28, 2) 
end 
addEventHandler ( "onResourceStart", resourceRoot, Object ) 
  
function Mine(thePlayer, matchingDimension) 
    if getElementType ( thePlayer ) == "player" then 
        if source == colShape then 
            local pX, pY, pZ = getElementPosition ( thePlayer )   -- get the player's position 
            createExplosion ( pX, pY, pZ, 6, thePlayer )   -- and create an explosion there 
             if ( theHealth < 100 ) then  
            setElementHealth ( source, theHealth - 70) 
            outputChatBox("You stepped on a Mine!",thePlayer,255,109 ,109 ) -- outputs a chatbox 
        end 
    end 
end 
end 
addEventHandler("onColShapeHit",root,Mine) 
  

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