Jump to content

[Help me]Radar Save Position


denny199

Recommended Posts

Hi there i got a small question i was making a own radar but now i got a problem how can i save the gui position

my code:

I wont give evrything cause u don't need it.

local screenWidth,screenHeight = guiGetScreenSize() 
local sx,sy = guiGetScreenSize() 
local posx = sy * 0.0600 
local posy = sy * 0.585 
local height = sy * 0.322 
  
  
-- u don't need anything here 
local centerleft = posx + height / 2 
local centertop = posy + height / 2 
local blipsize = height / 16 
local huntersizex = height / 9 
local huntersizey = height / 7 
local lpsize = height / 8 
local range = 120 
  
  
  
  
 --gui stuff 
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Scrollbar = {} 
  
GUIEditor_Window[1] = guiCreateWindow(147,378,487,364,"Advanced Radar By Denz",false) 
guiSetAlpha(GUIEditor_Window[1],1) 
guiWindowSetMovable(GUIEditor_Window[1],true) 
  
GUIEditor_Button[1] = guiCreateButton(14,254,202,43,"Radar On",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(274,253,197,43,"Radar Off",false,GUIEditor_Window[1]) 
  
GUIEditor_Label[1] = guiCreateLabel(94,220,303,35,"Radar is: ..status..",false,GUIEditor_Window[1]) 
  
guiLabelSetVerticalAlign(GUIEditor_Label[1],"center") 
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"center",false) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
  
GUIEditor_Scrollbar[1] = guiCreateScrollBar(63,61,413,30,true,false,GUIEditor_Window[1]) 
GUIEditor_Scrollbar[2] = guiCreateScrollBar(63,127,413,30,true,false,GUIEditor_Window[1]) 
    guiSetProperty(GUIEditor_Scrollbar[2],"StepSize",0.1/19.5) 
  
    guiSetProperty(GUIEditor_Scrollbar[1],"StepSize",0.1/19.5) 
  
GUIEditor_Label[2] = guiCreateLabel(20,30,450,25,"Move it to:",false,GUIEditor_Window[1]) 
GUIEditor_Label[3] = guiCreateLabel(13,64,54,29,"Up/Down",false,GUIEditor_Window[1]) 
guiLabelSetVerticalAlign(GUIEditor_Label[3],"center") 
guiLabelSetHorizontalAlign(GUIEditor_Label[3],"center",false) 
GUIEditor_Label[4] = guiCreateLabel(10,127,54,29,"Left/Right",false,GUIEditor_Window[1]) 
guiLabelSetVerticalAlign(GUIEditor_Label[4],"center") 
guiLabelSetHorizontalAlign(GUIEditor_Label[4],"center",false) 
GUIEditor_Label[5] = guiCreateLabel(196,165,105,37,"Size Off The Radar",false,GUIEditor_Window[1]) 
guiSetFont(GUIEditor_Label[5],"default-bold-small") 
  
  
GUIEditor_Scrollbar[3] = guiCreateScrollBar(17,188,461,33,true,false,GUIEditor_Window[1]) 
guiSetEnabled ( GUIEditor_Button[1], false ) 
  
GUIEditor_Button[3] = guiCreateButton(18,308,445,47,"Close",false,GUIEditor_Window[1]) 
  
guiSetVisible ( GUIEditor_Window[1], false ) 
  
  
function onScroll3() 
height = sy * (guiScrollBarGetScrollPosition(source)*0.01) 
centerleft = posx + height / 2 
centertop = posy + height / 2 
end 
addEventHandler("onClientGUIScroll",GUIEditor_Scrollbar[3],onScroll3) 
  
function onScroll2() 
posx = sy * (guiScrollBarGetScrollPosition(source)*0.01) 
    --outputChatBox(tostring(guiScrollBarGetScrollPosition(source)*0.01)) 
centerleft = posx + height / 2 
centertop = posy + height / 2 
end 
addEventHandler("onClientGUIScroll",GUIEditor_Scrollbar[2],onScroll2) 
  
function onScroll() 
posy = sy * (guiScrollBarGetScrollPosition(source)*0.01) 
centerleft = posx + height / 2 
centertop = posy + height / 2 
    --outputChatBox(tostring(guiScrollBarGetScrollPosition(source)*0.01)) 
end 
addEventHandler("onClientGUIScroll",GUIEditor_Scrollbar[1],onScroll) 
  
-- here goes the radar stuff u don't need this 
--here is the guiclick event. 
  
