Jump to content

Question


Xeno

Recommended Posts

How can I get the position infront of the player? I mean like, if I was moving an object, how would I make it so that it moves FORWARD in the direction the player is facing.

And how would I see if the object hit a wall? So if the object was to hit a wall ,it would stop.

Thanks in advance,

Xeno.

Link to comment

This has totally confused me? I gave it ago...

function predBomb(player) 
local x,y,z = getElementPosition(player) 
bomb = createObject(1337,x+1,y,z,findRotation(x,y,tx,ty) 
setTimer(setElementPosition,50,1,bomb,x+1,y,z) 
setTimer(setElementPosition,150,1,bomb,x+3,y,z) 
setTimer(setElementPosition,250,1,bomb,x+6,y,z) 
setTimer(setElementPosition,350,1,bomb,x+9,y,z) 
local xo,yo,zo = getElementPosition(bomb) 
setTimer(createExplosion,2000,1,xo,yo,zo, 0) 
end 
addCommandHandler("bomb", predBomb) 

Link to comment

There's an example to face another player:

addCommandHandler("facePlayer", 
function (player, cmd, targetName) 
  
    local target = getPlayerFromNick(targetName); 
  
    if not target then 
        outputChatBox("Invalid player", player); 
    end 
  
    local x,y,z     = getElementPosition(player); 
    local tx,ty,tz  = getElementPosition(target); 
  
    setPedRotation(player, findRotation(x,y,tx,ty) ); 
  
end 
); 

Link to comment
function getPositionInfrontOfElement ( element , meters ) 
    if not element or not isElement ( element ) then 
        return false 
    end 
    if not meters then 
        meters = 3 
    end 
    local posX , posY , posZ = getElementPosition ( element ) 
    local _ , _ , rotation = getElementRotation ( element ) 
    posX = posX - math.sin ( math.rad ( rotation ) ) * meters 
    posY = posY + math.cos ( math.rad ( rotation ) ) * meters 
    return posX , posY , posZ 
end 

Link to comment

Sorry for my noobyness, but I've never done this before..

Something like this?

function predBomb(player, element, meters) 
   if not element or not isElement ( element ) then 
        return false 
    end 
    if not meters then 
        meters = 3 
    end 
    local posX , posY , posZ = getElementPosition ( element ) 
    local _ , _ , rotation = getElementRotation ( element ) 
    posX = posX - math.sin ( math.rad ( rotation ) ) * meters 
    posY = posY + math.cos ( math.rad ( rotation ) ) * meters 
    return posX , posY , posZ 
bomb = createObject(1337,posX+1,posY,posZ) 
setTimer(setElementPosition,50,1,bomb,posX+1,posY,posZ) 
setTimer(setElementPosition,150,1,bomb,posX+3,posY,posZ) 
setTimer(setElementPosition,250,1,bomb,posX+6,posY,posZ) 
setTimer(setElementPosition,350,1,bomb,posX+9,posY,posZ) 
local xo,yo,zo = getElementPosition(bomb) 
setTimer(createExplosion,2000,1,xo,yo,zo, 0) 
end 
end 
end 
addCommandHandler("bomb", predBomb) 

Link to comment
function predBomb(player, _,name, meters) 
local target = getPlayerFromName (name) 
if not target or not isElement ( target) then return end 
meters = tonumber(meters) 
    if not meters then 
        meters = 3 
    end 
    local posX , posY , posZ = getElementPosition ( target ) 
    local  rotation = getPedRotation( target ) 
    posX = posX - math.sin ( math.rad ( rotation ) ) * meters 
    posY = posY + math.cos ( math.rad ( rotation ) ) * meters 
bomb = createObject(1337,posX+1,posY,posZ) 
setTimer(setElementPosition,50,1,bomb,posX+1,posY,posZ) 
setTimer(setElementPosition,150,1,bomb,posX+3,posY,posZ) 
setTimer(setElementPosition,250,1,bomb,posX+6,posY,posZ) 
setTimer(setElementPosition,350,1,bomb,posX+9,posY,posZ) 
local xo,yo,zo = getElementPosition(bomb) 
setTimer(createExplosion,2000,1,xo,yo,zo, 0) 
end 
addCommandHandler("bomb", predBomb) 

Link to comment
function predBomb(player, _,name, meters) 
local target = getPlayerFromPartialName (name,player) 
if not target or not isElement ( target) then return end 
meters = tonumber(meters) 
    if not meters then 
        meters = 3 
    end 
    local posX , posY , posZ = getElementPosition ( target ) 
    local  rotation = getPedRotation( target ) 
    posX = posX - math.sin ( math.rad ( rotation ) ) * meters 
    posY = posY + math.cos ( math.rad ( rotation ) ) * meters 
bomb = createObject(1337,posX+1,posY,posZ) 
setTimer(setElementPosition,50,1,bomb,posX+1,posY,posZ) 
setTimer(setElementPosition,150,1,bomb,posX+3,posY,posZ) 
setTimer(setElementPosition,250,1,bomb,posX+6,posY,posZ) 
setTimer(setElementPosition,350,1,bomb,posX+9,posY,posZ) 
local xo,yo,zo = getElementPosition(bomb) 
setTimer(createExplosion,2000,1,xo,yo,zo, 0) 
end 
addCommandHandler("bomb", predBomb) 
  
  
function getPlayerFromPartialName ( name , player ) 
    if name then 
        local matches = { } 
        for index , _player in ipairs ( getElementsByType ( "player" ) ) do 
            if getPlayerName ( _player ) == name then 
                return _player 
            end 
            if getPlayerName ( _player ) : gsub ( "#%x%x%x%x%x%x" , "" ) : lower ( ) : find ( name : lower ( ) ) then 
                table.insert ( matches , _player ) 
            end 
        end 
        if #matches == 1 then 
            return matches [ 1 ] 
        else 
            if player then 
                outputChatBox ( "Found " .. #matches .. " matches" , player , 255 , 0 , 0 ) 
            end 
        end 
    end 
end 

Link to comment

Check this:

function predBomb( player, _,name, meters ) 
    local target = getPlayerFromPartialName ( name,player ) 
    if not isElement ( target ) then return outputChatBox( "can't find player" ) end 
    local meters = tonumber( meters ) 
    if not meters then 
        meters = 3 
    end 
    local posX , posY , posZ = getElementPosition ( target ) 
    local  rotation = getPedRotation( target ) 
    posX = posX - math.sin ( math.rad ( rotation ) ) * meters 
    posY = posY + math.cos ( math.rad ( rotation ) ) * meters 
    local bomb = createObject( 1337,posX+1,posY,posZ ) 
    outputChatBox( "Bomb return: "..tostring( bomb ) ) 
    setTimer( setElementPosition,50,1,bomb,posX+1,posY,posZ ) 
    setTimer( setElementPosition,150,1,bomb,posX+3,posY,posZ ) 
    setTimer( setElementPosition,250,1,bomb,posX+6,posY,posZ ) 
    setTimer( setElementPosition,350,1,bomb,posX+9,posY,posZ ) 
    local xo,yo,zo = getElementPosition( bomb ) 
    setTimer( createExplosion,2000,1,xo,yo,zo, 0 ) 
end 
addCommandHandler("bomb", predBomb) 
  
  
function getPlayerFromPartialName ( name , player ) 
    if name then 
        local matches = { } 
        for index , _player in ipairs ( getElementsByType ( "player" ) ) do 
            if getPlayerName ( _player ) == name then 
                return _player 
            end 
            if getPlayerName ( _player ) : gsub ( "#%x%x%x%x%x%x" , "" ) : lower ( ) : find ( name : lower ( ) ) then 
                table.insert ( matches , _player ) 
            end 
        end 
        if #matches == 1 then 
            return matches [ 1 ] 
        else 
            if player then 
                outputChatBox ( "Found " .. #matches .. " matches" , player , 255 , 0 , 0 ) 
            end 
        end 
    end 
end 

Link to comment

OOH! I didn't think it would work like that....

I think you guys mis-understood what I am trying to do..

I was just trying to make it so when I type /bomb, an object shoots from the front of the player and goes in the direction of where there facing...

So for example if I was facing north, the object would go north, if I was facing south, the object would go south, do you get it?

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