Jump to content

set object position


Castillo

Recommended Posts

hey there, i got a problem, i want to create a object, all worked fine in client side but nobody see the object but me so i made it server side and here is the problem, i used onClientRender and getElementPosition getElementRotation to set his pos and rot like mine, the problem is that i dont know how to trigger from server to client to use onClientRender. i also tried using setTimer but all fucks up and dosnt work like i want.

Link to comment
i think its better that you use onClientTrigger, and onServerTrigger,

make the function (to move it, if its only for 1 player i dont prefer it) in client side,

and the object in server side ;)

I need to create the object server side cause i want all to see it, then move it with onClientRender.

Link to comment

yeah

make 2 files,

1 client

1 server

on server you make the object on server,

and add the code:

triggerClientEvent(playerSource,"move",getRootElement(),getRootElement());

((thx castillo))

and your function on client will be called "move"

Link to comment

this is what i got,

server side:

function move(playerSource)
local xx,yy,zz = getElementRotation (playerSource)
setElementRotation(ob,xx,yy,zz+85)
end
 
function trigger(playerSource,ob)
triggerClientEvent(playerSource,"move",getRootElement(),ob)
setTimer(move, 50, 0, playerSource)
end
addCommandHandler ("m", trigger)

client side:

local g_Root = getRootElement()
local g_ResRoot = getResourceRootElement(getThisResource())
local g_Me = getLocalPlayer()
 
addEvent("move", true)
function startMove()
addEventHandler("onClientRender", g_Root, onRender)
end
addEventHandler("move", g_ResRoot, startMove)
 
function onRender(ob)	
local x,y,z getElementPosition(g_Me)
setElementPosition(ob, x,y,z)
end

warning: bad argument setElementPosition.

Link to comment

its bad idea to get player position and rotation and trigger event every frame to server just to move one object..

it will be huge amount of bandwidth

and its just stupid to send it to the server then server send it back to clients

you can just get position of player server side and moving object server side

or if you really want to make it "smooth" (it won't be smooth anyway)

just create same object on every client, and then every client should move this object according to one selected player (pass this player with triggerClientEvent)

Link to comment
its bad idea to get player position and rotation and trigger event every frame to server just to move one object..

it will be huge amount of bandwidth

and its just stupid to send it to the server then server send it back to clients

you can just get position of player server side and moving object server side

or if you really want to make it "smooth" (it won't be smooth anyway)

just create same object on every client, and then every client should move this object according to one selected player (pass this player with triggerClientEvent)

I ve done this,

function move(playerSource)
local x,y,z = getElementPosition(playerSource)
local xx,yy,zz = getElementRotation (playerSource)
setElementRotation(ob,xx,yy,zz+85)
setElementPosition (ob,x,y,z)
end
 
function timer(playerSource)
setTimer(move, 50, 0, playerSource)
end
addCommandHandler ("m", timer)

only problem its that timer isnt that fast like onClientRender :P

Link to comment

or if you really want to make it "smooth" (it won't be smooth anyway)

just create same object on every client, and then every client should move this object according to one selected player (pass this player with triggerClientEvent)

It's not necessary to create the object on every client. It can be server-side object and player ID could be stored as element data. Only setting element position and rotation needs to be client-side.

Link to comment
only problem its that timer isnt that fast like onClientRender :P

oh, right.. forgot that server doesnt have "onRender" or something..

but you can do something like that:

function move(playerSource)
local x,y,z = getElementPosition(playerSource)
local xx,yy,zz = getElementRotation (playerSource)
setElementRotation(ob,xx,yy,zz+85)
setElementPosition (ob,x,y,z)
end
 
function loop(playerSource)
setTimer(move, 50, 0, playerSource)
end
 
function timer(playerSource)
setTimer(loop, 50, 0, playerSource)
setTimer(loop, 60, 0, playerSource)
setTimer(loop, 70, 0, playerSource)
setTimer(loop, 80, 0, playerSource)
setTimer(loop, 90, 0, playerSource)
end
addCommandHandler ("m", timer)

with this it will be 10ms instead of 50 :P

Link to comment

varez, i believe this is a much more effective way:

function move(playerSource)
local x,y,z = getElementPosition(playerSource)
local x2,y2,z2 = getElementRotation (playerSource)
setElementRotation(ob,x2,y2,z2+85)
setElementPosition (ob,x,y,z)
end
 
function loop(playerSource)
setTimer(move, 50, 0, playerSource)
end
 
function timer(playerSource)
for i = 50, 90, 10 do
setTimer(loop, i, 1, playerSource)
end
end
addCommandHandler ("m", timer)

That seems more resource-friendly, and more clean in my point of view.

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