Jump to content

Imposter

Members
  • Posts

    188
  • Joined

  • Last visited

Posts posted by Imposter

  1. Hey there, I am having trouble in finding the position of the exhaust tip of a car (where the nitrous is released from) and the getVehicleComponentPosition does NOT have the exhaust tip as a component. Help would be greatly appreciated.

    Thanks,

    Imposter.

  2. Well, you guys misunderstood, I meant, redirecting a person to a webpage by opening their browser, like Chrome. I know I could make a parser myself but that would be lengthy.

  3. Hey there,

    I am currently using the GUI Editor Resource and am experiencing problems with offsets when using the code that is outputted. As you can clearly see below, the offsets from left and right (for the children of the scrollpane) should be 10px each.

      
    GUIEditor = { 
        tab = {}, 
        staticimage = {}, 
        edit = {}, 
        tabpanel = {}, 
        label = {}, 
        button = {}, 
        scrollpane = {}, 
        gridlist = {}, 
        memo = {} 
    } 
    addEventHandler("onClientResourceStart", resourceRoot, 
        function() 
            local screenW, screenH = guiGetScreenSize() 
            GUIEditor.staticimage[1] = guiCreateStaticImage(screenW - 267 - 10, screenH - 484 - 10, 267, 484, "images/galaxys4.png", false) 
            GUIEditor.staticimage[2] = guiCreateStaticImage(20, 51, 227, 383, "images/white.png", false, GUIEditor.staticimage[1]); 
            GUIEditor.scrollpane[1] = guiCreateScrollPane(0, 0, 227, 383, false, GUIEditor.staticimage[2]) 
             
            GUIEditor.label[1] = guiCreateLabel(10, 10, 207, 43, "Email", false, GUIEditor.scrollpane[1]) 
            local font_0 = guiCreateFont(":SRR-Gamemode/fonts/srrheadfont.ttf") 
            guiSetFont(GUIEditor.label[1], font_0) 
            guiLabelSetColor(GUIEditor.label[1], 250, 195, 4) 
            guiLabelSetHorizontalAlign(GUIEditor.label[1], "center", false) 
            guiLabelSetVerticalAlign(GUIEditor.label[1], "center") 
            GUIEditor.tabpanel[1] = guiCreateTabPanel(10, 60, 207, 313, false, GUIEditor.scrollpane[1]) 
      
            GUIEditor.tab[1] = guiCreateTab("Inbox", GUIEditor.tabpanel[1]) 
      
            GUIEditor.memo[1] = guiCreateMemo(10, 114, 187, 165, "", false, GUIEditor.tab[1]) 
            GUIEditor.gridlist[1] = guiCreateGridList(9, 8, 188, 101, false, GUIEditor.tab[1]) 
            guiGridListAddColumn(GUIEditor.gridlist[1], "Subject", 0.4) 
            guiGridListAddColumn(GUIEditor.gridlist[1], "Sender", 0.4) 
      
            GUIEditor.tab[2] = guiCreateTab("Send", GUIEditor.tabpanel[1]) 
      
            GUIEditor.edit[1] = guiCreateEdit(6, 12, 191, 27, "Subject", false, GUIEditor.tab[2]) 
            GUIEditor.edit[2] = guiCreateEdit(6, 49, 191, 27, "Recipient(s) (Split by \", \")", false, GUIEditor.tab[2]) 
            GUIEditor.edit[3] = guiCreateEdit(8, 85, 189, 168, "", false, GUIEditor.tab[2]) 
            GUIEditor.button[1] = guiCreateButton(131, 259, 66, 20, "Send", false, GUIEditor.tab[2])     
        end 
    ) 
      
    

    But this is what is shown.

    cnt.png

    As you can see, the offsets are totally incorrect, and this is not what I see when designing the GUI. Is this an MTA Bug when using staticimages? I would really appreciate it if someone with knowledge of this would help me out.

    Thanks,

    NooP

  4. Sorry I took so long, I have exams. >_> Anyways, I can't get the peds to move, even the forward control state doesnt work. I need some way for the ped to look at the player and shoot him. The shooting works, but the looking doesn't (The ped doesn't rotate). Help would be greatly appreciated.

    Client.lua

      
    function setPedMoveState(thePed, theMoveState) 
        local theLastPlayer = getElementData(thePed, "theLastPlayer"); 
        if (isElement(theLastPlayer) == true) then 
            local pedX, pedY, pedZ = getElementPosition(thePed); 
            local playerX, playerY, playerZ = getElementPosition(theLastPlayer); 
            local playerRot = getElementRotation(theLastPlayer); 
            if (playerX) and (playerY) and (playerZ) then 
                if(isLineOfSightClear(playerX, playerY, playerZ, pedX, pedY, pedZ, true, false, false, true, true, false, false)) then 
                    if (theMoveState == true) then 
                        setPedLookAt(thePed, playerX, playerY, playerZ, 999999999, 200, theLastPlayer); 
                        setPedAimTarget(thePed, playerX, playerY, playerZ); 
                        setPedCameraRotation(thePed, (math.deg(math.atan2((playerX - pedX), (playerY - pedY)))) % 360); 
                        setPedControlState(thePed, "sprint", true); -- This doesn't work 
                        setPedControlState(thePed, "forward", true); -- This doesn't work 
                    end 
                else 
                    setPedControlState(thePed, "sprint", false); -- This doesn't work 
                    setPedControlState(thePed, "forward", false); -- This doesn't work 
                end 
            end 
        end 
    end 
    addEvent("setPedMoveState", true); 
    addEventHandler("setPedMoveState", getRootElement(), setPedMoveState); 
      
    function setPedShootState(thePed, theShootState) 
        local theLastPlayer = getElementData(thePed, "theLastPlayer"); 
        if (isElement(theLastPlayer) == true) then 
            setPedControlState(thePed, "fire", theShootState); 
        end 
    end 
    addEvent("setPedShootState", true); 
    addEventHandler("setPedShootState", getRootElement(), setPedShootState); 
      
    

    Server.lua

    thePeds = { 
        [0] = createPed(287, 152.85546875, 1929.802734375, 18.964239120483, 50.057220458984, true), 
        [1] = createPed(287, 160.578125, 1908.6025390625, 18.678409576416, 30.946228027344, true), 
        [2] = createPed(287, 185.9677734375, 1926.345703125, 17.759992599487, 181.6369934082, true), 
        [3] = createPed(287, 204.7578125, 1898.0029296875, 17.640625, 5.5619201660156, true), 
        [4] = createPed(287, 222.2822265625, 1897.9443359375, 17.640625, 18.388641357422, true) 
    }; 
      
    function givePedsWeapons() 
        table.foreach(thePeds, function(theIndex) 
            local thePed = thePeds[theIndex]; 
            if (thePed) then 
                giveWeapon(thePed, 31, 99999, true); 
            end 
        end); 
    end 
    addCommandHandler("gpw", givePedsWeapons); 
      
    function givePedsBrains() 
        table.foreach(thePeds, function(theIndex) 
            setTimer(function() 
                local thePed = thePeds[theIndex]; 
                if (thePed) then 
                    local theLastPlayer = getElementData(thePed, "theLastPlayer"); 
                    if (theLastPlayer) and (getElementType(theLastPlayer) == "player") then 
                        if (isPedDead(theLastPlayer) == true) then 
                            local pedX, pedY, pedZ = getElementPosition(thePed); 
                            local playerX, playerY, playerZ = getElementPosition(theLastPlayer); 
                            local theDistance = getDistanceBetweenPoints3D(pedX, pedY, pedZ, playerX, playerY, playerZ); 
                            if (theDistance <= 15) then 
                                triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                                triggerClientEvent("setPedShootState", getRootElement(), thePed, true); 
                            elseif (theDistance > 15) and (theDistance <= 25) then 
                                triggerClientEvent("setPedMoveState", getRootElement(), thePed, true); 
                                triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                            elseif (theDistance <= 50) then 
                                triggerClientEvent("setPedMoveState", getRootElement(), thePed, true); 
                                triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                            else 
                                -- Get New Player! 
                                setElementData(thePed, "theLastPlayer", nil); 
                                triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                                triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                            end 
                        else 
                            -- Get New Player! 
                            setElementData(thePed, "theLastPlayer", nil); 
                            triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                            triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                        end 
                    else 
                        for theIndex, thePlayer in ipairs(getElementsByType("player")) do 
                            if (isPedDead(thePlayer) == false) then 
                                local pedX, pedY, pedZ = getElementPosition(thePed); 
                                local playerX, playerY, playerZ = getElementPosition(thePlayer); 
                                local theDistance = getDistanceBetweenPoints3D(pedX, pedY, pedZ, playerX, playerY, playerZ); 
                                if (theDistance <= 15) then 
                                    setElementData(thePed, "theLastPlayer", thePlayer); 
                                    triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                                    triggerClientEvent("setPedShootState", getRootElement(), thePed, true); 
                                elseif (theDistance > 15) and (theDistance <= 25) then 
                                    setElementData(thePed, "theLastPlayer", thePlayer); 
                                    triggerClientEvent("setPedMoveState", getRootElement(), thePed, true); 
                                    triggerClientEvent("setPedShootState", getRootElement(), thePed, false);                                     
                                elseif (theDistance <= 50) then 
                                    triggerClientEvent("setPedMoveState", getRootElement(), thePed, true); 
                                    triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                                    setElementData(thePed, "theLastPlayer", thePlayer); 
                                else 
                                    -- Stop moving! 
                                    setElementData(thePed, "theLastPlayer", nil); 
                                    triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                                    triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                                end 
                            else 
                                -- Get New Player! 
                                setElementData(thePed, "theLastPlayer", nil); 
                                triggerClientEvent("setPedMoveState", getRootElement(), thePed, false); 
                                triggerClientEvent("setPedShootState", getRootElement(), thePed, false); 
                            end 
                        end 
                    end 
                end 
            end, 50, 0); 
        end); 
    end 
    addCommandHandler("gpb", givePedsBrains); 
    

  5. You can't set streamed audio to a certain position, as they are being streamed live and is not being recorded.

    It works when I do it with the command though.

    EDIT:

    Whatever, got it working with:

      
    thePosition = 0; 
    function updatePosition(theSeek) 
        thePosition = theSeek; 
    end 
    addEvent("updateStreamPosition", true); 
    addEventHandler("updateStreamPosition", getRootElement(), updatePosition); 
      
    function resume() 
        if (nowPlaying) then 
            outputMessage("Resuming!", "Radio"); 
            setSoundPosition(nowPlaying, thePosition); 
        end 
    end 
    addCommandHandler("resume", resume); 
      
    

  6. Help anyone?

    This works, but not in the streamAudio Event:

      
    function setSongPos(cmd, seconds) 
        local ssp = setSoundPosition(nowPlaying, seconds) 
        if ssp then 
            outputChatBox("Sound is now playing from: "..seconds.." Seconds!") 
        else 
            outputChatBox("An error has occured. Please make shore there are atleast") 
            outputChatBox(seconds.." Seconds in this song!") 
        end 
    end 
    addCommandHandler("seek", setSongPos) 
      
    

  7. I did that, but the music starts from 0.

    My Code:

    server.lua

      
    musicList = { }; 
    theBaseUrl = "http://www.indigogames.net/tmhc/music/"; 
    theStreamUrl = nil; 
    theStreamPosition = 0; 
    theStreamTimer = nil; 
      
    function outputMessage(theMessage, theObject, theClass) 
        if (theClass == nil) then 
            outputChatBox("#00C3FF[TMHC]:#E0E0E0 " .. theMessage, theObject, 255, 255, 255, true); 
        elseif (theObject == nil) then 
            outputChatBox("#00C3FF[TMHC" .. theClass .. "]:#E0E0E0 " .. theMessage, getRootElement(), 255, 255, 255, true); 
        else 
            outputChatBox("#00C3FF[TMHC-" .. theClass .. "]:#E0E0E0 " .. theMessage, getRootElement(), 255, 255, 255, true); 
        end 
    end 
      
    function onResourceStart() 
        fetchRemote("http://www.indigogames.net/tmhc/music/index.php?mode=list", parseMusicData, "", false); 
    end 
    addEventHandler("onResourceStart", resourceRoot, onResourceStart); 
      
    function onPlayerLogin() 
        triggerClientEvent("streamAudio", getRootElement(), theStreamUrl, theStreamPosition); 
    end 
    addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin); 
      
    function parseMusicData(responseData, errorNo) 
        if (errorNo == 0) then 
            if (string.len(responseData) > 0) then 
                musicList = fromJSON(responseData); 
                if (musicList == nil) then 
                    outputMessage("#FF0000A system error occurred while parsing the music list.", getRootElement(), "Radio");    
                    return false; 
                end 
            else 
                outputMessage("#FF0000A system error occurred while loading the music list.", getRootElement(), "Radio");    
                return false; 
            end 
        else 
            outputMessage("#FF0000A system error occurred while fetching the music list.", getRootElement(), "Radio");   
            return false; 
        end 
    end 
      
    function playRandomMusic(theTime) 
        setTimer(function() 
            local count = 0; 
            local randomInteger = math.random(0, table.getn(musicList)); 
            for theKey, theValue in pairs(musicList) do 
                if ((count == randomInteger) == false) then 
                    count = count + 1; 
                else 
                    beginStreaming(theValue); 
                    theStreamUrl = theBaseUrl .. theValue; 
                    theStreamPosition = 0; 
                    theStreamTimer = setTimer(function() theStreamPosition = theStreamPosition + 1 end, 1000, 0); 
                    return true; 
                end 
            end 
        end, theTime, 1); 
    end 
      
    function beginStreaming(theFileName) 
        for theKey, thePlayer in ipairs(getElementsByType("player")) do 
            triggerClientEvent("streamAudio", thePlayer, theBaseUrl .. theFileName); 
        end 
        fetchRemote("http://www.indigogames.net/tmhc/music/index.php?mode=list", parseMusicData, "", false); -- Get new list 
        fetchRemote("http://www.indigogames.net/tmhc/music/index.php?mode=info&filename=" .. theFileName, parseMusic, "", false); 
    end 
      
    function isPlayerAdmin(thePlayer) 
        if ((thePlayer) and (isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")))) then 
            return true; 
        else 
            return false; 
        end 
    end 
      
    function streamMusic(theSource, theCommand, theUrl) 
        if ((isGuestAccount(getPlayerAccount(source)) == false) and (isPlayerAdmin(source) == true)) then 
            -- FIx this if the server can do it! 
            theStreamUrl = theBaseUrl .. theValue; 
            theStreamPosition = 0; 
            theStreamTimer = setTimer(function() theStreamPosition = theStreamPosition + 1 end, 1000, 0); 
            for theKey, thePlayer in ipairs(getElementsByType("player")) do 
                triggerClientEvent("streamAudio", thePlayer, theUrl); 
            end 
            outputMessage(getPlayerName(theSource) .. " is now streaming!", getRootElement(), "Radio"); 
        end 
    end 
    addCommandHandler("stream", streamMusic); 
      
    function endStreaming(theSource, theCommand) 
        if ((isGuestAccount(getPlayerAccount(source)) == false) and (isPlayerAdmin(source) == true)) then 
            for theKey, thePlayer in ipairs(getElementsByType("player")) do 
                triggerClientEvent("endStream", thePlayer); 
            end 
            outputMessage(getPlayerName(theSource) .. "#FFFF00 has ended the radio stream!", getRootElement(), "Radio"); 
        end 
    end 
    addCommandHandler("endStream", endStreaming); 
      
    function refreshMusicList(theSource, theCommand) 
        if ((isGuestAccount(getPlayerAccount(theSource)) == false) and (isPlayerAdmin(theSource) == true)) then 
            outputMessage(getPlayerName(theSource) .. " is refreshing the music list!", getRootElement(), "Radio"); 
            fetchRemote("http://www.indigogames.net/tmhc/music/index.php?mode=list", parseMusicData, "", false); 
        end 
    end 
    addCommandHandler("refreshMusicList", refreshMusicList); 
      
    function startStream(theSource, theCommand) 
        if ((isGuestAccount(getPlayerAccount(theSource)) == false) and (isPlayerAdmin(theSource) == true)) then 
            outputMessage(getPlayerName(theSource) .. " has started the radio stream!", getRootElement(), "Radio"); 
            playRandomMusic(50); 
        end 
    end 
    addCommandHandler("startStream", startStream); 
      
    function parseMusic(responseData, errorNo) 
        local musicData = fromJSON(responseData); 
        if (musicData) then 
            outputMessage("Now playing: " .. musicData["title"] .. " by " .. musicData["artist"] .. "!", getRootElement(), "Radio"); 
            outputMessage("The next song will be played in " .. musicData["length_long"] .. "!", getRootElement(), "Radio"); 
            playRandomMusic(tonumber(musicData["length"]) * 1000 + 3000); 
        else 
            playRandomMusic(tonumber(musicData["length"]) * 1000 + 3000); 
        end 
    end 
      
    

    client.lua

      
    nowPlaying = nil; 
      
    function streamAudio(theUrl, theSeek) 
        if (nowPlaying) then 
            stopSound(nowPlaying); 
        end 
        nowPlaying = playSound(theUrl); 
        if (theSeek) then 
            setSoundPosition(nowPlaying, theSeek * 1000); 
        end 
    end 
    addEvent("streamAudio", true); 
    addEventHandler("streamAudio", getRootElement(), streamAudio); 
      
    function endStream() 
        if (nowPlaying) then 
            stopSound(nowPlaying); 
        end 
    end 
    addEvent("endStream", true); 
    addEventHandler("endStream", getRootElement(), endStream); 
      
    

  8. So I have this piece of code, when the streamAudio event is triggered, the seek/sound position is sent to the client. but my problem is, it won't set. The wiki's documentation is also wrong, it says that the setSoundPostion() function uses milliseconds, but it actually uses seconds. Any help??

    Client:

    nowPlaying = nil; 
      
    function streamAudio(theUrl, theSeek) 
        if (nowPlaying) then 
            stopSound(nowPlaying); 
        end 
        nowPlaying = playSound(theUrl); 
        if (theSeek) then 
            setSoundPosition(nowPlaying, theSeek); 
        end 
    end 
    addEvent("streamAudio", true); 
    addEventHandler("streamAudio", getRootElement(), streamAudio); 
      
    function endStream() 
        if (nowPlaying) then 
            stopSound(nowPlaying); 
        end 
    end 
    addEvent("endStream", true); 
    addEventHandler("endStream", getRootElement(), endStream); 
    

×
×
  • Create New...