Jump to content

Crosshair

Members
  • Posts

    32
  • Joined

  • Last visited

Posts posted by Crosshair

  1. Hello all.

    Lets say some players have set an elementdata called "x" with the value "y".

    I need a function that gets all those players that have getElementdata(player, "x") == "y" and sends a outputChatBox to all of them.

    PS: I did something but i can`t test it right now since i`m the only player on the server

    local players = getElementsByType( "player" ) 
      
    for i=1,#players do 
        if (getElementData(players[i], "x") == "true") then 
            outputChatBox("test", players[i]) 
        end 
    end 
    

    Could this work ?

  2. I`m trying to make a progress bar with dxdraw. All works well but the rectangle flickers every time till the timer stops. I need help on that so the rectangle would not flicker anymore.

    local screenW, screenH = guiGetScreenSize() 
    function render() 
        if (isTimer(timer) == false) then 
            i=0 
            timer = setTimer(function() 
                dxDrawRectangle((screenW - 23) / 2-131, (screenH - 10) / 2, i, 10, tocolor(144, 3, 3, 255), true) 
                i=i+1 
            end, 50, 100) 
        end 
        removeEventHandler("onClientRender", root, render) 
    end 
    addEventHandler("onClientRender", root, render) 
    

  3. You can't declare different things with the same name.

    There is also no "plantID" variable declared.

    I just didn`t included the variable.

    Then dont use id as table index, use this:

    table.insert(plants,createObject(plantID,x,y,z)) 
    

    I make another thing right now.

    I added on the top id = 0, removed the id argument and add id=id+1 before it creates the object.

    Now if i use table.insert how do i retrieve the emelents ? with unpack ? What is the best option to do this ? Mine or yours ?

  4. Your right, but i want the player to not enter a number. Just to type plant and the plant will later rise from the ground, So i need the script to add the plant1 in the table with the first position and if he decides to add another plant(plant2) to be added also in the table with the second position.

    If i don`t use the cmd argument this works and if i use outputchatbox(plants[1]) works.

  5. Hi. I`m trying to make 2 commands that uses one command and i have some problems.

    plants = { } 
      
    function plants(thePlayer, cmd, id) 
        if (cmd == "plant") then 
            local x,y,z = getElementPosition(thePlayer) 
            plants[id] = createObject(plantID,x,y,z) 
        end 
        if (cmd == "harvest") then 
            --TODO 
        end 
             
    end 
    addCommandHandler("plant", plants) 
    addCommandHandler("harvest", plants) 
    

    When i enter the command "plant" gives me an error at plants[id] = createObject(plantID,x,y,z): table index is nill.

    If i remove the argument "cmd" from the function all works well.

  6. Hello guys.

    I tried to make a job and i run in some issues.

    function enter(thePlayer) 
        marker = createMarker(2809, -2474, 13, "cylinder", 2, 248, 211, 6, 153, thePlayer) 
        blip = createBlip(2809, -2474, 13, 0) 
        addEventHandler("onMarkerHit", marker, marcar) 
    end 
    addEventHandler ( "onVehicleEnter", getRootElement(), enter ) 
      
    function marcar(thePlayer) 
        destroyElement(marker) 
        destroyElement(blip) 
    end 
    

    I simplify the code to this. The problem is with destroyElement of course.

    Bad 'element' pointer @ 'destroyElement'(1) 
    

    marker and blip is gone but i want to get rid of this warning.

  7. How about this ?

    function sql(thePlayer) 
    team = getPlayerTeam(thePlayer) 
    teamstr = getTeamName(team) 
    local sql = mysql:query("SELECT `username` FROM `accounts` WHERE `factiune` = '"..teamstr.."'") 
        if (sql) then 
            while true do 
                row = mysql:fetch_assoc(sql) 
                if (not row) then break end 
                jucatori = row["username"] 
                triggerClientEvent(source, "factiunemeniu", getRootElement(), jucatori) 
            end 
            mysql:free_result(sql) 
        end 
    end 
    addEventHandler("onPlayerJoin", getRootElement(), sql) 
      
    

    function factiunemeniu(jucatori) 
    meniu = guiCreateWindow(233,164,600,440,"Meniu factiune",false) 
    grid = guiCreateGridList(9,29,467,379,false,meniu) 
    local nume = guiGridListAddColumn(grid,"Nume",0.2) 
    outputDebugString(jucatori) 
        for k, v in ipairs (jucatori) do 
            local row = guiGridListAddRow(grid) 
            guiGridListSetItemText(grid, row, nume, jucatori, false, false) 
        end 
    end 
    addEvent("factiunemeniu", true) 
    addEventHandler("factiunemeniu", getRootElement(), factiunemeniu) 
    

    On outputDebugString(jucatori) returns nil. In server side the debug shows

  8. You mean change

    setElementData(source, "jucatori", jucatori) 
    

    to

    setElementData(source, "jucatori", row) 
    

    ? This will give me a warning that guiGridListSetItemText expects string and not a table.

  9. Hello.

    I want to fetch some data from sql and add in the gui but is not working.

    addEvent("nume", true) 
    addEventHandler("nume", getRootElement(), function(team) 
        local teamstr = getTeamName(team) 
        local sql = mysql:query("SELECT `username` FROM `accounts` WHERE `factiune` = '"..teamstr.."'") 
        if (sql) then 
            while true do 
                local row = mysql:fetch_assoc(sql) 
                if (not row) then break end 
                local jucatori = row["username"] 
                setElementData(source, "jucatori", jucatori) 
            end 
            mysql:free_result(sql) 
        end 
    end) 
    

    if i debug row["username"] it returns all those users that has my team.

      
    grid = guiCreateGridList(9,29,467,379,false,meniu) 
    local nume = guiGridListAddColumn(grid,"Nume",0.2) 
    local team = getPlayerTeam(getLocalPlayer()) 
    if (team) then 
        local players = getPlayersInTeam(team) 
        for k, v in ipairs(players) do 
            triggerServerEvent("nume", getLocalPlayer(), team) 
            local row = guiGridListAddRow(grid) 
            guiGridListSetItemText(grid, row, nume, getElementData( localPlayer, "jucatori"), false, false) 
        end 
    end 
    

    in grid only shows one user.

  10. Hello.

    I have a question about vehicle id`s. I want to add all the vehicles in sql(add and delete in game). Adding is easy, but let`s say i want to delete a vehicle. How do i do that ? Using set/getElementData should do it, but there will be dozens of vehicles in the database. Anyone has some idea ?

  11. Hi guys, i have an issue with a marker. Guess could help me with it.

    I enter marker1, i get the job and marker2 appears. When i enter marker2 something happens.

    The problem is with marker2. It does nothing.

      
    function on_btn_join_clicked(button, state) 
        if (button ~= "left") or (state ~= "up") then 
            return 
        end 
        triggerServerEvent("jf", getLocalPlayer()) 
        local marker2= createMarker (-1208.7, -1073.8, 127.2, "cylinder", 1.5, 248, 211, 6, 153 ) 
        setElementData(localPlayer, "jobm", marker2) 
        showCursor(false) 
        guiSetVisible(fwdw, false) 
         
    end 
    [.......................] 
    function jstart(element) 
        if getElementType(element) == "player" and (element == localPlayer) then 
            outputChatBox("test") 
        end 
    end 
    addEventHandler("onClientMarkerHit", getElementData( localPlayer, "jobm"), jstart) 
      
    

    addEvent("jf", true) 
    addEventHandler("jf", getRootElement(), function() 
        mysql_query(handler, "UPDATE `lm`.`accounts` SET `jobsecundar` = '1' WHERE `accounts`.`username` = '"..getPlayerName(source).."';") 
        outputChatBox("test") 
    end) 
    

×
×
  • Create New...