addEventHandler("onClientGUIClick",getRootElement(), 
function (player) 
   if (source == GUIEditor_Button[3]) then 
   guiSetVisible (GUIEditor_Window[1],false) 
   outputChatBox ("Radar Changed, Pres F3 to change it.",225,0,0) 
   showCursor (false) 
   elseif (source == GUIEditor_Button[1]) then 
   money = getPlayerMoney (source) 
   if (money < 0) then 
   outputChatBox ("error contact denz",225,0,0) 
   else 
   player = getLocalPlayer() 
guiSetEnabled ( GUIEditor_Button[1], false ) 
guiSetEnabled ( GUIEditor_Button[2], true ) 
addEventHandler("onClientRender", getRootElement(), renderit ) 
addEventHandler("onClientRender",root,renderFrame) 
   end 
   elseif (source == GUIEditor_Button[2]) then 
   money = getPlayerMoney (source) 
   if (money < 0) then 
   outputChatBox ("error contact denz",225,0,0) 
   else 
   player = getLocalPlayer() 
guiSetEnabled ( GUIEditor_Button[2], false ) 
guiSetEnabled ( GUIEditor_Button[1], true ) 
removeEventHandler("onClientRender", getRootElement(), renderit ) 
removeEventHandler("onClientRender",root,renderFrame) 
   end 
  end 
end) 
  
  

but i want to save the HEIGHT and posY and posX off the radar. but dunno how to start

Example. i pres close it saves the position and the height off the radar when i rejoin it's still that size

Link to comment

i never worked with xml files but this should be learned if i made it,

questions:

-Must I create onmyself a xml file with accounts or useing xmlcreateFile

-How can i import the saved things

-how save the positions? [ gimme just the function ]

caus i'm not understanding much about the xml at the moment

Link to comment

This is a simple example of how to save data with XML:

function saveDataToXML(dataName, dataValue) 
    local xmlFile = xmlLoadFile ("userdata.xml") -- Try to load the XML file. 
    local saved = false 
    if (not xmlFile) then -- If the file couldn't be loaded .. 
        xmlFile = xmlCreateFile("userdata.xml", "data") -- We create the XML file. 
    end 
    if (dataName and dataName ~= "") then -- If dataName and dataName is not "" then.. 
        local dataNode = xmlFindChild (xmlFile, dataName, 0) -- We try to load the child with that name. 
        if (not dataNode) then -- If the child doesn't exists .. 
            dataNode = xmlCreateChild(xmlFile, dataName) -- We create the child with that name. 
        end 
        if xmlNodeSetValue (dataNode, tostring(dataValue) or "") then -- If we successfully set the child data to .. 
            saved = true -- set 'saved' variable to true. 
        else 
            saved = false -- else set it to false. 
        end 
    else 
        saved = false -- If dataName was nil or was "" then we set 'saved' variable to false. 
    end 
    if (xmlFile) then -- If the XML file was loaded.. 
        xmlSaveFile(xmlFile) -- We save the XML file and then .. 
        xmlUnloadFile (xmlFile) -- We unload the XML file. 
    end 
    return saved -- We return the 'saved' variable. 
end 
  
function loadDataFromXML(dataName) 
    local xmlFile = xmlLoadFile ("userdata.xml")  -- Try to load the XML file. 
    local loaded = false 
    if (not xmlFile) then -- If the file couldn't be loaded .. 
        xmlFile = xmlCreateFile("userdata.xml", "data") -- We create the XML file. 
    end 
    if (dataName and dataName ~= "") then -- If dataName and dataName is not "" then.. 
        local dataNode = xmlFindChild (xmlFile, dataName, 0) -- We try to load the child with that name. 
        if (dataNode) then -- If the child exists .. 
            loaded = xmlNodeGetValue(dataNode) -- We set 'loaded' variable with the value obtained. 
        else 
            loaded = false -- else we set it to false. 
        end 
    else 
        loaded = false -- If dataName was nil or was "" then we set 'loaded' variable to false. 
    end 
    if (xmlFile) then -- If the XML file was loaded.. 
        xmlUnloadFile (xmlFile) -- We unload the XML file. 
    end 
    return loaded -- We return the 'loaded' variable. 
end 
  
addCommandHandler("save", 
    function (cmd, dataName, dataValue) 
        if saveDataToXML(dataName, dataValue) then 
            outputChatBox(tostring(dataName) ..": ".. tostring(dataValue) or "") 
        end 
    end 
) 
  
addCommandHandler("load", 
    function (cmd, dataName) 
        local data = loadDataFromXML(dataName) 
        if data then 
            outputChatBox(tostring(dataName) ..": ".. tostring(data) or "") 
        end 
    end 
) 

commands:

/save

/load

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...