Jump to content

Hadif

Members
  • Posts

    73
  • Joined

  • Last visited

Posts posted by Hadif

  1. addEvent("onRaceStateChanging",true) 
    addEventHandler("onRaceStateChanging", getRootElement(), 
        function(newState, oldState) 
            if (newState == "GridCountdown") then 
                addEventHandler("onPlayerVehicleEnter", getRootElement(), setPlayerVehicle) -- don't add () 
            end 
        end 
    ) 
      
    function setPlayerVehicle(player) 
     local vehicle = getPedOccupiedVehicle(player) 
      if isPedInVehicle(player) then -- check if ped in vehicle 
        if getElementModel(vehicle) then 
            setElementModel(vehicle, 400) -- Test 
            outputChatBox("setPlayerVehicle") 
        end 
    end 
    end 
    

    idk but should work

    Not working :(

  2. I think this should work, but..

    addEvent("onRaceStateChanging") 
    addEventHandler("onRaceStateChanging", getRootElement(), 
        function(newState, oldState) 
            if (newState == "GridCountdown") then 
                addEventHandler("onPlayerVehicleEnter", getRootElement(), setPlayerVehicle()) 
            end 
        end 
    ) 
      
    function setPlayerVehicle(player) 
        local vehicle = getPedOccupiedVehicle(player) 
        if getElementModel(vehicle) then 
            setElementModel(vehicle, 400) -- Test 
            outputChatBox("setPlayerVehicle") 
        end 
    end 
    

    I get an error,

    11: Bad Argument @ 'getPedOccupiedVehicle' [expected ped at argument 1, got nil] 
    12: Bad Argument @ 'getElementModel' [expected element at argument 1, got boolean] 
    5: Bad Argument @ 'addEventHandler' [expected function at argument 3, got none] 
    

  3. addEvent('onMapStarting') 
    addEventHandler('onMapStarting', root, function() 
     for index, vehicle in pairs(getElementsByType('vehicle')) do 
      setElementModel(vehicle, 411) 
     end 
    end) 
    

    Not working bro, I have made a new one but i got an error:

    addEventHandler("onResourceStart", getRootElement(), 
        function() 
            setPlayerVehicle(startedResource) 
        end 
    ) 
      
    function setPlayerVehicle(startedResource) 
        -- gamemodes="race" type="map" 
        local gamemodes = getResourceInfo(startedResource, "gamemodes") 
        local types = getResourceInfo(startedResource, "type") 
        if (gamemodes == "race") and (types == "map") then 
            for index, vehicle in pairs(getElementsByType("vehicle")) do 
                setElementModel(vehicle, 409) 
            end 
        end 
    end 
    

  4. Just the username or what...? Look up the XML writing functions on the MTA Wiki, there's plenty of information on how to read and write using those functions.

    If you plan to store passwords as well, I suggest you do some research on password encryption. Storing password as plaintext is a terrible idea. :)

    Then you simply store the account username in the XML file once they register an account. You'll need to write your own register function.

    I'll try!

  5. Thanks, that example works but.. I have another problem, when I click and try to type, the character appears in both edit field. How do I solve this?

    addEventHandler("onClientRender", getRootElement(), 
        function() 
            panelLogin() 
        end 
    ) 
      
    local font = {"title", "subtitle", "display", "button"} 
    ... 
    font["display"] = dxCreateFont("file/ttf/roboto-regular.ttf", 9) 
    ... 
    local word = {"username", "password"} 
    word["username"] = "" 
    word["password"] = "" 
      
    function panelLogin() 
        ... 
        local display = {} 
        ... 
        display[5] = dxDrawText(word["username"], 603, 366, 843, 382, tocolor(255, 255, 255, 255), 1.00, font["display"], "left", "center", false, false, false, false, false) 
        display[6] = dxDrawText(word["password"], 603, 392, 843, 408, tocolor(255, 255, 255, 255), 1.00, font["display"], "left", "center", false, false, false, false, false) 
        ... 
    end 
      
    function isMouseInPosition(absoluteX, absoluteY, screenW, screenH) 
        if (not isCursorShowing()) then 
            return false 
        end 
        local screenX, screenY = guiGetScreenSize() 
        local cursorX, cursorY = getCursorPosition() 
        local cursorX, cursorY = (cursorX * screenX), (cursorY * screenY) 
        if (cursorX >= absoluteX and cursorX <= absoluteX + screenW) and (cursorY >= absoluteY and cursorY <= absoluteY + screenH) then 
            return true 
        else 
            return false 
        end 
    end 
      
    addEventHandler("onClientClick", getRootElement(), 
        function() 
            onClientClickEditPassword() 
            onClientClickEditUsername() 
        end 
    ) 
      
    function onClientClickEditUsername() 
        if isMouseInPosition(603, 366, 240, 16) then 
            addEventHandler("onClientCharacter", getRootElement(), onClientEditUsername) 
        end 
    end 
      
    function onClientEditUsername(character) 
        word["username"] = word["username"]..character 
    end 
      
    function onClientClickEditPassword() 
        if isMouseInPosition(603, 366, 240, 16) then 
            addEventHandler("onClientCharacter", getRootElement(), onClientEditPassword) 
        end 
    end 
      
    function onClientEditPassword(character) 
        word["password"] = word["password"]..character 
    end 
    

    And by the way, how do I simplify the function? I think that my edit field will have a lot in my script and I don't want to repeat the script, there must be the way to make it own function, any help will be appreciate. Thank you for your time, may god bless your kindness and make you more genius!

  6.   
    addEventHandler ("onClientResourceStart", getRootElement(), 
    function () 
    local word = "" 
    showCursor (true) 
    end 
    ) 
      
    function isMouseInPosition ( x, y, width, height ) 
        if ( not isCursorShowing ( ) ) then 
            return false 
        end 
      
        local sx, sy = guiGetScreenSize ( ) 
        local cx, cy = getCursorPosition ( ) 
        local cx, cy = ( cx * sx ), ( cy * sy ) 
        if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then 
            return true 
        else 
            return false 
        end 
    end 
      
    function drawing () 
        dxDrawRectangle (300, 300, 200, 100, tocolor (255, 255, 255)) 
        dxDrawText (word, 310, 305, 200, 100, tocolor (255, 255, 255)) 
    end 
    addEventHandler ("onClientRender", getRootElement(), drawing) 
      
    addEventHandler ("onClientClick", getRootElement(), 
        function () 
            if isMouseInPosition (300, 300, 200, 100) then 
                outputChatBox ("You have clicked the rectangle, start writing") 
                addEventHandler ("onClientCharacter", getRootElement(), writeInBox) 
            end 
        end 
    ) 
      
    function writeInBox (key) 
        word = word .. key 
    end 
      
    

    It is somehow like this

    This example works without edit nothing?

  7. Using guiGetText wouldn't really make a proper edit box. You can do it one this way, you declare an empty string, so you have to get mouse's position, if mouse is within the specified rectangle, and it clicks, then you start using onClientCharacter, which would look like this:
      
    addEventHandler ("onClientCharacter", getRootElement(), 
    function (key) 
    yourstring = yourstring .. key 
    end 
    ) 
      
    

    then draw the text with onclientrender, this is the way I do it

    I guess this way is what I want, but... Can you explain more? :D

  8.         function onDeleteCharacter() 
        if editBoxState == true then 
            textEdited = string.sub(textEdited,1,string.len(textEdited)-1) 
        end 
    end 
    bindKey("backspace", "down", onDeleteCharacter) 
    function onEditCharacter(character) 
        if editBoxState == true then 
            local count =  string.len(textEdited) 
            if count < 23 then 
                textEdited = textEdited..character 
            end 
        end 
    end 
    addEventHandler("onClientCharacter", getRootElement(), onEditCharacter) 
    

    u just add to add ur variable textEdited on ur dxDrawText and make your click state (focus on edit box)

    More explanation pls, it looks useful!

  9. local deathTimer 
      
    function theLocator ( ) 
        local allLocations = { 
        "Las Venturas", 
        "San Fierro", 
        "Whetstone", 
        "Flint County", 
        "Red County", 
        "Los Santos" 
        } 
        local allPlayers = getElementsByType ( "player" ) 
        local allVehicles = getElementsByType ( "vehicle" ) 
        for index, thePlayer in ipairs ( allPlayers ) do 
            local theLocation = getElementZoneName ( thePlayer, true ) 
            for index, allLocations in ipairs ( allLocations ) do 
                if ( theLocation == allLocations ) then 
                    if not isTimer(deathTimer) then 
                        deathTimer = setTimer(killPed, 10000, 1, thePlayer ) 
                    end 
                else 
                    if isTimer(deathTimer) then 
                        killTimer(deathTimer) 
                    end 
                end 
            end 
        end 
        for index, theVehicle in ipairs ( allVehicles ) do 
            local theLocation = getElementZoneName ( theVehicle, true ) 
            for index, allLocations in ipairs ( allLocations ) do 
                if ( theLocation == allLocations ) then 
                    if not isTimer(deathTimer) then 
                        deathTimer = setTimer(blowVehicle, 10000, 1, theVehicle ) 
                    end 
                else 
                    if isTimer(deathTimer) then 
                        killTimer(deathTimer) 
                    end 
                end 
            end 
        end 
    end 
    

    Not working... :(

  10. Hello guys! I need to modify my script, I want to get times remaining. Example: If player get out from Tierra Robada and Bone County for 10 seconds, that player will be kill or vehicle will be explode. Any help will be appreciate!

    Script:

    addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource ( ) ), 
        function ( ) 
            startLocator ( ) 
        end 
    ) 
      
    function theLocator ( ) 
        local allLocations = { 
        "Las Venturas", 
        "San Fierro", 
        "Whetstone", 
        "Flint County", 
        "Red County", 
        "Los Santos" 
        } 
        local allPlayers = getElementsByType ( "player" ) 
        local allVehicles = getElementsByType ( "vehicle" ) 
        for index, thePlayer in ipairs ( allPlayers ) do 
            local theLocation = getElementZoneName ( thePlayer, true ) 
            for index, allLocations in ipairs ( allLocations ) do 
                if ( theLocation == allLocations ) then 
                    killPed ( thePlayer ) 
                end 
            end 
        end 
        for index, theVehicle in ipairs ( allVehicles ) do 
            local theLocation = getElementZoneName ( theVehicle, true ) 
            for index, allLocations in ipairs ( allLocations ) do 
                if ( theLocation == allLocations ) then 
                    blowVehicle ( theVehicle ) 
                end 
            end 
        end 
    end 
      
    function startLocator ( ) 
        setTimer ( theLocator, 50, 0 ) 
    end 
    

  11. source is not defined in setPlayerSpawn, you need to add it as an argument.
    addEventHandler ( "onPlayerLogin", getRootElement ( ), 
        function ( ) 
            setPlayerSpawn (source ) 
        end 
    ) 
      
    function setPlayerSpawn ( player ) 
        setPlayerSpawnPosition ( player ) 
    end 
      
    function setPlayerSpawnPosition ( player ) 
        local positions = { 
        { -894.90002, 1963, 0.6, 14 }, 
        { -893.40002, 1963.4, 60.6, 14 }, 
        { -891.79999, 1963.8, 60.6, 14 } 
        } 
        local randomize = math.random ( 1, #positions ) 
        spawnPlayer ( player, positions [ randomize ] [ 1 ], positions [ randomize ] [ 2 ], positions [ randomize ] [ 3 ], positions [ randomize ] [ 4 ] ) 
    end 
    

    Are you sure? Ill try this later. Anyway, thanks for your help.

×
×
  • Create New...