Jump to content

I cant getelementposition


iFoReX

Recommended Posts

@tittle, I cant get element position of a player , I want do a script of getpos :D

function getpos( thePlayer ) 
  
x,y,z = getElementPosition( thePlayer ) 
  
outputChatBox( "ur pos is (x,y,z) " ) 
  
end 
  
addCommandHandler("getpos", getpos) 

what is bad ?

Link to comment
function getpos( thePlayer ) 
  
x,y,z = getElementPosition( thePlayer ) 
  
outputChatBox( "ur pos is X: " ..x.. "Y: " ..y.. "Z: " ..z.. "!", thePlayer) -- here you had (X) (Y) which wouldn't output the result, it would output what you wrote, you need to "end" the message, and add "MESSAGE" ..x.. "MSG2" ..z.. cheers. 
  
end 
  
addCommandHandler("getpos", getpos) 

server sided.

Edited by Guest
Link to comment
solid is server-side or client ?

Server side.

@seb: Your script would output the message to everyone, since you're using "client" as player element instead of "thePlayer".

Yea well, we don't know if he wanted it to show for everyone or just the player, anyhow I've changed it.

He also asked us WHAT is bad, not to actually write the code he wanted

Link to comment

why my camera matrix doesnt work D:

sv- side

function a( source ) 
  
setCameraMatrix( source, 1654.2763671875, -1670.05078125, 21.4375, 1654.16162, -1661.63123, 21.9 ) 
end 
  
addEvent("qd4", true) 
addEventHandler("qd4", getLocalPlayer(), a) 

cl-side

GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Edit = {} 
  
