Jump to content

DiSaMe

Distinguished Members
  • Posts

    1,461
  • Joined

  • Last visited

  • Days Won

    34

Posts posted by DiSaMe

  1. How do you know when you arrive at some destination? Do you calculate the distance in the beginning and then count down while walking? I doubt it, I think you're aware of the distance all the time and only stop when you see that you have arrived at the destination. So peds should work the same way, they must continuously check their position and see if they have arrived or not.

  2. ...

    getElementMatrix 
    

    You can't keep the image at the same position from the vehicle's point of view just by using position. Obviously, rotation makes difference. And matrix is the most straightforward and intuitive way to represent the rotation.

  3. You didn't say what the problem is, but it seems like you use the arguments incorrectly. 2nd argument of triggerServerEvent is the source of the event, and function arguments come after it.

    --client 
    triggerServerEvent("someEvent", someElement, "aaaa", "bbbb") 
      
    --server 
    function handlerOfSomeEvent(arg1, arg2) 
        -- 'source' is the same as 'someElement' was on the client 
        -- 'arg1' is "aaaa" 
        -- 'arg2' is "bbbb" 
    end 
    

  4. If you want to get the value from the table, then you must store it into the table first

    object_table = {} 
      
    --creating and storing the object 
    object_table[some_index] = createObject(...) 
      
    --destroying the object 
    destroyElement(object_table[some_index]) 
    object_table[some_index] = nil -- although object no longer exists, its identifier value is still there, so we assign nil to remove that value and free the memory 
    

  5. No table? Obviously, there is a table (that's how data is stored in SQL databases), and the error messages say exactly what's wrong: the table has 9 colums, therefore takes 9 values for each row, but the query string passed to 'executeSQLQuery' only has 8 values. Same with another error - there's no column 'huntersReached'. The table in the database is clearly different from the one that is specified in table creation query in this script.

    RE-Install MTA And it should work. (If its not made by you then only do it.)

    Excuse me, but that doesn't make any sense.

  6. How would I transfer information that someone placed onto a GUI(Like a text or number) to server side?
    addEvent 
    addEventHandler 
    triggerServerEvent 
    --or 
    setElementData -- element data is synced if you set it for server-side elements unless you explicitly specify not to sync it 
    

    And how can I run something multiple times without spamming the script. For example
    removeElementData(thePlayer, "hello")*2 
    

    Would run that twice.

    Bit of a a bad example but I think you get the idea. That would run that removeElementData twice and save the space/time

    Use loops

    for i = 1, 5 do 
        outputChatBox(tostring(i)) 
    end 
    

    Outputs:

    1 
    2 
    3 
    4 
    5 
    

    The code inside the loop block (therefore 'outputChatBox' too) will be executed 5 times, with different 'i' value every time.

  7. Calling 'setElementData' triggers "onElementDataChange"/"onClientElementDataChange". If these events cause 'setElementData' to be called, you get an infinite recursion. You could make a variable that stops the execution of event handler if element data is being reverted. An example:

    local revertingData 
      
    addEventHandler("onElementDataChange", root, function(dataname, oldvalue) 
        if revertingData then 
            return 
        end 
      
        revertingData = true 
        setElementData(source, dataname, oldvalue) 
        revertingData = nil 
    end) 
    

    'setElementData' call in this handler will cause the same handler to be called recursively, but the checking of 'revertingData' variable will prevent the subsequent recursive calls.

  8. And it still won't work because the parent of all markers is 'ele'. That's it, if you want to abstractly link values, so that knowing one value would allow you to get another, it's better to use tables than parent/child hierarchy.

  9. Events have 'hidden' variables, one of which is 'source' (more info about them: https://wiki.multitheftauto.com/wiki/Event_system). 'Hidden' variables are actually global variables that are set before the handler is executed and unset after it's done. Every event has source which is an element related to that event (In case of "onPlayerJoin" it's the player who joined), and if there's additional data, it's passed via function parameters.

    As for "providing parameters" in 'addEventHandler', no, you don't provide parameters when you pass the function as a value.

    -- this will call 'someFunction' and pass 'someOtherFunction' as an argument: 
    someFunction(someOtherFunction)  
      
    -- this will use the return value of 'someOtherFunction' as the argument for 'someFunction': 
    someFunction(someOtherFunction(someArgument)) 
      
    -- this has the same effect as 'someFunction(someOtherFunction(someArgument))': 
    local returnval = someOtherFunction(someArgument) 
    someFunction(returnval) 
    

    When you pass 'whenPlayerJoins' as an argument to 'addEventHandler', that means MTA will call 'whenPlayerJoins' function every time "onPlayerJoin" event is triggered. The parameters passed to the handler function depend on event. It's not so much different from what you can do in C:

    void someFunction(int (*funcPtr)(int funcArg)); 
    int (*someOtherFunction)(int funcArg); 
      
    int main() 
    { 
        someFunction(someOtherFunction); 
        return 0; 
    } 
    

    (Not sure if syntax in this example is correct)

    Basically, if you have 'someFunction' and 'someOtherFunction' defined, this will call 'someFunction', passing 'someOtherFunction' as an argument, and if 'someFunction' calls 'funcPtr', it will call the function that was provided. The difference is that C, as a low level language, requires function parameter lists to be predefined and matching (both 'funcPtr' and 'someOtherFunction' accept one integer), while Lua doesn't make it all that strict.

×
×
  • Create New...