Jump to content

help with code


Paplo

Recommended Posts

  
-- this will create the xml file in which info will be holded. 
addEventHandler ("onResourceStart", getResourceRootElement (getThisResource ()), 
     function () 
          local fileInfo = xmlCreateFile ("unbaninfo.xml", "info"); 
          assert (fileInfo, "Fail to create xml file"); 
          xmlSaveFile (fileInfo); 
          xmlUnloadFile (fileInfo); 
     end); 
  
-- this will save info about the player who connects to the server. 
addEventHandler ("onUnban", getRootElement (), 
    function ( theBan, responsibleElement ) 
        -- get player info. 
        if getElementType( responsibleElement ) then 
        local name = getPlayerName( responsibleElement ); 
        local whounban = getBanSerial(theBan) or getBanIP(theBan) 
        
        -- open the file 
        local fileInfo = xmlOpenFile ("unbaninfo.xml"); 
        
        -- create a new node for this player. 
        local node = xmlCreateChild (fileInfo, "player"); 
        
        -- save info. 
        xmlNodeSetAttribute (node, "name", name); 
        xmlNodeSetAttribute (node, "whounban", whounban); 
        
        xmlSaveFile (fileInfo); -- this will save all the changes done in the file. 
        xmlUnloadFile (fileInfo); -- close file handle. 
    end end); 

whats wrong?

if body unban he not save in file xml :oops:

Link to comment

((Not Tested))

  
-- this will create the xml file in which info will be holded. 
addEventHandler ("onResourceStart", getResourceRootElement (getThisResource ()), 
     function () 
          local fileInfo = xmlCreateFile ("unbaninfo.xml", "info"); 
          assert (fileInfo, "Fail to create xml file"); 
          xmlSaveFile (fileInfo); 
          xmlUnloadFile (fileInfo); 
     end); 
  
-- this will save info about the player who connects to the server. 
addEventHandler ("onUnban", getRootElement (), 
    function ( theBan, responsibleElement ) 
        -- get player info. 
        if responsibleElement  and getElementType( responsibleElement ) == 'player' then 
        local name = getPlayerName( responsibleElement ); 
        local whounban = getBanSerial(theBan) or getBanIP(theBan) 
        
        -- open the file 
        local fileInfo = xmlOpenFile ("unbaninfo.xml"); 
        
        -- create a new node for this player. 
        local node = xmlCreateChild (fileInfo, "player"); 
        
        -- save info. 
        xmlNodeSetAttribute (node, "name", name); 
        xmlNodeSetAttribute (node, "whounban", whounban); 
        
        xmlSaveFile (fileInfo); -- this will save all the changes done in the file. 
        xmlUnloadFile (fileInfo); -- close file handle. 
    end end); 

Link to comment
((Not Tested))
  
-- this will create the xml file in which info will be holded. 
addEventHandler ("onResourceStart", getResourceRootElement (getThisResource ()), 
     function () 
          local fileInfo = xmlCreateFile ("unbaninfo.xml", "info"); 
          assert (fileInfo, "Fail to create xml file"); 
          xmlSaveFile (fileInfo); 
          xmlUnloadFile (fileInfo); 
     end); 
  
-- this will save info about the player who connects to the server. 
addEventHandler ("onUnban", getRootElement (), 
    function ( theBan, responsibleElement ) 
        -- get player info. 
        if responsibleElement  and getElementType( responsibleElement ) == 'player' then 
        local name = getPlayerName( responsibleElement ); 
        local whounban = getBanSerial(theBan) or getBanIP(theBan) 
        
        -- open the file 
        local fileInfo = xmlOpenFile ("unbaninfo.xml"); 
        
        -- create a new node for this player. 
        local node = xmlCreateChild (fileInfo, "player"); 
        
        -- save info. 
        xmlNodeSetAttribute (node, "name", name); 
        xmlNodeSetAttribute (node, "whounban", whounban); 
        
        xmlSaveFile (fileInfo); -- this will save all the changes done in the file. 
        xmlUnloadFile (fileInfo); -- close file handle. 
    end end); 

not work

Link to comment
If the element(player) isn't in the server, how the hell can you get the type of it?
    if getElementType( responsibleElement ) then --Check if a player unbanned the IP/Serial 

:!:

the getElementType returns a element's type, not a boolean. change it to;

if ( getelementType ( responsibleElement ) == "player" ) then 

Link to comment
If the element(player) isn't in the server, how the hell can you get the type of it?
    if getElementType( responsibleElement ) then --Check if a player unbanned the IP/Serial 

the getElementType returns a element's type, not a boolean. change it to;

if ( getelementType ( responsibleElement ) == "player" ) then 

     addEventHandler ("onResourceStart", getResourceRootElement (getThisResource ()), 
     function () 
          local fileInfo = xmlCreateFile ("unbaninfo.xml", "info"); 
          assert (fileInfo, "Fail to create xml file"); 
          xmlSaveFile (fileInfo); 
          xmlUnloadFile (fileInfo); 
     end); 
  
addEventHandler ("onUnban", getRootElement (), 
    function ( theBan, responsibleElement ) 
if ( getelementType ( responsibleElement ) == "player" ) then 
        local name = getPlayerName( responsibleElement ); 
        local whounban = getBanSerial(theBan) or getBanIP(theBan) 
        local fileInfo = xmlLoadFile ("unbaninfo.xml"); 
        -- create a new node for this player. 
        local node = xmlCreateChild (fileInfo, "player"); 
        -- save info. 
        xmlNodeSetAttribute (node, "name", name); 
        xmlNodeSetAttribute (node, "whounban", whounban); 
        xmlSaveFile (fileInfo); -- this will save all the changes done in the file. 
        xmlUnloadFile (fileInfo); -- close file handle. 
     end end ); 

ERROR:whounban/server.lua:11:attempt to call global'getelemetType'(a nil value)

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