Jump to content

Trying to attach a blip to a player's position


Recommended Posts

I'm trying to attach a blip to a player's position, so whenever he pressed a key, it should open an image and display a blip on his position on the map, can someone check why have I done wrong?

I'm getting the following error message: " Bad argument @ 'attachElements' "

It's supposed to attach a blip to a player, and keep changing the blip's location when the player moves, also, it should only display the blip when a key is pressed, which is "F10"

function posicao () 
    local myplayer = getLocalPlayer 
    local x, y, z = getElementPosition ( getLocalPlayer ( ) ) 
    local myBlip = createBlip( x, y, z, 2 ) 
    attachElements ( myPlayer, myBlip ) 
end 
addEventHandler("onClientKey", root, posicao, "F11") 

Link to comment

@SolidSnake, but is the

addEventHandler("onClientKey", root, posicao, "F11") 

Line right? Because it seems like I have made something wrong there. Also, it should only display the button to the player who has pressed the key and it should not display other people locations.

Link to comment
  • Moderators

onClientKey

Doesn't take extra arguments.

  
function posicao(button,pressOrRelease) 
    if button == "f11" and pressOrRelease then 
     
    end 
end 
  
  
addEventHandler("onClientKey", root, posicao) 

Link to comment

I'm getting a bad argument on createBlipAttachedTo, I have created a variable to define local player, but I'm pretty sure it's completely wrong...

function posicao(button,pressOrRelease) 
    if button == "f11" and pressOrRelease then 
    local myplayer = getLocalPlayer () 
    local myBlip = createBlipAttachedTo ( myPlayer, 2 ) 
    end 
end 
addEventHandler("onClientKey", root, posicao) 

Edited by Guest
Link to comment

I did it but it's not working. I have in mind that it's because there is a GUI in front of the blip, as I have said on the first topic message, it's supposed to open an image when the player presses a key and at that image a blip should be displayed, showing player's position, I'll paste the whole script so you can check what I'm doing. It's basically a modified map, an image, when a player moves a blip on that image moves along.

myWindow = guiCreateWindow( 100, 0, 600, 600, "asdddasdwds", false ) 
guiWindowSetSizable( myWindow, false ) 
guiWindowSetMovable( myWindow, false ) 
guiSetVisible ( myWindow, false ) 
myImage = guiCreateStaticImage(9, 18, 581, 572, "radar.png", false, myWindow ) 
  
function abriromapa () 
    if ( guiGetVisible ( myWindow ) == false ) then 
        guiSetVisible ( myWindow, true ) 
    else               
        guiSetVisible ( myWindow, false ) 
    end 
end 
addCommandHandler( "sadasdddasd", abriromapa ) 
bindKey( "F11", "down", abriromapa ) 
  
function posicao(button,pressOrRelease) 
    if button == "F11" and pressOrRelease then 
    local myPlayer = getLocalPlayer () 
    local myBlip = createBlipAttachedTo ( myPlayer, 2 ) 
    end 
end 
addEventHandler("onClientKey", root, posicao) 

Link to comment
  • Moderators

Debug your code if you want to know why it isn't working.

/debugscript 3

function posicao(button,pressOrRelease) 
    outputDebugString("key pressed Button: " .. tostring(button) .. ",  State: " .. tostring(pressOrRelease)) 
    if button == "F11" and pressOrRelease then 
    local myPlayer = getLocalPlayer () 
    local myBlip = createBlipAttachedTo ( myPlayer, 2 ) 
    end 
end 
addEventHandler("onClientKey", root, posicao) 

Link to comment

It is working, eveyrthing is fine and i'm using /debugscript 3. I realized the problem is that the image is opening on top of the blip. All I wanted was to make an image and on that image a blip that moves along with the player... The blip is created, it displays on map and on radar, but on the image that I have created it doesn't because the image is on top of the blip.

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