Jump to content

announcements


ahmedo01

Recommended Posts

i am making announcements system. announcements.xml

<announcements> 
    <ANNOUNCEMENT day="01" month="01" year="2014" announcement="Hey Guys"></ANNOUNCEMENT> 
</announcements> 
  

this is server file:

  
function addannouncement(day, month, year, announcement) 
xml = xmlLoadFile ( ":CGlogin/announcements.xml" ) 
child = xmlCreateChild ( xml, "ANNOUNCEMENT" ) 
xmlNodeSetAttribute ( child, "day", day) 
xmlNodeSetAttribute ( child, "month", month) 
xmlNodeSetAttribute ( child, "year", year) 
xmlNodeSetAttribute ( child, "announcement", announcement ) 
xmlSaveFile ( xml ) 
  
end 
addEvent("addannouncement", true) 
addEventHandler("addannouncement", getRootElement(), addannouncement) 
  
  

it's working but when i add announcement it likes Hey Guys . i am maked gui for this.

this is client side file :

  
GUIEditor = { 
    label = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        addannouncementwindow = guiCreateWindow(460, 207, 379, 398, "Add Announcement", false) 
        guiWindowSetSizable(addannouncementwindow, false) 
        guiSetProperty(addannouncementwindow, "CaptionColour", "FFFF0000") 
  
        GUIEditor.label[1] = guiCreateLabel(15, 33, 59, 19, "Day:", false, addannouncementwindow) 
        GUIEditor.label[2] = guiCreateLabel(124, 33, 59, 19, "Month:", false, addannouncementwindow) 
        GUIEditor.label[3] = guiCreateLabel(243, 33, 59, 19, "Year:", false, addannouncementwindow) 
        day = guiCreateEdit(43, 32, 75, 20, "", false, addannouncementwindow) 
        month = guiCreateEdit(163, 32, 75, 20, "", false, addannouncementwindow) 
        year = guiCreateEdit(275, 32, 75, 20, "", false, addannouncementwindow) 
        announcement = guiCreateMemo(9, 75, 360, 261, "", false, addannouncementwindow) 
        GUIEditor.label[4] = guiCreateLabel(134, 57, 119, 18, "Your Announcement", false, addannouncementwindow) 
        guiLabelSetColor(GUIEditor.label[4], 255, 0, 0) 
        button = guiCreateButton(135, 345, 108, 43, "Add Announcement", false, addannouncementwindow) 
        guiSetVisible(addannouncementwindow, false) 
         
        addEventHandler ( "onClientGUIClick", button, 
        function() 
        day = guiGetText ( day ) 
        month = guiGetText ( month ) 
        year = guiGetText ( year ) 
        announcement = guiGetText ( announcement ) 
        triggerServerEvent("addannouncement", getRootElement(), day, month, year, announcement) 
        end 
        , false ) 
        --dana 
         
         
  
end 
) 
function opengui(thePlayer) 
guiSetVisible(addannouncementwindow, true) 
showCursor(true) 
end 
addCommandHandler("addannouncement", opengui) 
  
  

i need this announcements in memo

i have memo but how i can list announcements in memo? like this:

in memo:

  
06/08/2014 Removed Hydra. 
05/08/2014 Testing system. 
  

sorry for my bad english ( very bad )

Link to comment

i do this for list. command for testing.

function memoannouncement() 
xml = xmlLoadFile ( ":CGlogin/announcements.xml" ) 
children = xmlNodeGetChildren (xml) 
--day = xmlNodeGetAttribute ( unpack(children), "day" ) 
--month = xmlNodeGetAttribute ( unpack(children), "month" ) 
--year = xmlNodeGetAttribute ( unpack(children), "year" ) 
--announcement = xmlNodeGetAttribute ( unpack(children), "announcement" ) 
attr = xmlNodeGetAttributes (unpack(children)) 
for day,month,year,announcement in ipairs(attr) do 
outputChatBox(day..month..year..announcement) 
end 
end 
addCommandHandler("testmemo", memoannouncement) 

when i say testmemo no debugscript error and warning but not working.

and

i have problem with this

