Jump to content

Bartje

Members
  • Posts

    17
  • Joined

  • Last visited

Posts posted by Bartje

  1. I am not entirely sure, but it seems like you are trying to bind the keys to the server instead of the player. Maybe you are looking for another eventHandler.

    What about:

    addEventHandler ( "onPlayerJoin", getRootElement(), bindTheKeys )

     

    • Like 1
  2. Hi,

    Is it possible to check the aiming status of a player? When you have a weapon like a 'tec-9' and you aim backwards, you will lose your aimcontrol and your player just aims up. Is it possible to check if the player is in this upwards aiming state?

    Take a look the image below to see what I mean. The second image is the state that I want to check.

    Y8EgfWN.png

    Thanks!

  3. 10 minutes ago, The_GTA said:

    Thank you for posting the code. So let me summarize what I understand:

    • no matter what state of the V zoom, you want things to spawn at the same position
    • the problem is that if your camera zooms out the object is closed to the player than what you want
    • you probably want an offset starting from the player and not from the camera position

    So what about this code? I have changed line 3 from csx, csy, csz to x, y, z + 0.5 ...

    
    local x, y, z = getElementPosition(player)
    local direction = Vector3(ctx - csx, cty - csy, ctz - csz);
    direction:normalize();
    local start_x, start_y, start_z = interpolate_position( x, y, z + 0.5, direction, 10 );
    local object = createObject ( 1600, start_x, start_y, start_z)
    

     

     

    Lol, this is it! Thank you once again.

  4. Not exactly sure what your question is. But I do believe this topic could help you out: 

    Check out 'myonlake's' reply on it. He draws a colshape on the players position and warps all vehicle within that range to his location.
    You could use this code as well but instead of warping the vehicles, you could do other things with them like opening or closing the doors.

    Is this what you were looking for?

    • Like 1
  5. 1 hour ago, The_GTA said:

    Could you please show your code? I cannot help you based purely on explanation because your implementation does matter for error detection.

    Sure. The current code looks like this now:

    local x, y, z = getElementPosition(player)
    local direction = Vector3(ctx - csx, cty - csy, ctz - csz);
    direction:normalize();
    local start_x, start_y, start_z = interpolate_position( csx, csy, csz, direction, 10 );
    local object = createObject ( 1600, start_x, start_y, start_z)

    So the problem that I have now is that '10' should be relative instead of a static number. I played around with some calculations to get it, but I can't seem to figure it out.

  6. 17 minutes ago, The_GTA said:

    Maybe you want to spawn an object in front of the player instead? Then you need to use different mathematics: the element matrix. I recommend you a read of the wiki article about MTA's matrix implementation. But here is some sample code.

    I think it's a bit more complicated. The part with the start distance actually does half the trick in my situation. Based on the zoom level which you can toggle with 'V', the position has to be set. So using a static number will give different offsets from the player when you use different zoom levels.

    As you can see in the picture below. Both fish are at a different offset from the player because they were spawned with different camera views. That is the problem I am running into at the moment.

     

     rR1ksrb.jpg

  7. On 25/03/2020 at 23:56, The_GTA said:

    Explanation: the direction is defined as the normal vector of the difference between two 3D points. You can subtract the start 3D vector from the target 3D vector to get the difference between two 3D points.

    Hi again. So I wanted to tweak the part a little. The moving part is working great. The object is moving into the direction where my camera is looking at. However, I want to create the object first just in front of the player (where the camera is looking at). I came as far as getting the object right on top of the player. but it should have some distance. Mathematics is not my strongest skill.

    What I've got right now, is the following:

    local x, y, z = getElementPosition(player)
    local csx, csy, csz, ctx, cty, ctz = getCameraMatrix();
    local object = createObject ( 1600, ctx + (x - ctx), cty + (y - cty) , ctz + (z - ctz) )

    So the above code makes the object spawn directly at the players' position. How can I give a little offset, let's say 1 meter towards the direction of where I am looking at?

  8. 11 hours ago, The_GTA said:

    Since there is no serverside physics simulation you really should do the hit detection on the clientside. You have to take physics depending on player framerate into account which is impossible to do on the server. Thus the client has to trigger a server event to tell the server about a projectile hit.

    I hope you see that anything involving game physics is doomed from a security point of view. But that is why we have anti-cheat detection systems built into the MTA system so do not worry. ?

    Exactly what I wanted to hear! Thanks!

  9. Hi again!

    Thank you so much. I used some of this to make my part work. So that's awesome.

    Another quick question that you may have the answer to: So I am making this 'projectile' kind of thing. When it hits the player, I reduce the target's health and eventually kill it.
    I am firing the setElementHealth on the serverside as I thought this would be more 'secure'. I do believe that client side would be more efficient.

    With my background of webdeveloping, I would still handle this on the server-side to prevent hackers or bug-abusers. What are your thoughts on this? 

  10. Hi,

    So I think I have kind of a difficult one here. 

    Is it possible to move an object towards the players camera look at? I am creating the object in front of the player and I then want to move it in the camera direction with a certain speed (not a destination). Actually just like projectiles work, but then for objects.
    I have a feeling that the 'moveObject' function is not going to work here.

    Any ideas or examples on how to do this?

    Thanks!

  11. Hi!

    Oh my. This entire code was inside a client script, so it wouldn't have worked either way!?  It is obvious now.

    1 hour ago, The_GTA said:

    Did you know about the script debug output? If you look into the server console then it should tell you which line is at fault and maybe which function got you an error

    Didn't know about this. I thought the server console was showing all errors.

    So I can start this debugging by typing for example: 'debugscript 3' in the in-game console, correct?

     

    Thanks for making clear that I was mixing up client and server functionality!

  12. Hi,

    So I am trying to do something simple again. In my experience with other coding languages, this should work. However, here it does not.
    I am creating a marker near my position when entering a command. At that moment I want to bind a new hit event that triggers a function. The function does not trigger for some reason.

    Is there something I am missing here?

    function createTheMarker (  )
        local x, y, z = getElementPosition(localPlayer)
        local theMarker = createMarker ( x, y+5, z, "cylinder", 1.5, 255, 255, 0, 170 )
        addEventHandler( "onMarkerHit", theMarker, markerTriggered )
    end
    addCommandHandler ( "create", createTheMarker )
    
    function markerTriggered (  ) 
        outputServerLog ( 'hit' )
    end 

     

    Thanks!

  13. 5 minutes ago, The_GTA said:
    • line 4: fromJSON(toJSON(query)) ? really? ? Why don't you just use ipairs? In case query is false then you just check for that error condition before the loop.
    • if your token is a key to the accounts table then you can improve it to...

    Hehehe this is, definitely not final. Still learning all the Lua basics so I've been playing around to get things to work.

    Thanks for your help. Everything seems clear to me now.

    • Like 1
  14. 33 minutes ago, The_GTA said:

    I recommend a read of the wiki's event system info for the full details. But in your case the "root" means to listen to the "updateMoney" event triggers on all elements in the MTA element tree. Thus if you were to execute...

    Alright. So I've got it to work and tested it on two clients at the same time. Works fine. But I still wonder if there is any way to improve this. My currently working code is as followed:

     

    server-1.Lua

    triggerEvent ("updateMoney", client, token)


    server-2.Lua

    function updateMoneyHandler(token)
        local query =  exports.mysql:_Query("select gold from accounts where token = ?", token)
        local gold = 0
        for rid, row in ipairs (fromJSON(toJSON(query))) do
            gold = row['gold']
        end
        triggerClientEvent ("updateMoneyClient", source, gold)
    end
    addEvent("updateMoney",true)
    addEventHandler("updateMoney",root ,updateMoneyHandler)

    Especially this part is what I am worried about. the 'root' seems to overkill to me, but I still can't find another way to get this to work.

     

    client.Lua

    function updateMoneyClientHandler(gold)
        setPlayerMoney(tonumber(gold))
    end
    
    addEvent("updateMoneyClient",true)
    addEventHandler("updateMoneyClient", localPlayer, updateMoneyClientHandler)

     

     

  15. Thanks! I used to play MTA way back. I have a full time job as a front-end web developer and saw this as a nice opportunity to play around.

    Setting the playermoney works now with your solution, thanks for that. I also just found out there is a server-side setPlayerMoney function as well.

    About the player element. I changed my first trigger to:

    triggerEvent ("updateMoney", client)

    In the following code, what would root be in this case?

    function updateMoneyHandler(token)
      
        triggerClientEvent ("updateMoneyClient", source, 1000)
    end
    addEvent("updateMoney",true)
    addEventHandler("updateMoney",root,updateMoneyHandler)

    Should I change this to resourceRoot instead?

  16. Hi all, 

    Just started Lua scripting and I am already running into something I do not quite understand. I am trying to set the player's money after logging in.
    I am not getting any warnings or errors, but the players' money does not get updated for some reason. This is what I tried:

    On a successful login I trigger an event which I have in another server file:

    triggerEvent ("updateMoney", root)

    In my other server file I have the function:

    function updateMoneyHandler(token)
        triggerClientEvent ("updateMoneyClient", source, 1000)
    end
    addEvent("updateMoney",true)
    addEventHandler("updateMoney",root,updateMoneyHandler)

    So I try to set the user's money to 1000 by sending it to the client. This is my client file:

    function updateMoneyClientHandler(gold)
        setPlayerMoney(source, tonumber(gold))
    end
    
    addEvent("updateMoneyClient",true)
    addEventHandler("updateMoneyClient", root, updateMoneyClientHandler)

    All functions are actually being called as I tried to put an outputchatbox in it. Money just isn't updating.

    So what am I missing here? I assume I am doing something wrong with the baseElement as I do not quite understand them yet.

    Thanks in advance.

×
×
  • Create New...