Jump to content

arezu

Members
  • Posts

    446
  • Joined

  • Last visited

Posts posted by arezu

  1. I'm not noticing anything like that in your script, or do you mean it's slow when you are turning? I think that is because your gravity is too strong. Btw, you should use onClientPreRender instead of onClientRender for the gravity and then multiply the gravity power with the 'timeSlice' parameter you get from onClientPreRender. If you dont multiply by the time slice, then the gravity will be very different depending on your fps.

  2. I used setVehicleGravity(vehicle, 0, 0, 0) and then used setElementVelocity on the vehicle in that script instead to simulate gravity, since setElementVelocity doesn't affect the camera in the same way as setVehicleGravity.

  3. Why'd you want to ignore code errors?

    If there a runtime error in the code you load with loadstring, for example trying to call a function that doesn't exist; then when you call the function returned by loadstring, the script you are running will stop execution (but mta will still call your code functions in the script, like events, binds etc).

    That means if you have code like this:

    local func = loadstring("outputChatBoxZ('hello, world!')") 
    func() 
    outputChatBox("After calling loadstring func") 
    

    then the second outputChatBox will not be called.

    But if you are using pcall:

    local func = loadstring("outputChatBoxZ('hello, world!')") 
    pcall(func) 
    outputChatBox("After calling loadstring func") 
    

    then the second outputChatBox will be called.

    You will get a chance to recover from script error. pcall also returns true or false if the script executed without any errors.

  4. The best way to do it is probably to create a command that saves data (maybe stopping work and afk resource first?) and then closes the server.

    Something like this:

    local resourcesToWaitFor = { "work", "afk" } 
    local waitingForResources = {} 
    local doShutdown = false 
      
    addCommandHandler("safeshutdown", 
    function(player) 
        outputChatBox("Safely shutting down the server...") 
         
        for k, resourceName in ipairs(resourcesToWaitFor) do 
            local resource = getResourceFromName(resourceName) 
            if(resource)then 
                waitingForResources[resource] = true 
            end 
        end 
         
        doShutdown = true 
         
        for resource, resourceWaitState in pairs(waitingForResources) do 
            stopResource(resource) 
        end 
    end, true, false) 
      
    addEventHandler("onResourceStop", root, 
    function(stoppedResource) 
        if(doShutdown and waitingForResources[stoppedResource])then 
            waitingForResources[stoppedResource] = false 
            for resource, resourceState in pairs(waitingForResources) do 
                if(resourceWaitState)then 
                    return false 
                end 
            end 
            shutdown("The server has safely been shutdown.") 
        end 
    end) 
    

    Make sure the resource has the rights to use the shutdown function, etc.

  5. Something like this if you just want to get started and might want to learn about vectors more later:

    -- "ball" is the ball element 
    -- "vehicle" is the vehicle element that collided with the ball 
      
    local x, y, z = getElementPosition(ball) 
    local x2, y2, z2 = getElementPosition(vehicle) 
    local velX, velY, velZ = getElementVelocity(vehicle) 
    local vel = math.sqrt(velX*velX + velY*velY + velZ*velZ) -- equal to getDistanceBetweenPoints3D(0, 0, 0, velX, velY, velZ) 
      
    local dirX, dirY, dirZ = x - x2, y - y2, z - z2 
    local dist = math.sqrt(dirX*dirX + dirY*dirY + dirZ*dirZ) -- equal to getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) 
    dirX, dirY, dirZ = dirX / dist, dirY / dist, dirZ / dist 
      
    -- To change velocity of the ball now, i guess you might want to do: 
    -- setElementVelocity(ball, dirX * vel, dirY * vel, dirZ * vel) 
    

    Keep in mind that this will set the velocity of the ball to the velocity of the vehicle in the direction that the ball is compared to the center of the vehicle, and that's why you might want to instead get the point of collision in onClientVehicleCollision and use that point together with vehicle position and you could then add stuff like spin to the ball as well then, but that is a bit more advanced.

  6. From downloadFile wiki page:

    If the file has been previously downloaded and the CRC matches, the file will not be downloaded again but onClientFileDownloadComplete will still run.

    In other words: downloadFile will only download the file if the file doesn't exist, or if the file exists and the content of the file does not match the content of the file you want to download.

  7. onClientClick executes twice because it executes when you press down a mouse button and when release it. The button state is the second parameter value for the callback function.

    button: This refers the button used to click on the mouse, can be left, right, or middle

    state: This can be used to tell if the user released or pressed the mouse button, where up is passed if the button is released, and down is passed if the button is pushed

    https://wiki.multitheftauto.com/wiki/OnClientClick

    You just have to check if button == "left" and state == "down" to make your function only detect a click when your left mouse button is pressed down.

  8. Don't know if you can check it on performencebrowser but you can try.

    That runs on server's performance sadly, there's no client part.

    Tick the box "include clients" and select a player and it will tell you performance information from the player (client-side performance).

  9. yeah i am already using cache to false(every client script i got)

    soo this is it? only way scripts could get stolen now as far as i see is to hack the server itself?

    No, you can use packet sniffing tools to read received packet data, but nobody who has the knowledge to do that would bother doing that and trying to deduce which encrypted strings that are received that are part of the script, and the scripts are sent in several packets so they would need to find them all and put them together.

    It would be much easier and less troublesome for them if they made the lua scripts themselves instead.

    As long as scripts are sent to client, they can always be stolen.

    Don't forget that using cache="false" will change your script load order in some situations. So keep that in mind.

    I think that was fixed.

  10. You can compile a file. It's the safest way.

    https://luac.multitheftauto.com/

    That is not enough

    luac.multitheftauto.com encrypts your file the same way packets are encrypted when you are sending data from server to client (triggerClientEvent).

    The other option is to add cache="false" in meta for script file, and it will send the file to client encrypted (just like triggerClientEvent) and load it but not save it on the clients harddrive, the exact same thing you are trying to do with triggerClientEvent + loadstring.

  11. setVehicleHandling animGroup "GetOutF" could maybe have worked, but it was disabled because

    Get works, set is disabled due to people not knowing this property was vehicle-based and caused crashes.
  12. You can just do this and it will automatically shoot forwards, and it wont collide with your vehicle either.

    function ejectProjectile() 
        local vehicle = getPedOccupiedVehicle(source) 
        if(vehicle)then 
            local x, y, z = getElementPosition(vehicle) 
            createProjectile(vehicle, 19, x, y, z) 
        end 
    end 
    

    I edited the wiki page for createProjectile for others that need it as well.

  13. Since novo hasn't updated his reply yet:

    local SCREEN_WIDTH, SCREEN_HEIGHT = guiGetScreenSize() 
      
    if(isCursorShowing())then 
        local curX, curY = getCursorPosition() 
        curX, curY = curX * SCREEN_WIDTH, curY * SCREEN_HEIGHT 
         
        -- circleCenterX and circleCenterY should be the center coordinate of your circle 
        local distance = getDistanceBetweenPoints2D(curX, curY, circleCenterX, circleCenterY) 
         
        -- circleRadius should be the distance from the center of your circle to the circle lines (border) 
        if(distance <= circleRadius)then 
            -- The cursor is inside the circle! 
        end 
    end 
    

×
×
  • Create New...