Jump to content

OOP and localPlayer


syrasia

Recommended Posts

Hi there,

I am trying to use OOP where ever i can to learn it. More or less.

Nothing special:

function f4_get_pos( button, press ) 
    if button == "F4" and (press) then 
        --local x, y, z = getElementPosition(localPlayer) <--This way it works, but no oop  
        local x, y, z = localPlayer:getPosition() <-- throws the error 
        outputChatBox(x) 
        outputChatBox(y) 
        outputChatBox(z) 
    end 
end 
addEventHandler("onClientKey", getRootElement(), f4_get_pos) 

And this is the /debugscript 3 message:

attempt to index golbal 'localPlayer' (a userdata value)

How do i use oop right in this case? Do i miss somthing?

Have a N.I.C.E. day ^^

Link to comment

I had the same problem before a few days, try this:

function f4_get_pos( button, press ) 
    if button == "F4" and (press) then 
        --local x, y, z = getElementPosition(localPlayer) <--This way it works, but no oop 
        local x, y, z = localPlayer.position <-- throws the error 
        outputChatBox(x) 
        outputChatBox(y) 
        outputChatBox(z) 
    end 
end 
addEventHandler("onClientKey", getRootElement(), f4_get_pos) 

Link to comment

OOP coordinates functions do not return 3 values, it returns a Vector3 object that contains the coords:

function f4_get_pos( button, press ) 
    if button == "F4" and (press) then 
        --local x, y, z = getElementPosition(localPlayer) <--This way it works, but no oop 
        local pos = localPlayer.position <-- throws the error 
        outputChatBox(pos.x) 
        outputChatBox(pos.y) 
        outputChatBox(pos.z) 
    end 
end 
addEventHandler("onClientKey", getRootElement(), f4_get_pos) 

Make sure OOP is enabled in meta.xml.

Link to comment

Okay,

thanks for the info/tipp xeon, I looked in the oope_client wiki and found out, that the getPostion() seems to be not aviable for cliend side. The link is realy healpfull.

BTW: oop is enabled with true in meta.xml

So this is solved, ty

Link to comment
Okay,

thanks for the info/tipp xeon, I looked in the oope_client wiki and found out, that the getPostion() seems to be not aviable for cliend side. The link is realy healpfull.

BTW: oop is enabled with true in meta.xml

So this is solved, ty

2 people helped, I and you :lol::lol::lol::lol:

Link to comment
Okay,

thanks for the info/tipp xeon, I looked in the oope_client wiki and found out, that the getPostion() seems to be not aviable for cliend side. The link is realy healpfull.

BTW: oop is enabled with true in meta.xml

So this is solved, ty

Anytime :)

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