Jump to content

help with code


Paplo

Recommended Posts

Posted
  
-- 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:

Posted

You are using "xmlOpenFile" but the function is "xmlLoadFile".

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

in my server it work

but in server online he said

WARNING: whounban/server.lua:15 Bad 'element' pointer @ 'getElementType'(1)

?? :?:

Posted

((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); 

Posted
((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

  • Moderators
Posted

If the element(player) isn't in the server, how the hell can you get the type of it?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
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 

:!:

Posted
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 

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

Posted
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)

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