Jump to content

setElementPosition doubt


Overkillz

Recommended Posts

Hey dear community, I have a little question about setElementPosition.

When I want to set a position for the vehicle using this

function changePos() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
     
    setElementPosition(vehicle, spPosX[3],spPosY[3],spPosZ[3]) 
end 
bindKey ( "1", "down", changePos ) 

it work's perfectly

but when I try to use a variable as number, it doesnt works

function changePos() 
    local currentSpawn = 3 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
     
    setElementPosition(vehicle, spPosX[currentSpawn],spPosY[currentSpawn],spPosZ[currentSpawn]) 
end 
bindKey ( "1", "down", changePos ) 

Someone could tell me the reason.

Thanks for all, regards.

Link to comment

Well, now I got a new problem now

If both guys are using the command to the same time, the variable " currentNumber " increase when it is used by anybody

local currentNumber = 1 
function setPositionasd(source) 
    local vehicle = getPedOccupiedVehicle(source) 
    if vehicle then 
        setElementPosition(vehicle, 300,500,2) 
    end 
    currentNumber = currentNumber+1 
end 
addCommandHandler("spD",setPositionasd) 

Its serverside, how can I set it using an easy way just for the local player without triggering our whatever ?

Thanks

Link to comment

I decided to use a triggerServerEvent from a client due to I cant stand tables.

I couldnt test it due to Im alone at my server, but this should only move myself and increase the variable only for me?

--## Client 
function triggerToSrv() 
    triggerServerEvent("oncgSP", getLocalPlayer(),localPlayer) 
end 
addCommandHandler("chsp",triggerToSrv) 
  
--## Server 
currentNumber = 1 
  
function chSP(source) 
    local vehicle = getPedOccupiedVehicle(source) 
    if vehicle then 
        setElementPosition(vehicle, 300,500,2) 
    end 
    currentNumber = currentNumber+1 
end 
addEvent("oncgSP",true) 
addEvent("oncgSP",getRootElement(),chSP) 

Link to comment
What the use of the variable currentNumber?

Im using a table where I have a posX, posY, and posZ, there are some values insertered and I want to move the player when he press the key 1. It is done, but the unique problem is that Im having issues increasing the value. If more than 1 players use it, the variable increase for all, and I want to increase it for one each player.

Example:

Player 1 press 2 times the key: currentNumber: 2

player 2 press 2 times the key: currentNumber: 4

player 1 press again 2 times the key: currentNumber: 6

The player 1 jumped from a number: 2 to 6.

I would like to fix it.

Link to comment
currentNumber = {} -- This on the top of the file 

currentNumber[source] = currentNumber[source] and currentNumber[source] + 1 or 1 

or

if not currentNumber[source] then 
    currentNumber[source] = 1 
else 
    currentNumber[source] = currentNumber[source] + 1 
end 

Link to comment
currentNumber = {} -- This on the top of the file 

currentNumber[source] = currentNumber[source] and currentNumber[source] + 1 or 1 

or

if not currentNumber[source] then 
    currentNumber[source] = 1 
else 
    currentNumber[source] = currentNumber[source] + 1 
end 

and to select just a player, should be the same right ?

I mean:

currentPlayer = {} 

if not currentNumber[source] then 
    currentPlayer[source] = source 
end 

to select an unique player to move later

local vehicle = getPedOccupiedVehicle(currentPlayer[source]) 

and to set the position to an unique player

setElementPosition(currentPlayer[source], posAnyX,posAnyy,posAnyz) 

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