Jump to content

LabiVila

Members
  • Posts

    272
  • Joined

  • Last visited

Posts posted by LabiVila

  1. Hello, I need some help finding a specific angle. So let me start, I want this:

    I need to get local player's rotation and display the rotation he has to do in order to be looking on the direction of the object. Like: 'you have to turn `degrees` to face the object'.

     

    I can't seem to do the right math, thank you in advance! 

  2. I just solved that by setting a timer to warpPedIntoVehicle (100 ms). I don't know why but somehow it's solved. Does it matter that I call the functions with: function () without event handlers? Maybe that messed me up earlier. I'll definitely change it to the style your style tho

  3. Hello,

    can you help me fix this part? It's the 'warpPedIntoVehicle', every time I use this I get 'Network Trouble' and I don't know why,

     

        for a, b in ipairs (getElementsByType ("player")) do
            local mySpawn = math.random (1, #mapSpawns)
            
            for c, d in ipairs (mapSpawns) do
                if (c == mySpawn) then
                    local veh = createVehicle (d.id, d.x, d.y, d.z)
                    
                    if veh then
                        outputDebugString ("created veh")
                    end
                    
                    warpPedIntoVehicle (b, veh)
                    
                    setCameraTarget (b, b)
                    fadeCamera (b, true)
                end
            end
        end

    mapSpawns is fine, I can output any value of it. And I as well get the 'created veh' from outputDebugString. Dunno what's wrong...

  4. Also, you don't need an infinite loop to run above. It's pointless doing such, since it'll only use quite some CPU and not do much.

    You can set the timer once inside the 'onVehicleExplode', would be better

  5. for _,v in ipairs (getElementsByType ("team")) do 
        guiGridListAddRow (rankinggrid, getTeamName (v)) 
    end 
      
    

    Replace all your lines above with these ones, should work. So you literally don't need to 'unpack' the table when loops like this above exist.

    EDIT: I had the page open for like 30 minutes than I replied, didn't see your comment (the guy above) x)

  6.   
    local kills = {} 
      
    addEventHandler ("onResourceStart", getRootElement(), 
        function () 
            for _,player in ipairs (getElementsByType ("player")) do 
                local account = getPlayerAccount (player) 
                local playerKills = getAccountData (account, "player.kills") 
                table.insert (kills, playerKills) 
            end 
        end 
    ) 
      
    addCommandHandler ("ranking", 
        function () 
            table.sort (kills, 
                function (a, b) 
                    return a > b 
                end 
            ) 
             
            for _,v in ipairs (kills) do 
                outputChatBox (v) --is gonna output kills from highest to lowest 
            end 
        end 
    ) 
      
    

    So firstly, you put all the players in a table (actually player's account) when the resource starts (you can change that as you wish, just an example). Once you do that, when you write /ranking the table is gonna sort and then the output with all the row as you want.

  7. So, I'll try to sum it up quickly, the advantage of OOP is that you don't have to rewrite the whole thing over and over like "normal" scripts do. Even tho OOP is much harder, once you get used to it you won't ever script in the "normal" way again.

    In the script you posted, if you turn it into OOP nothing would change but the syntax. It's the same stuff literary, but I have a very good example that progressed me very much.

    https://forum.multitheftauto.com/viewtopic.php?f ... le#p753385

    a cool example of metatables and OOPs.

  8. You can use element data to determine the player with a bounty.

    setElementData and getElementData 
    

    you can get all players in the server

    allPlayers = getPlayersCount ()  
    

    and assign a random number with

    randomplayer = math.random (1, allPlayers)  
    

    then you can do this to assign the player as bounty

    for k, player in ipairs (getElementsByType ("player")) do 
    if (k == randomplayer) then 
    setElementData (player, "bounty", true) -- or anything you like 
    end 
    end 
      
    

    Let me know for any problem

  9.   
    local players = {cars = {}, unlockedFor = {}} 
      
    addCommandHandler ("vehUser", 
    function (player) 
      
    players [player] = {} 
      
    end 
    ) 
      
    addCommandHandler ("addVehicle", 
    function (player, _, car) 
      
    for name, v in pairs (players) do 
    if (name == player) then 
    table.insert (v.cars, car) 
      
    end 
    ) 
      
    addCommandHandler ("lockFor", 
    function (player, _, otherPlayer) 
    local otherPlayer = getPlayerFromName (otherPlayer) 
      
      
    for name, v in pairs (players) do 
    if (name == player) then 
    table.insert (v.unlockedFor, otherPlayer) 
    end 
    end 
      
    end 
    ) 
      
      
    

    It looks a lot like this.

    Now you can do the 'unlockCarFor' command, opposite of the one above.

    and when a player enters the car as passager, you can loop through v.unlockedFor, see if there's a name similiar to the one that wants to enter, if yes let him enter, if no then cancelEvent

  10. You can use something like this:

    players [player] = {cars = {}} 
      
    now you can insert cars and 'carLock' like this: 
      
    table.insert (v.cars, {car, sharable = true / false }} 
      
    

  11. This should work:

    addCommandHandler("startup", function(p, cmd, suf) 
    if suf == "job" then 
        if scripter[getAccountName(getPlayerAccount(p))] then 
           for i, res in ipairs(getResources()) do 
               local resName = getResourceName(res) 
               if resName:find("Job_") then 
                  local finalRes = getResourceFromName (res) 
                  startResource(finalRes, true) 
               end 
           end 
        end 
    end 
    end) 
    

  12. or you can use this:

    addEventHandler ("onClientRender", root, 
         function () 
              dxDrawText(table.maxn (text), 654, 354, 778, 377, tocolor(255, 255, 255, 255), 1, f2, "left", "top", true, true, true, true, true) 
         end 
    ) 
    

  13. I'm not telling anyone whether if onClientPlayerJoin is wrong or not. I'm just telling him how it works. Not up to me to decide which events to use, so instead of replying me whether it's right or wrong, post the solution

  14. Try this one:

      
    addEventHandler ("onClientPlayerJoin", root, 
         function () 
              setTimer (checkTimer, 2000, 1) 
         end 
    ) 
      
    function checkTimer () 
        if not isTransferBoxActive() then 
            outputDebugString("Not visible, proceed") 
        else 
            setTimer(checkTransferBox, 2000, 1) 
            outputDebugString("Still visible, do not proceed") 
        end 
    end 
      
    

×
×
  • Create New...