Jump to content

DiSaMe

Distinguished Members
  • Posts

    1,461
  • Joined

  • Last visited

  • Days Won

    34

Posts posted by DiSaMe

  1. Using setElementPosition without setting the 5th argument to false will reset the animation. Try something like this for speed-up:

      
    local speedmult = 0.1 
      
    addEventHandler("onClientPreRender", root, 
        function(timeslice) 
            local x, y, z = getElementPosition(ped2) 
            local vx, vy, vz = getElementVelocity(ped2) 
            local speedmult = speedmult*timeslice 
            vx, vy, vz = vx*speedmult, vy*speedmult, vz*speedmult 
            setElementPosition(ped2, x+vx, y+vy, z+vz, true) 
        end 
    ) 
    

    As you can see, it gets the velocity of the ped, multiplies it by some value (you can change the speed by editing the speedmult value) and adds it to the position, so it moves in the direction where the animations and control states make it move.

  2. Updating the table is faster than using getElementsByType every time. When you call getElementsByType, you are creating a new table and doing this every 0.3 seconds isn't efficient. When you update the table, the slowest code to execute is looping through all players and using table.remove (which also pushes all elements back by one index) and doing this when the player leaves isn't that much. So if you're after performance, update the table instead of creating a new one. By the way, it's better to use the player element as the key for the table:

    --onPlayerJoin 
    myPlayers[source] = true 
      
    --onPlayerQuit 
    myPlayers[source] = nil 
      
    --looping through all players: 
    for player in pairs(myPlayers) do 
      
    end 
    

    No need to loop through the table on quit, Lua will take care of what's needed, resulting in best performance.

  3. You can try using Lua coroutines. They are a nice way to pause the execution of function and resume it later. An example:

    function infiniteLoopFunction() 
        local lastresume = getTickCount() 
        while true do 
            --do something 
      
            if getTickCount() > lastresume+200 then 
                coroutine.yield() 
                lastresume = getTickCount() 
            end 
        end 
    end 
      
    function resumeLoopThread() 
        coroutine.resume(loopThread) 
    end 
      
    loopThread = coroutine.create(infiniteLoopFunction) 
    resumeLoopThread() 
    setTimer(resumeLoopThread, 400, 0) 
    

    This code will execute the infinite loop in the infiniteLoopFunction function, but will not cause the error. It runs the loop for 200 ms, then pauses for another 200 ms before resuming the loop again.

    More about coroutines:

    http://www.lua.org/pil/9.html

    http://lua-users.org/wiki/CoroutinesTutorial

    By the way, I used coroutines in my traffic resource to load the paths. It takes 8-9 seconds to load them on my older computer and the maximum execution time of the loop (unless you use certain functions) is 5 seconds. To avoid "too long execution" error, I put the loading code into the coroutine and the problem was solved :)

  4. Use setElementDimension client-side. For example, you can get the dimension of the local player in onClientPreRender event, check if it has changed since the last frame and if so, use setElementDimension to change the dimension of the marker to the player's dimension. Client-side dimension changes are not synced automatically, so every player can see the same marker in their own dimension.

  5. You can replace the models during the whole gameplay process. For example, if you go to one place, the model ID has some model, then if you go to another place, another model is put into the same ID slot. If you make it like this, you may have multiple different models with the same ID as long as you make sure that these models are not both visible for the player at the same time.

  6. So, you have downloaded what you need (except the ByteData, you don't need to download it, it's already included in the traffic resource). Now you have to extract these archives, override the contents of npchlc_traffic (from npchlc_traffic_0.1 archive) with the contents of paths_san_andreas_1.0 archive. Move the folders npc_hlc, server_coldata, npchlc_traffic and optionally npchlc_traffic_denctrl to the server resources folder, then start npchlc_traffic.

×
×
  • Create New...