Jump to content

help with script[SOLVED]


Kenix

Recommended Posts

 function create_tables() 
    executeSQLCreateTable ( "users", "user STRING, health INT,  armor FLOAT, money INT, x FLOAT, y FLOAT, z FLOAT, wanted INT, skin INT, dim INT, int INT, r INT, g INT, b INT, jailtime INT" ) 
end 
addEventHandler("onResourceStart",resourceRoot,create_tables) 
  
function save_general() 
    local health = getElementHealth(source) 
    local Armor = getPedArmor(source) 
    local money = getPlayerMoney(source) 
    local x,y,z = getElementPosition(source) 
    local wanted = getPlayerWantedLevel(source) 
    local skin = getElementModel(source) 
    local dim = getElementDimension (source) 
    local int = getElementInterior (source) 
    local r, g, b = getPlayerNametagColor ( source ) 
    local playername = getPlayerName ( source ) 
    local jailtime = getElementData(source,"jailtime")   
    executeSQLUpdate( "users", "user = '" .. getAccountName( getPlayerAccount( source ) ) .. "', health = '" .. health .. "', armor = '" .. armor .. "', money = '" .. money .. "', x = '" .. x .. "', y = '"..y.."'z = '" .. z .."',wanted = '".. wanted .."',skin = '".. skin .."',dim = '".. dim .. "',int = '".. int .."',r = '".. r .. "',g = '".. g .."',b = '".. b ..  "',jailtime = '".. jailtime .."'") 
end 
addEventHandler("onPlayerQuit",root,save_general) 
  
  
  
function save_setData() 
    local userTable = executeSQLSelect ( "users", "user","user = '" .. getAccountName( getPlayerAccount( source ) ) .. "'", "health", "armor", "money", "x", "y", "z", "wanted","skin","dim","int","r","g","b","jailtime" ) 
    setElementHealth(source,userTable[3]) 
    setPedArmor(source,userTable[4]) 
    setPlayerMoney(source,userTable[5]) 
    setElementPosition( source, userTable[6], userTable[7], userTable[8] ) 
    setPlayerWantedLevel(source,userTable[9]) 
    setElementModel(source,userTable[10]) 
    setElementDimension (source,userTable[11]) 
    setElementInterior (source,userTable[12]) 
    setPlayerNametagColor ( source, userTable[13], userTable[14], userTable[15] ) 
    setElementData(source,"jailtime",userTable[16) 
end 
addEventHandler( "onPlayerLogin", root, save_setData ) 
  

Debug says on login:

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:26: Bad argument @ 'setElementHealth'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:27: Bad argument @ 'setPedArmor'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:28: Bad argument @ 'setPlayerMoney'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:29: Bad argument @ 'setElementPosition'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:30: Bad argument @ 'setPlayerWantedLevel'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:31: Bad argument @ 'setElementModel'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:32: Bad argument @ 'setElementDimension'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:33: Bad argument @ 'setElementInterior'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:34: Bad argument @ 'setPlayerNametagColor'

thx in advance :)

Edited by Guest
Link to comment

executeSQLSelect returns 2-dimensional table. You are using 1-dimensional table.

So try this one:

  
     function create_tables() 
        executeSQLCreateTable ( "users", "user STRING, health INT,  armor FLOAT, money INT, x FLOAT, y FLOAT, z FLOAT, wanted INT, skin INT, dim INT, int INT, r INT, g INT, b INT, jailtime INT" ) 
    end 
    addEventHandler("onResourceStart",resourceRoot,create_tables) 
      
    function save_general() 
        local health = getElementHealth(source) 
        local Armor = getPedArmor(source) 
        local money = getPlayerMoney(source) 
        local x,y,z = getElementPosition(source) 
        local wanted = getPlayerWantedLevel(source) 
        local skin = getElementModel(source) 
        local dim = getElementDimension (source) 
        local int = getElementInterior (source) 
        local r, g, b = getPlayerNametagColor ( source ) 
        local playername = getPlayerName ( source ) 
        local jailtime = getElementData(source,"jailtime")  
        executeSQLUpdate( "users", "user = '" .. getAccountName( getPlayerAccount( source ) ) .. "', health = '" .. health .. "', armor = '" .. armor .. "', money = '" .. money .. "', x = '" .. x .. "', y = '"..y.."'z = '" .. z .."',wanted = '".. wanted .."',skin = '".. skin .."',dim = '".. dim .. "',int = '".. int .."',r = '".. r .. "',g = '".. g .."',b = '".. b ..  "',jailtime = '".. jailtime .."'") 
    end 
    addEventHandler("onPlayerQuit",root,save_general) 
      
      
      
    function save_setData() 
        local userTable = executeSQLSelect ( "users", "user","user = '" .. getAccountName( getPlayerAccount( source ) ) .. "'", "health", "armor", "money", "x", "y", "z", "wanted","skin","dim","int","r","g","b","jailtime" ) 
        setElementHealth(source,userTable[1][3]) 
        setPedArmor(source,userTable[1][4]) 
        setPlayerMoney(source,userTable[1][5]) 
        setElementPosition( source, userTable[1][6], userTable[1][7], userTable[1][8] ) 
        setPlayerWantedLevel(source,userTable[1][9]) 
        setElementModel(source,userTable[1][10]) 
        setElementDimension (source,userTable[1][11]) 
        setElementInterior (source,userTable[1][12]) 
        setPlayerNametagColor ( source, userTable[1][13], userTable[1][14], userTable[1][15] ) 
        setElementData(source,"jailtime",userTable[1][16) 
    end 
    addEventHandler( "onPlayerLogin", root, save_setData ) 
      
  

Link to comment
not working

i check database not adding data

First you must insert something in table. Use executeSQLInsert when creating account.

So i create it

it work adding data.

but

Debug says on login:

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:26: Bad argument @ 'setElementHealth'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:27: Bad argument @ 'setPedArmor'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:28: Bad argument @ 'setPlayerMoney'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:29: Bad argument @ 'setElementPosition'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:30: Bad argument @ 'setPlayerWantedLevel'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:31: Bad argument @ 'setElementModel'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:32: Bad argument @ 'setElementDimension'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:33: Bad argument @ 'setElementInterior'

[2011-08-24 11:29:54] WARNING: save_system\account_s.lua:34: Bad argument @ 'setPlayerNametagColor'

Link to comment

Try:

function save_setData() 
    local userTable = executeSQLSelect ( "users", "*","user = '" .. getAccountName( getPlayerAccount( source ) ) .. "'") 
    setElementHealth(source,userTable[1]['health']) 
    setPedArmor(source,userTable[1]['armor']) 
    setPlayerMoney(source,userTable[1]['money']) 
    setElementPosition( source, userTable[1]['x'], userTable[1]['y'], userTable[1]['z']) 
    setPlayerWantedLevel(source,userTable[1]['wanted']) 
    setElementModel(source,userTable[1]['skin']) 
    setElementDimension (source,userTable[1]['dim']) 
    setElementInterior (source,userTable[1]['int']) 
    setPlayerNametagColor ( source, userTable[1]['r'], userTable[1]['g'], userTable[1]['b'] ) 
    setElementData(source,"jailtime",userTable[1]['jailtime']) 
end 
addEventHandler( "onPlayerLogin", root, save_setData ) 

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