Jump to content

setElementPosition


Xwad

Recommended Posts

Hi i made this script that teleport the player to a given cordinates. But when i press f then the debug says this:

WARNING: machineGun\client.lua:31: Bad argument @ 'setElementPosition' [Expected element at argument 1, got string 'f']

WARNING: machineGun\client.lua:30: Bad argument @ 'getElementPosition' [Expected element at argument 1, got string 'f']

  
function binds()  
bindKey ( "f", "down", onEnter )  
end  
addEventHandler('onClientResourceStart', getRootElement(), binds)  
  
  
function onEnter ( localPlayer, posX, posY, posZ )  
local x,y,z = getElementPosition(localPlayer)  
setElementPosition ( localPlayer, -2422.1469, -607.8954, 132.56 ) 
end  
  

Link to comment
function binds() 
   bindKey("f", "down", onEnter) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), binds) 
  
function onEnter(posX, posY, posZ) 
    local x, y, z = getElementPosition(localPlayer) 
    setElementPosition(localPlayer, -2422.1469,  -607.8954, 132.56) 
end 

Link to comment

Try it client-side. Or if you want it on the server add the first argument to your bindKey function like says your debug. It must be player element. And it's an obvious warning, learn to read it first.

UPD: I didn't notice it's already client-side. Sorry. The solution is above, you just specified loclPlayer in bindKey handler function. Sorry again...

Link to comment

One more question. I tryed it in server but its also not working there.

debugscript:

Bad argumentum @ 'getElementPosition' [expected element at argumentum 1,got nil]

Bad argumentum @ 'setElementPosition' [expected element at argumentum 1,got nil]

Bad argumentum @ 'setElementFrozen' [expected element at argumentum 1,got nil]

server

  
function onEnter () 
    outputChatBox ( "Test" ) 
    local x, y, z = getElementPosition(thePlayer) 
    setElementPosition(thePlayer, -2422.1469,  -607.8954, 132.56) 
    setElementFrozen ( thePlayer, true ) 
end 
addEvent( "check", true ) 
addEventHandler( "check", resourceRoot, onEnter ) 
  

client

  
function binds() 
bindKey ( "e", "down", onEnter ) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), binds) 
  
  
  
  
  
function onEnter(posX, posY, posZ) 
    triggerServerEvent ( "check", resourceRoot )  
end 
  

Link to comment
function onEnter(thePlayer) 
    local x, y, z = getElementPosition(thePlayer) 
    setElementPosition(thePlayer, -2422.1469, -607.8954, 132.56) 
    setElementFrozen(thePlayer, true) 
 end 
addEvent("check", true) 
addEventHandler("check", getRootElement(), onEnter) 
  
function bind() 
    bindKey(source, "e", "down", onEnter) 
end 
addEventHandler("onPlayerLogin", getRootElement(), bind) 
  
function binds() 
    for i, v in ipairs(getElementsByType("player")) do 
        bindKey(v, "e", "down", onEnter) 
    end 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), binds) 

I wrote everything in server side

Link to comment
  • 2 months later...

Hi. Pls help me again, its not working again and theres no debugscript..:/ The triggering is working.. Its starting the server side function but the animation and the position is not working

client

  
function onEnter() 
if guiGetVisible(icon) then 
triggerServerEvent ( "onEnter", resourceRoot ) 
end 
end 
  

server

  
function onEnter ( posX, posY, posZ ) 
    local x, y, z = getElementPosition(source) 
    outputChatBox ( "Test" ) 
    setElementPosition ( source, -2377.25, -578.71, 132.75 ) 
    setPedAnimation ( source, "SILENCED", "SilenceCrouchfire", 1, false, false, false, true ) 
end 
addEvent( "onEnter", true ) 
addEventHandler( "onEnter", resourceRoot, onEnter ) 
  

Link to comment
Hi. Pls help me again, its not working again and theres no debugscript..:/ The triggering is working.. Its starting the server side function but the animation and the position is not working

client

  
function onEnter() 
if guiGetVisible(icon) then 
triggerServerEvent ( "onEnter", resourceRoot ) 
end 
end 
  

server

  
function onEnter ( posX, posY, posZ ) 
    local x, y, z = getElementPosition(source) 
    outputChatBox ( "Test" ) 
    setElementPosition ( source, -2377.25, -578.71, 132.75 ) 
    setPedAnimation ( source, "SILENCED", "SilenceCrouchfire", 1, false, false, false, true ) 
end 
addEvent( "onEnter", true ) 
addEventHandler( "onEnter", resourceRoot, onEnter ) 
  

client

  
function onEnter() 
if guiGetVisible(icon) then 
triggerServerEvent ( "onEnter", localPlayer ) 
end 
end 
  

server

  
function onEnter () 
    local x, y, z = getElementPosition(client) 
    outputChatBox ( "Test" ) 
    setElementPosition ( client, -2377.25, -578.71, 132.75 ) 
    setPedAnimation ( client, "SILENCED", "SilenceCrouchfire", 1, false, false, false, true ) 
end 
addEvent( "onEnter", true ) 
addEventHandler( "onEnter", root, onEnter ) 
  

Link to comment

One more question. Now the bind key is not working. The debugscripts says its a bad argumentum

server

  
function onEnter () 
    local x, y, z = getElementPosition(client) 
    setElementPosition ( client, -2377.25, -578.71, 132.75 ) 
    setPedAnimation ( client, "SILENCED", "SilenceCrouchfire", 1, false, false, false, true ) 
    setTimer ( fireBind, 100, 1) 
end 
addEvent( "onEnter", true ) 
addEventHandler( "onEnter", root, onEnter ) 
  
  
  
  
function fireBind ( key, player ) 
  bindKey ( player, "mouse1", "down", startFire )    
  bindKey ( player, "mouse1", "up", stopFire )     
end 
  

Link to comment

One more question. Now the bind key is not working. The debugscripts says its a bad argumentum

server

  
function onEnter () 
    local x, y, z = getElementPosition(client) 
    setElementPosition ( client, -2377.25, -578.71, 132.75 ) 
    setPedAnimation ( client, "SILENCED", "SilenceCrouchfire", 1, false, false, false, true ) 
    setTimer ( fireBind, 100, 1) 
end 
addEvent( "onEnter", true ) 
addEventHandler( "onEnter", root, onEnter ) 
  
  
  
  
function fireBind ( key, player ) 
  bindKey ( player, "mouse1", "down", startFire )    
  bindKey ( player, "mouse1", "up", stopFire )     
end 
  

Link to comment
function onEnter () 
    local x, y, z = getElementPosition(client) 
    setElementPosition ( client, -2377.25, -578.71, 132.75 ) 
    setPedAnimation ( client, "SILENCED", "SilenceCrouchfire", 1, false, false, false, true ) 
    setTimer ( fireBind, 100, 1, client ) -- you haven't put the player argument here ( for the "fireBind" function ) 
end 
addEvent( "onEnter", true ) 
addEventHandler( "onEnter", root, onEnter ) 
      
      
      
      
function fireBind ( player ) 
    bindKey ( player, "mouse1", "down", startFire )   
    bindKey ( player, "mouse1", "up", stopFire )     
end 

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