function time() 
local time = getRealTime() 
local gun = time.monthday 
outputChatBox(gun) 
end 
addCommandHandler("times",time) 
function addannouncement(announcement) 
local time = getRealTime() 
xml = xmlLoadFile ( ":CGlogin/announcements.xml" ) 
child = xmlCreateChild ( xml, "ANNOUNCEMENT" ) 
xmlNodeSetAttribute ( child, "day", time.monthday) 
xmlNodeSetAttribute ( child, "month", 1+time.month) 
xmlNodeSetAttribute ( child, "year", 1900+time.year) 
xmlNodeSetAttribute ( child, "announcement", announcement ) 
xmlSaveFile ( xml ) 
outputChatBox("Correct Syntax: /addannouncement day month year announcement", thePlayer) 
outputChatBox("Example: /addannouncement 01 01 2000 Removed Hydras", thePlayer) 
end 
addEvent("addannouncement", true) 
addEventHandler("addannouncement", getRootElement(), addannouncement) 
--addCommandHandler("addannouncement", addannouncement) 
  

this server file

and this is client side file

  
GUIEditor = { 
    label = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        addannouncementwindow = guiCreateWindow(460, 207, 379, 398, "Add Announcement", false) 
        guiWindowSetSizable(addannouncementwindow, false) 
        guiSetProperty(addannouncementwindow, "CaptionColour", "FFFF0000") 
  
        GUIEditor.label[1] = guiCreateLabel(15, 33, 59, 19, "Day:", false, addannouncementwindow) 
        GUIEditor.label[2] = guiCreateLabel(124, 33, 59, 19, "Month:", false, addannouncementwindow) 
        GUIEditor.label[3] = guiCreateLabel(243, 33, 59, 19, "Year:", false, addannouncementwindow) 
        day = guiCreateEdit(43, 32, 75, 20, "", false, addannouncementwindow) 
        month = guiCreateEdit(163, 32, 75, 20, "", false, addannouncementwindow) 
        year = guiCreateEdit(275, 32, 75, 20, "", false, addannouncementwindow) 
        guiSetEnabled ( day, false ) 
        guiSetEnabled ( month, false ) 
        guiSetEnabled ( year, false ) 
        announcement = guiCreateMemo(9, 75, 360, 261, "", false, addannouncementwindow) 
        GUIEditor.label[4] = guiCreateLabel(134, 57, 119, 18, "Your Announcement", false, addannouncementwindow) 
        guiLabelSetColor(GUIEditor.label[4], 255, 0, 0) 
        button = guiCreateButton(135, 345, 108, 43, "Add Announcement", false, addannouncementwindow) 
        guiSetVisible(addannouncementwindow, false) 
         
        addEventHandler ( "onClientGUIClick", button, 
        function() 
        announcement = guiGetText ( announcement ) 
        triggerServerEvent("addannouncement", getRootElement(),announcement) 
        end 
        , false ) 
        --dana 
         
         
  
end 
) 
function opengui(thePlayer) 
guiSetVisible(addannouncementwindow, true) 
showCursor(true) 
end 
addCommandHandler("addannouncement", opengui) 
  
  

when i add announcement i see this in xml

<ANNOUNCEMENT day="7" month="8" year="2014" announcement="Test"></ANNOUNCEMENT> 

what is ?

how i can delete this?

Link to comment
function memoannouncement(tPlayer) 
    xml = xmlLoadFile ( ":CGlogin/announcements.xml" ) 
    if (xml ~= false) then --If loading the file wasn't failed, then: 
        children = xmlNodeGetChildren(xml) 
        for placeNumber, childrenData in ipairs(children) do --Loop through all childs in the XML file. 
            attr = xmlNodeGetAttributes(childrenData) --Get all attributes with values 
            for attributeData, valueData in pairs(attr) do --For every attribute, do: 
                outputChatBox(attributeData..": "..valueData, tPlayer) 
            end 
        end 
    else 
        outputChatBox("Error loading announcements files", tPlayer) 
    end 
end 
addCommandHandler("testmemo", memoannouncement) 

'xmlNodeGetAttributes' returns a table of arrays/keys(?). Also this needs to be looped through with 'pairs' and not with 'ipairs'. 'xmlNodeGetChildren' needs to be looped though with 'ipairs', because this code returns a table with indexes.

I think you are using this server-side, otherwise, remove ", tPlayer".

Made this 'start' for you, now you can make your script further from here.

--

XML doesn't 'support' those signs :roll:

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...