Jump to content

setElementPosition


Xwad

Recommended Posts

Posted

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  
  

Posted
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 

Posted

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

Posted

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 
  

Posted
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

Posted

no I dont want it in server. I want to make with triggerServerEvent. But then its always saying me bad argumentum! MY good i have always problems with argumentums!

Posted
no I dont want it in server. I want to make with triggerServerEvent. But then its always saying me bad argumentum! MY good i have always problems with argumentums!

Then change 'thePlayer' argument to 'source' on the server.

  • 2 months later...
Posted

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 ) 
  

Posted
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 ) 
  

Posted

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 
  

Posted

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 
  

Posted
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 

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