Xeno Posted November 26, 2011 Share Posted November 26, 2011 function setTeam() local account = getPlayerAccount(source) local team = getAccountData (account, "team") if (team) and getTeamFromName(team) then setPlayerTeam(source, getTeamFromName(team)) end end addEventHandler("onPlayerLogin",root,setTeam) function save(player) local team = getPlayerTeam(player) local account = getPlayerAccount(player) if (team) and not isGuestAccount(account) then setAccountData(account, "team", getTeamName(team)) end end addEventHandler("onPlayerQuit", getRootElement(), save) I used this script to save teams, and I have no idea why its not working, can someone help me please? I get no errors. Link to comment
AeroXbird Posted November 26, 2011 Share Posted November 26, 2011 function setTeam() local account = getPlayerAccount(source) local team = getAccountData (account, "team") if (team) and getTeamFromName(team) then setPlayerTeam(source, getTeamFromName(team)) end end addEventHandler("onPlayerLogin",root,setTeam) function save() local team = getPlayerTeam(source) local account = getPlayerAccount(source) if (team) and not isGuestAccount(account) then setAccountData(account, "team", getTeamName(team)) end end addEventHandler("onPlayerQuit", getRootElement(), save) Make sure you read the arguments of events, onPlayerQuit does not have a player argument, the player is source. Link to comment
Xeno Posted November 26, 2011 Author Share Posted November 26, 2011 function setTeam() local account = getPlayerAccount(source) local team = getAccountData (account, "team") if (team) and getTeamFromName(team) then setPlayerTeam(source, getTeamFromName(team)) end end addEventHandler("onPlayerLogin",root,setTeam) function save() local team = getPlayerTeam(source) local account = getPlayerAccount(source) if (team) and not isGuestAccount(account) then setAccountData(account, "team", getTeamName(team)) end end addEventHandler("onPlayerQuit", getRootElement(), save) Make sure you read the arguments of events, onPlayerQuit does not have a player argument, the player is source. Ill test that nao Link to comment
Xeno Posted November 26, 2011 Author Share Posted November 26, 2011 And how would I save skin? the same but change around the functions Link to comment
unknooooown Posted November 26, 2011 Share Posted November 26, 2011 And how would I save skin? the same but change around the functions See this example. This is one way of saving the skin, for the next time the player connects. function onMapLoad () -- create our table, if it doesn't already exist executeSQLCreateTable ( "players", "clothes_head_texture TEXT, clothes_head_model TEXT, player TEXT" ) end addEventHandler ( "onGamemodeMapStart", getRootElement(), onMapLoad ) function addInfoToSQL( theSpawnpoint, theTeam ) sourcename = getPlayerName ( source ) -- get the player's name -- try to retrieve the player data from the db result = executeSQLSelect ( "players", "player", "player = '" .. sourcename .. "'" ) if ( result == false ) then -- see if any data was found at all outputChatBox ( "This is your first time here! Welcome " .. sourcename .. "!", source ) executeSQLInsert ( "players", "'none', 'none', '" .. sourcename .. "'" ) else outputChatBox ( "Welcome back " .. sourcename .. "!", source ) executeSQLUpdate ( "players", "clothes_head_texture = 'hairgreen', clothes_head_model = 'somehead'", "player = '" .. sourcename .. "'" ) end -- get the clothes data for the player result = executeSQLSelect ( "players", "clothes_head_texture, clothes_head_model", "player = '" .. sourcename .. "'" ) outputChatBox ( "Your head texture is " .. result[1][1] ) outputChatBox ( "Your head model is " .. result[1][2] ) end addEventHandler ( "onPlayerSpawn", getRootElement(), addInfoToSQL ) https://wiki.multitheftauto.com/wiki/ExecuteSQLUpdate And for getting the players current skin use. https://wiki.multitheftauto.com/wiki/GetElementModel Link to comment
Xeno Posted November 26, 2011 Author Share Posted November 26, 2011 And how would I save skin? the same but change around the functions See this example. This is one way of saving the skin, for the next time the player connects. function onMapLoad () -- create our table, if it doesn't already exist executeSQLCreateTable ( "players", "clothes_head_texture TEXT, clothes_head_model TEXT, player TEXT" ) end addEventHandler ( "onGamemodeMapStart", getRootElement(), onMapLoad ) function addInfoToSQL( theSpawnpoint, theTeam ) sourcename = getPlayerName ( source ) -- get the player's name -- try to retrieve the player data from the db result = executeSQLSelect ( "players", "player", "player = '" .. sourcename .. "'" ) if ( result == false ) then -- see if any data was found at all outputChatBox ( "This is your first time here! Welcome " .. sourcename .. "!", source ) executeSQLInsert ( "players", "'none', 'none', '" .. sourcename .. "'" ) else outputChatBox ( "Welcome back " .. sourcename .. "!", source ) executeSQLUpdate ( "players", "clothes_head_texture = 'hairgreen', clothes_head_model = 'somehead'", "player = '" .. sourcename .. "'" ) end -- get the clothes data for the player result = executeSQLSelect ( "players", "clothes_head_texture, clothes_head_model", "player = '" .. sourcename .. "'" ) outputChatBox ( "Your head texture is " .. result[1][1] ) outputChatBox ( "Your head model is " .. result[1][2] ) end addEventHandler ( "onPlayerSpawn", getRootElement(), addInfoToSQL ) https://wiki.multitheftauto.com/wiki/ExecuteSQLUpdate And for getting the players current skin use. https://wiki.multitheftauto.com/wiki/GetElementModel I swear you need a special server to use SQL? Link to comment
Xeno Posted November 26, 2011 Author Share Posted November 26, 2011 No. Oh... So I just throw it in the script and it will work? Link to comment
AeroXbird Posted November 27, 2011 Share Posted November 27, 2011 No. Oh... So I just throw it in the script and it will work? Yes, SQLite is implented into MTA, MySQL on the other hand, is not. Link to comment
Castillo Posted November 27, 2011 Share Posted November 27, 2011 The new DB functions are MySQL, aren't they? if so, they are now implemented on MTA. https://wiki.multitheftauto.com/wiki/Ser ... _functions Link to comment
50p Posted November 27, 2011 Share Posted November 27, 2011 The new DB functions are MySQL, aren't they? if so, they are now implemented on MTA.https://wiki.multitheftauto.com/wiki/Ser ... _functions In the future release though. Link to comment
Castillo Posted November 28, 2011 Share Posted November 28, 2011 Yes, that's right, but they already work in the nightly builds of 1.1. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now