GUIEditor_Window[1] = guiCreateWindow(0.3242,0.6933,0.3477,0.1833,"GUI Skins",true) 
GUIEditor_Edit[1] = guiCreateEdit(21,25,75,30,"",false,GUIEditor_Window[1]) 
GUIEditor_Label[1] = guiCreateLabel(101,28,214,18,"Aqui Pones la ID del skin que quieras",false,GUIEditor_Window[1]) 
guiLabelSetColor(GUIEditor_Label[1],255,255,0) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
GUIEditor_Button[1] = guiCreateButton(21,66,111,32,"Comprar Skin",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(196,66,111,32,"Cancelar",false,GUIEditor_Window[1]) 
  
guiSetVisible( GUIEditor_Window[1], false) 
showCursor(false) 
  
------------------------------------ 
---TheMarker------------------------ 
marker = createMarker( 1654.16162, -1661.63123, 21.9, "cylinder", 2, 100, 0, 255, 100 ) 
  
------------------------------------ 
---TheFunctions--------------------- 
  
function markerHit ( hitPlayer ) 
    if ( hitPlayer == localPlayer and source == marker ) then 
guiSetVisible( GUIEditor_Window[1], true ) 
showCursor(true) 
   triggerServerEvent ( "qd4", getLocalPlayer() ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", root, markerHit ) 
  
function botton() 
    if source == GUIEditor_Button[2] then 
guiSetVisible( GUIEditor_Window[1], false) 
showCursor(false) 
    end 
end 
addEventHandler ( "onClientGUIClick", root, botton ) 

Link to comment

what is bad ? bad element setElementDimension and the SetElementFrozen

function markerHit ( hitPlayer ) 
    if ( hitPlayer == localPlayer and source == marker ) then 
guiSetVisible( GUIEditor_Window[1], true ) 
showCursor(true) 
setElementDimension( ped, 2 ) 
   triggerServerEvent ( "cm", getLocalPlayer() ) 
   ped = createPed( 1654.16162, -1661.63123, 21.9 ) 
   setElementFrozen ( ped , true ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", root, markerHit ) 

Link to comment
what is bad ? bad element setElementDimension and the SetElementFrozen
function markerHit ( hitPlayer ) 
    if ( hitPlayer == localPlayer and source == marker ) then 
   guiSetVisible( GUIEditor_Window[1], true ) 
   showCursor(true) 
   setElementDimension( ped, 2 ) 
   triggerServerEvent ( "cm", getLocalPlayer() ) 
   ped = createPed( 1654.16162, -1661.63123, 21.9 ) 
   setElementFrozen ( ped , true ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", root, markerHit ) 

You need to specify an ID for the ped, which will set the skin ID.

function markerHit ( hitPlayer ) 
    if ( hitPlayer == localPlayer and source == marker ) then 
guiSetVisible( GUIEditor_Window[1], true ) 
showCursor(true) 
   triggerServerEvent ( "cm", getLocalPlayer() ) 
   ped = createPed(  skinID, 1654.16162, -1661.63123, 21.9 ) -- change skinID to the id you want the ped to wear/have 
   setElementFrozen ( ped , true ) 
   setElementDimension( ped, 2 ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", root, markerHit ) 

Edited by Guest
Link to comment
function markerHit ( hitPlayer ) 
    if ( hitPlayer == localPlayer and source == marker ) then 
        guiSetVisible( GUIEditor_Window[1], true ) 
        showCursor(true) 
        triggerServerEvent ( "cm", getLocalPlayer() ) 
        ped = createPed( 0, 1654.16162, -1661.63123, 21.9 ) -- Change '0' to your skin ID. 
        setElementFrozen ( ped, true ) 
        setElementDimension( ped, 2 ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", root, markerHit ) 

Link to comment

Again in debugging : bad argument setElementDimension and bad argument setElementFrozen

it is my code

function markerHit ( hitPlayer ) 
    if ( hitPlayer == localPlayer and source == marker ) then 
guiSetVisible( GUIEditor_Window[1], true ) 
showCursor(true) 
   triggerServerEvent ( "cm", getLocalPlayer() ) 
   setElementDimension( localPlayer, 2 ) 
   ped = createPed( tonumber(guiGetText( GUIEditor_Edit[1] )), 1654.16162, -1661.63123, 21.9 ) 
        setElementFrozen ( ped, true ) 
        setElementDimension( ped, 2 ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", root, markerHit ) 

Link to comment
function markerHit ( hitPlayer ) 
    if ( hitPlayer == localPlayer and source == marker ) then 
        guiSetVisible ( GUIEditor_Window[1], true ) 
        showCursor ( true ) 
        triggerServerEvent ( "cm", getLocalPlayer() ) 
        setElementDimension( localPlayer, 2 ) 
        ped = createPed ( tonumber ( guiGetText ( GUIEditor_Edit[1] ) ) or 0, 1654.16162, -1661.63123, 21.9 ) -- If no skin was given, it'll create it with CJ skin. 
        if ( ped ) then 
            setElementFrozen ( ped, true ) 
            setElementDimension( ped, 2 ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", root, markerHit ) 

Link to comment

now Doesnt Work it function , I put when the Player hit the marker he go to 0,0,0 but I want when he press the button back to the original Pos

function botton() 
    if source == GUIEditor_Button[2] then 
guiSetVisible( GUIEditor_Window[1], false) 
showCursor(false) 
setCameraTarget( localPlayer ) 
setElementDimension( localPlayer, 0 ) 
setElementFrozen ( localPlayer, false ) 
setElementPosition ( localPlayer, 1654.16162, -1661.63123, 21.9 ) 
    end 
end 
addEventHandler ( "onClientGUIClick", root, botton ) 

Link to comment

That's a table, but still is better than variables, but incorrect though.

local originalPosition = { } 
  
function botton() 
    if source == GUIEditor_Button[2] then 
        originalPosition = { getElementPosition ( localPlayer ) } 
        guiSetVisible( GUIEditor_Window[1], false) 
        showCursor ( false ) 
        setCameraTarget ( localPlayer ) 
        setElementDimension ( localPlayer, 0 ) 
        setElementFrozen ( localPlayer, false ) 
        setElementPosition ( localPlayer, 1654.16162, -1661.63123, 21.9 ) 
    end 
end 
addEventHandler ( "onClientGUIClick", root, botton ) 

To set the position again you can do:

setElementPosition ( localPlayer, unpack ( originalPosition ) ) 

Link to comment

sv-side

function a() 
  
camara = setCameraMatrix( source, 1654.2763671875, -1670.05078125, 21.4375, 1654.16162, -1661.63123, 21.9 ) 
setElementDimension( camara, 2 ) 
end 
  
addEvent("cm", true) 
addEventHandler("cm", root, a) 
  
function e( ) 
local money = getPlayerMoney ( source ) 
if (money >= 15000) then 
takePlayerMoney( source, 15000 ) 
else 
outputChatBox( " tu Dinero es "..money.." y necesitas $15000 para comprarte un skin " ) 
end 
end 
addEvent("qtm", true) 
addEventHandler("qtm", getRootElement(), e) 
  
function playerQuits () 
      local playeraccount = getPlayerAccount ( source ) -- get the player's account 
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in 
            local skin = getElementModel( source ) -- get skin accountdata 
            setAccountData ( playeraccount, "skins", skin ) -- save current skin to account 
      end 
end 
addEventHandler ( "onPlayerQuit", getRootElement ( ), playerQuits ) 
  
function playerLogin ( _, playeraccount ) -- player logs in 
      if playeraccount then -- if account that he logged into, exists 
            local skins = getAccountData ( playeraccount, "skins" ) -- get skin accountdata 
            if skins then -- if he has skin accountdata 
                  setElementModel ( source, skins ) -- give him the skin 
            end 
      end 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), playerLogin ) 
  
function playerSpawns () -- called when a player spawns 
    local account = getPlayerAccount ( source ) -- get the player's account 
    if account and not isGuestAccount ( account ) then -- if he's logged in on an account 
        local skin = getAccountData ( playeraccount, "skins" ) -- get skin accountdata 
        if skin then -- if he has skin accountdata 
            setElementModel ( source, skin ) -- give him the skin 
        end 
    end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), playerSpawns ) -- when player spawns, call playerSpawns function 

cl-side

GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Edit = {} 
  
GUIEditor_Window[1] = guiCreateWindow(0.3242,0.6933,0.3477,0.2316,"GUI Skins",true) 
GUIEditor_Label[1] = guiCreateLabel(101,28,214,18,"Aqui Pones la ID del skin que quieras",false,GUIEditor_Window[1]) 
guiLabelSetColor(GUIEditor_Label[1],255,255,0) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
GUIEditor_Edit[1] = guiCreateEdit(21,25,75,30,"",false,GUIEditor_Window[1]) 
GUIEditor_Button[1] = guiCreateButton(21,66,111,32,"Comprar Skin",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(196,66,111,32,"Cancelar",false,GUIEditor_Window[1]) 
GUIEditor_Label[2] = guiCreateLabel(17,111,323,16,"El Costo de este Skin es el siguiente : 15000 ",false,GUIEditor_Window[1]) 
guiLabelSetColor(GUIEditor_Label[2],255,255,0) 
guiSetFont(GUIEditor_Label[2],"default-bold-small") 
GUIEditor_Window[2] = guiCreateWindow(0.3594,0.295,0.291,0.2167,"GUI Confirmacion de Cambio de Skin",true) 
guiWindowSetMovable(GUIEditor_Window[2],false) 
guiWindowSetSizable(GUIEditor_Window[2],false) 
GUIEditor_Label[3] = guiCreateLabel(39,26,207,14,"Seguro que quieres cambiar tu skin ?",false,GUIEditor_Window[2]) 
guiLabelSetColor(GUIEditor_Label[3],255,255,0) 
guiSetFont(GUIEditor_Label[3],"default-bold-small") 
GUIEditor_Button[3] = guiCreateButton(9,82,63,29,"Si",false,GUIEditor_Window[2]) 
GUIEditor_Button[4] = guiCreateButton(206,82,63,29,"No",false,GUIEditor_Window[2]) 
  
guiSetVisible( GUIEditor_Window[1], false) 
showCursor(false) 
------------------------------------ 
---TheMarker------------------------ 
marker = createMarker( 1654.16162, -1661.63123, 21.9, "cylinder", 2, 100, 0, 255, 100 ) 
createBlipAttachedTo( marker, 45 ) 
function warp() 
setElementPosition( localPlayer, 1651, -1661.63123, 21.9 ) 
end 
addCommandHandler("setpos", warp) 
------------------------------------ 
---TheFunctions--------------------- 
  
function markerHit ( hitPlayer ) 
    if ( hitPlayer == localPlayer and source == marker ) then 
        guiSetVisible ( GUIEditor_Window[1], true ) 
        showCursor ( true ) 
        triggerServerEvent ( "cm", getLocalPlayer() ) 
        setElementDimension( localPlayer, 2 ) 
        ped = createPed ( tonumber ( guiGetText ( GUIEditor_Edit[1] ) ) or 0, 1654.16162, -1661.63123, 21.9 ) -- If no skin was given, it'll create it with CJ skin. 
        setPedSkin(ped, tonumber ( guiGetText ( GUIEditor_Edit[1] ) ) ) 
        if ( ped ) then 
            setElementFrozen ( ped, true ) 
            setElementDimension( ped, 2 ) 
            setElementAlpha( localPlayer, 0 ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", root, markerHit ) 
  
local originalPosition = { } 
  
function botton() 
    if source == GUIEditor_Button[2] then 
originalPosition = { getElementPosition ( localPlayer ) } 
guiSetVisible( GUIEditor_Window[1], false) 
guiSetVisible( GUIEditor_Window[2], false) 
showCursor(false) 
setCameraTarget( localPlayer ) 
setElementDimension( localPlayer, 0 ) 
setElementFrozen ( localPlayer, false ) 
setElementPosition ( localPlayer, unpack ( originalPosition ) ) 
setElementAlpha ( localPlayer, 255 ) 
elseif source == GUIEditor_Button[1] then 
guiSetVisible( GUIEditor_Window[1], false) 
guiSetVisible( GUIEditor_Window[2], true) 
showCursor(true) 
elseif source == GUIEditor_Button[4] then 
guiSetVisible( GUIEditor_Window[1], true ) 
guiSetVisible( GUIEditor_Window[2], false ) 
showCursor(true) 
elseif source == GUIEditor_Button[3] then 
setCameraTarget( localPlayer ) 
guiSetVisible( GUIEditor_Window[1], false ) 
guiSetVisible( GUIEditor_Window[2], false ) 
showCursor(false) 
setElementDimension( localPlayer, 0 ) 
setElementAlpha( localPlayer, 255 ) 
local money = getPlayerMoney( localPlayer ) 
     if ( money >= 15000 ) then 
     triggerServerEvent("qtm", getLocalPlayer() ) 
     setElementModel( localPlayer, tonumber ( guiGetText ( GUIEditor_Edit[1] ) ) ) 
     else 
     outputChatBox( " Para Comprarte este skin necesitas $15000 y tu dinero es "..money.." " ) 
    end 
end 
end 
addEventHandler ( "onClientGUIClick", root, botton ) 
  
function destruir ( matchingDimension ) 
if ( localPlayer and source == marker ) then 
     if isElement(ped) then destroyElement(ped) 
end 
end 
end 
addEventHandler("onClientMarkerLeave", root, destruir) 
  
guiSetVisible( GUIEditor_Window[2], false) 

debugging ( My resource is called GUI4

mtascreen20120421114146.png

Link to comment

This works for me:

GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Edit = {} 
originalPosition = { } 
  
GUIEditor_Window[1] = guiCreateWindow(0.3242,0.6933,0.3477,0.2316,"GUI Skins",true) 
GUIEditor_Label[1] = guiCreateLabel(101,28,214,18,"Aqui Pones la ID del skin que quieras",false,GUIEditor_Window[1]) 
guiLabelSetColor(GUIEditor_Label[1],255,255,0) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
GUIEditor_Edit[1] = guiCreateEdit(21,25,75,30,"",false,GUIEditor_Window[1]) 
GUIEditor_Button[1] = guiCreateButton(21,66,111,32,"Comprar Skin",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(196,66,111,32,"Cancelar",false,GUIEditor_Window[1]) 
GUIEditor_Label[2] = guiCreateLabel(17,111,323,16,"El Costo de este Skin es el siguiente : 15000 ",false,GUIEditor_Window[1]) 
guiLabelSetColor(GUIEditor_Label[2],255,255,0) 
guiSetFont(GUIEditor_Label[2],"default-bold-small") 
GUIEditor_Window[2] = guiCreateWindow(0.3594,0.295,0.291,0.2167,"GUI Confirmacion de Cambio de Skin",true) 
guiWindowSetMovable(GUIEditor_Window[2],false) 
guiWindowSetSizable(GUIEditor_Window[2],false) 
guiSetVisible( GUIEditor_Window[2], false) 
GUIEditor_Label[3] = guiCreateLabel(39,26,207,14,"Seguro que quieres cambiar tu skin ?",false,GUIEditor_Window[2]) 
guiLabelSetColor(GUIEditor_Label[3],255,255,0) 
guiSetFont(GUIEditor_Label[3],"default-bold-small") 
GUIEditor_Button[3] = guiCreateButton(9,82,63,29,"Si",false,GUIEditor_Window[2]) 
GUIEditor_Button[4] = guiCreateButton(206,82,63,29,"No",false,GUIEditor_Window[2]) 
  
guiSetVisible( GUIEditor_Window[1], false) 
showCursor(false) 
------------------------------------ 
---TheMarker------------------------ 
marker = createMarker ( 1654.16162, -1661.63123, 21.9, "cylinder", 2, 100, 0, 255, 100 ) 
createBlipAttachedTo ( marker, 45 ) 
  
function warp ( ) 
    setElementPosition ( localPlayer, 1651, -1661.63123, 21.9 ) 
end 
addCommandHandler ( "setpos", warp ) 
------------------------------------ 
---TheFunctions--------------------- 
  
function markerHit ( hitPlayer ) 
    if ( hitPlayer == localPlayer and source == marker ) then 
        guiSetVisible ( GUIEditor_Window[1], true ) 
        showCursor ( true ) 
        triggerServerEvent ( "cm", getLocalPlayer() ) 
        setElementDimension( localPlayer, 2 ) 
        ped = createPed ( tonumber ( guiGetText ( GUIEditor_Edit[1] ) ) or 0, 1654.16162, -1661.63123, 21.9 ) -- If no skin was given, it'll create it with CJ skin. 
        if ( ped ) then 
            setElementFrozen ( ped, true ) 
            setElementDimension( ped, 2 ) 
            setElementAlpha( localPlayer, 0 ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", root, markerHit ) 
   
function botton ( ) 
    if source == GUIEditor_Button[2] then 
        originalPosition = { getElementPosition ( localPlayer ) } 
        guiSetVisible( GUIEditor_Window[1], false) 
        guiSetVisible( GUIEditor_Window[2], false) 
        showCursor(false) 
        setCameraTarget( localPlayer ) 
        setElementDimension( localPlayer, 0 ) 
        setElementFrozen ( localPlayer, false ) 
        setElementPosition ( localPlayer, unpack ( originalPosition ) ) 
        setElementAlpha ( localPlayer, 255 ) 
    elseif source == GUIEditor_Button[1] then 
        guiSetVisible( GUIEditor_Window[1], false) 
        guiSetVisible( GUIEditor_Window[2], true) 
        showCursor(true) 
    elseif source == GUIEditor_Button[4] then 
        guiSetVisible( GUIEditor_Window[1], true ) 
        guiSetVisible( GUIEditor_Window[2], false ) 
        showCursor(true) 
    elseif source == GUIEditor_Button[3] then 
        setCameraTarget( localPlayer ) 
        guiSetVisible( GUIEditor_Window[1], false ) 
        guiSetVisible( GUIEditor_Window[2], false ) 
        showCursor(false) 
        setElementDimension( localPlayer, 0 ) 
        setElementAlpha( localPlayer, 255 ) 
        local money = getPlayerMoney( localPlayer ) 
        if ( money >= 15000 ) then 
            triggerServerEvent("qtm", getLocalPlayer() ) 
            setElementModel( localPlayer, tonumber ( guiGetText ( GUIEditor_Edit[1] ) ) ) 
        else 
            outputChatBox( " Para Comprarte este skin necesitas $15000 y tu dinero es ".. money .." " ) 
        end 
    end 
end 
addEventHandler ( "onClientGUIClick", root, botton ) 
  
function destruir ( matchingDimension ) 
    if ( localPlayer and source == marker ) then 
        if isElement ( ped ) then  
            destroyElement ( ped ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerLeave", root, destruir ) 

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