Jump to content

Gordon_G

Members
  • Posts

    282
  • Joined

  • Last visited

Posts posted by Gordon_G

  1. For this you need to undestand the MTA DayZ Gamemode :

     

    The contains of inventorys and tents are defined by elementData.

     

    You'll have to use these functions :

     

    setElementData()
    getElementData()

     

    • Like 1
  2. The dbExec returns a table so, if you want to make something like this you should use :

    dbExec() -- Like in your code
    dbPoll() -- Because you need the result of your dbExec

    And you could use the '#' to count the number of lines into the returned result of your dbPoll

    If you've any other question, ask here.

  3. Damn it.

     

    Hum... You will need these function :

     

    getPlayerTeam() -- Get the player's team when he disconnect
    getTeamName() -- Because  getPlayerTeam() returns a userdata value but we need a string
    setAccountData() -- Save the player's team on quit
    
    getAccountData() -- Get  player team when he disconnected
    getTeamFromName() -- Because our account data is a string, not a userdata
    setPlayerTeam() -- Set player team when he joins
    getPlayerName() -- Take the player name
    setPlayerName() -- Add to the name the team name

     

    Ask if you have any other question.

     

    EDIT : Loki, you're too fast for me x'(

    • Like 1
  4. Hello ! I'm trying to do a script, and I need to turn the player, to a point.

    I know it will be a mathematical function, I started like this but it's not working :

     

    function turn(source)
    local x,y,z = getElementPosition(source) 
    local x1,y1,z1 = -2004.1025390625,146.181640625,27.5390625
    local Player_A = getDistanceBetweenPoints2D(x,y,0,0)
    local A_point = getDistanceBetweenPoints2D(0,0,x1,y1)
    print(A_point)
    print(Player_A)
    local rot = math.deg(math.atan(Player_A/A_point))
    print(rot)
    setElementRotation(source,0,0,rot)
    end
    addCommandHandler("turn",turn)

    Could someone help me ? Thanks ! 

  5. Hello,

    I would like to get the last updates by an xml file and write it in a memo. But ; for this I need to pass lines.

    My xml : 

    <settings>
    <news>something \n other</news>
    </settings>

    server :

    -- Server :
    
    
    
    function showNews(source)
    local settings = xmlLoadFile(":script/settings.xml")
    triggerClientEvent(source,"shownews",source,xmlNodeGetValue(xmlFindChild(settings, "news", 0)))
    end
    
    -- I made a bind a bind to this function  somewhere else in my script and it work so, it's not the problem

    client :

    -- Client :
    
    
    
    function showNews(news_)
    if news then destroyElement(news) else
    local screenW, screenH = guiGetScreenSize()
    news = guiCreateMemo((screenW - 505) / 2, (screenH - 304) / 2, 505, 304, news_, false)
    
    end
    end
    addEvent("shownews",true)
    addEventHandler("shownews",getLocalPlayer(),showNews)

    So, when I push my key who is bind, I can see the memo, I can see the text but, I would like to see it like this :

    "something 

    other"

    not like this "something \n"

     

    Thanks !

  6. I took my motivation and I did something like this to make easily colRectangle :

    col_rect = {}
    
    function colrect(source)
    x,y,z = getElementPosition(source)
    
    if col_rect.un == nil then
    table_ = {x,y}
    col_rect.un = table_
    outputChatBox("1")
    elseif col_rect.deux == nil then
    table_ = {x,y}
    outputChatBox("2")
    col_rect.deux = table_
    elseif col_rect.trois == nil then
    table_ = {x,y}
    outputChatBox("3")
    col_rect.trois = table_
    local a = getDistanceBetweenPoints2D(col_rect.un[1],col_rect.un[2],col_rect.trois[1],col_rect.trois[2])
    local b = getDistanceBetweenPoints2D(col_rect.un[1],col_rect.un[2],col_rect.deux[1],col_rect.deux[2])
    local x,y = col_rect.un[1],col_rect.un[2]
    local w = a
    local h = math.sqrt(a^2-b^2)
    
    rect__ = createColRectangle(x,y,w,h)
    print(x..","..y..","..w..","..h)
    col_rect = {}
    end 
    end
    addCommandHandler("rect",colrect)

     

    Thanks to everyone.

  7. Hello, I know the event "onRadarAreaElementEnter" do not exist but, I would like to have something like this.

    In my script I've some radar area but I cant use any colshape (because I've some negatives lenghts) or zone because my areas are not the same than the zone.

     

    Could someone find a way to have an event like "onRadarAreaElementEnter" ? Thanks a lot !

  8.   
    -- First : Make this function in your script, she's realy usefull 
      
    function table.contains(table, element) 
      for _, value in pairs(table) do 
        if value == element then 
          return true 
        end 
      end 
      return false 
    end 
      
    -- Ok now we'll define all the LSPD vehicles :  
      
    lspdv = {596, 598, 427, 601, 599, 528, 490} -- You can add or remove some value(s) by this table. 
      
    function lock (source) 
    if not isPedInVehicle(source) then 
    local x,y,z = getElementPosition(source) 
    local colshape = createColShape(x,y,z,2) -- Ok, here the colshape is not too big but it's for don't have any bug 
    local elements = getElementsWithinColShape(colshape, "vehicle") 
    destroyElement(colshape) 
    if #elements == 1 then -- So here the # is to count the number of vehicle in the colshape 
    for _,v in ipairs(elements) do 
    local model = getElementModel(v) 
    if table.contains (lspdv, model) then -- We check if the vehicle near the player is the lspdv table 
    -- Ok, here make you faction detection with "if" and after don't forget to make an end 
    local locked = isVehicleLocked ( vh  ) 
    local locked = not locked 
    setVehicleLocked(vh, locked) 
    end 
    end 
    else 
    outputChatBox("Sorry, too much vehicles / any vehicle near you.", source, 255,0,0) 
    end 
    else 
    local vh = getPedOccupiedVehicle(source) 
    local model = getElementModel(source) 
    if table.contains(lspdv, model) then 
    -- Ok, here make you faction detection with "if" and after don't forget to make an end 
    local locked = isVehicleLocked ( vh  ) 
    local locked = not locked 
    setVehicleLocked(vh, locked) 
    end 
    end 
    end 
    addCommandHandler("lock",lock) 
    

    Ok, so now, make that for the engine. We'll see if you have learn something.

    And ... You can join me by private message, I could help you ...

    veh is not defined in the first lines so it returns nil. how should I define it ?

    Also the script is not better then the previous cause with this the police can open all police cars. As example when I would add the Savanna model in grove street they could open all models.

    Mhh ... You asked something I gave you a big part of you script.

    We'll (by "we" I say the MTA's forum) not script your gamemode for you. You must be sure of that.

    And for my little error, yes.

    Replace the line 30 by this :

    setVehicleLocked(v, locked) 
    

  9. function playerCarLock(source) 
        local playeraccount = getPlayerAccount(source) 
        local fac = getAccountData(playeraccount, "Faction") or 0 
        for vehicles in pairs (pVehicle) do 
            if (tonumber(fac) == 2) then 
                if (getDistanceBetweenPoints3D(getElementPosition(vehicles), getElementPosition(source)) < 6 ) then 
                    if not (isVehicleLocked(vehicles)) then      
                        setVehicleLocked(vehicles, true) 
                    else 
                        setVehicleLocked(vehicles, false) 
                    end     
                end 
            end 
        end 
    end 
    addCommandHandler("lock", playerCarLock) 
      
    function engine(source) 
        local playeraccount = getPlayerAccount(source) 
        local fac = getAccountData(playeraccount, "Faction") or 0 
        for vehicles in pairs (pVehicle) do 
            if (getPedOccupiedVehicle(source) == vehicles) and (tonumber(fac) == 2) then 
                if (getVehicleEngineState(vehicles) == false) then 
                    setVehicleEngineState(vehicles, true) 
                else 
                    setVehicleEngineState(vehicles, false) 
                end 
            end     
        end     
    end 
    addCommandHandler("engine", engine) 
    

    If it doesn't work try to change this line:

    local pVehicle = {} 
      
    function buildPVehicle() 
        for _, v in ipairs (pVeh) do       
            table.insert(pVehicle, createVehicle(v.model, v.x, v.y, v.z, v.rx, v.ry, v.rz, v.lp)) 
            setVehicleLocked(pVehicle, false) 
            setVehicleColor(pVehicle, v.r, v.g, v.b, v.r2, v.g2, v.b2) 
        end 
    end 
    addEventHandler("onResourceStart", root, buildPVehicle) 
    

    And if afterall it doesn't work, you should wait for the answer of someone with more knowledge than me cause I'm not very experienced atall.

    I'm sorry but this is not correct.

    So, let's do something like this :

      
    -- First : Make this function in your script, she's realy usefull 
      
    function table.contains(table, element) 
      for _, value in pairs(table) do 
        if value == element then 
          return true 
        end 
      end 
      return false 
    end 
      
    -- Ok now we'll define all the LSPD vehicles :  
      
    lspdv = {596, 598, 427, 601, 599, 528, 490} -- You can add or remove some value(s) by this table. 
      
    function lock (source) 
    if not isPedInVehicle(source) then 
    local x,y,z = getElementPosition(source) 
    local colshape = createColShape(x,y,z,2) -- Ok, here the colshape is not too big but it's for don't have any bug 
    local elements = getElementsWithinColShape(colshape, "vehicle") 
    destroyElement(colshape) 
    if #elements == 1 then -- So here the # is to count the number of vehicle in the colshape 
    for _,v in ipairs(elements) do 
    local model = getElementModel(v) 
    if table.contains (lspdv, model) then -- We check if the vehicle near the player is the lspdv table 
    -- Ok, here make you faction detection with "if" and after don't forget to make an end 
    local locked = isVehicleLocked ( vh  ) 
    local locked = not locked 
    setVehicleLocked(vh, locked) 
    end 
    end 
    else 
    outputChatBox("Sorry, too much vehicles / any vehicle near you.", source, 255,0,0) 
    end 
    else 
    local vh = getPedOccupiedVehicle(source) 
    local model = getElementModel(source) 
    if table.contains(lspdv, model) then 
    -- Ok, here make you faction detection with "if" and after don't forget to make an end 
    local locked = isVehicleLocked ( vh  ) 
    local locked = not locked 
    setVehicleLocked(vh, locked) 
    end 
    end 
    end 
    addCommandHandler("lock",lock) 
    

    Ok, so now, make that for the engine. We'll see if you have learn something.

    And ... You can join me by private message, I could help you ...

  10. function MarkerHit( hitElement) 
    if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player 
    local r,g,b = getMarkerColor(source) 
    if r == 255 and g == 0 and b == 0 then -- We check the color of the marker 
    local x,y,z = getElementPosition(hitElement) -- Get the position of the player 
    if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle 
    local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table 
    warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle 
    end 
    end 
    end 
    end 
    

    I retry this this moon and, it work perfectly

    How does this even work? There is no event handling the function.

    Oh, f*ck I'm so stupid ...

    Write that after the last "end" ...

    addEventHandler( "onMarkerHit", getRootElement(), MarkerHit ) 
    

  11. function MarkerHit( hitElement) 
    if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player 
    local r,g,b = getMarkerColor(source) 
    if r == 255 and g == 0 and b == 0 then -- We check the color of the marker 
    local x,y,z = getElementPosition(hitElement) -- Get the position of the player 
    if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle 
    local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table 
    warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle 
    end 
    end 
    end 
    end 
    

    I retry this this moon and, it work perfectly

  12. function MarkerHit( hitElement) 
    if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player 
    local r,g,b = getMarkerColor(source) 
    if r == 255 and g == 0 and b == 0 then -- We check the color of the marker 
    local x,y,z = getElementPosition(hitElement) -- Get the position of the player 
    if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle 
    local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table 
    warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle 
    end 
    end 
    end 
    end 
      
    

    This code work. I just edit a little bit.

  13. Humpf ... The createBlip or createBlipAttachedTo already got the "visibleto"

      
    createBlipAttachedTo ( element elementToAttachTo [, int icon = 0, int size = 2, int r = 255, int g = 0, int b = 0, int a = 255, int ordering = 0, float visibleDistance = 99999.0, visibleTo = getRootElement( ) ] ) 
      
    

    Try something like this :

    createBlipAttachedTo(v,22,2,255,0,0,255,0,99999.0,v) 
    

    Instead of

                        
     local blip = createBlipAttachedTo(v,22) 
    for i,v in pairs(getElementsByType("player")) do 
                           local playerTeam = getTeamName(getPlayerTeam(v)) 
                           if playerTeam == "Axis" then 
                              setElementVisibleTo(blip,v,true) 
                          else 
                              setElementVisibleTo(blip,v,false) 
                          end 
                      end 
    

  14. Yes, it's possible !

      
    -- Server 
      
    function onElementModelChange () 
    if getElementModel(source) == 45 then 
    giveWeapon(source,42,10000000, true) 
    end 
    end 
    addEventHandler("onElementModelChange", root,onElementModelChange) 
      
    

    Something like that ...

  15.   
    vehiclesid = {429, 541, 480 , 411 , 565} 
      
    changermarker = createMarker(x, y, z, "typeofmarker", size,255, 0, 0, alpha) 
      
    function MarkerHit( hitElement) 
    if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player 
    if  getMarkerColor(source) == 255,0,0 then -- We check the color of the marker  
    local x,y,z = getElementPosition(hitElement) -- Get the position of the player 
    createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table 
    end 
    end 
    end 
    addEventHandler( "onMarkerHit", getRootElement() , MarkerHit) 
      
    

    I don't try this but it should work :P

×
×
  • Create New...