FWCentral Posted September 5, 2011 Share Posted September 5, 2011 Hey im trying to save player teams so when a player disconnects and reconnect they will be in the team. Here is the functions i used: local team = getAccountData (theCurrentAccount, "team") if (team) then setPlayerTeam(source, team) --and local team = getPlayerTeam(source) if (team) then setAccountData(account, "team", team) and it doesn't work, All the other things save using the same sort of way as above e.g position and sking esc but this wont Link to comment
JR10 Posted September 5, 2011 Share Posted September 5, 2011 local team = getAccountData (theCurrentAccount, "team") if (team) then setPlayerTeam(source, getTeamFromName ( team )) --and local team = getPlayerTeam(source) if (team) then setAccountData(account, "team", getTeamName ( team )) Link to comment
bandi94 Posted September 5, 2011 Share Posted September 5, 2011 (edited) funtion setTeam(player) local account = getPlayerAccount(player) local team = getAccountData (account, "team") if (team) then setPlayerTeam(player, team) end end addEventHandler("onPlayerJoin",root,setTeam) function save(player) local team = getPlayerTeam(player) if (team) then setAccountData(account, "team", team) end end addCommandHandler("saveteam",save) Edited September 5, 2011 by Guest Link to comment
JR10 Posted September 5, 2011 Share Posted September 5, 2011 bandi, his problem isn't that, he already did this, and the code he posted is just the functions he used. As he said. I faced problems before with saving the team, but when I used names, it got solved. Link to comment
bandi94 Posted September 5, 2011 Share Posted September 5, 2011 yes i think your problem was on saving team onPlayerQuit for my autoteam i use onPlayerQuit getTeam to check the player's in that team to delet team or not and it returns BadArgument getPlayerTeam Link to comment
Castillo Posted September 5, 2011 Share Posted September 5, 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 addCommandHandler("saveteam",save) Try that, should work. Link to comment
FWCentral Posted September 5, 2011 Author Share Posted September 5, 2011 Hey sorry i did send a reply before saying thanks JR10, I didn't notice i wasn't logged in anyways it works now it was the name in the saving of the team that was the error. Link to comment
FWCentral Posted September 5, 2011 Author Share Posted September 5, 2011 Didn't want to start a new topic so i decided to post here. I got another problem, I want to set the players blip to the color of the players team so i tried editing the playerblips resource to do that but the problem is it just sets the players blip to red and i dno why here's the code: -- needs configurable blip colors, and team support root = getRootElement () r, g, b = getTeamColor( getTeamFromName(getPlayerTeam( root )) ) -- i added this color = { r, g, b } -- changed this players = {} resourceRoot = getResourceRootElement ( getThisResource () ) function onResourceStart ( resource ) for id, player in ipairs( getElementsByType ( "player" ) ) do if ( players[player] ) then createBlipAttachedTo ( player, 0, 2, color[r], color[g], color[b] ) else createBlipAttachedTo ( player, 0, 2, color[r], color[g], color[b] ) end end end function onPlayerSpawn ( spawnpoint ) if ( players[source] ) then createBlipAttachedTo ( source, 0, 2, players[source][1], players[source][2], players[source][3] ) else createBlipAttachedTo ( source, 0, 2, color[r], color[g], color[b] ) --and this end end function onPlayerQuit () destroyBlipsAttachedTo ( source ) end function onPlayerWasted ( totalammo, killer, killerweapon ) destroyBlipsAttachedTo ( source ) end function setBlipsColor ( source, commandName, r, g, b ) if ( tonumber ( b ) ) then color = { tonumber ( r ), tonumber ( g ), tonumber ( b ) } for id, player in ipairs( getElementsByType ( "player" ) ) do destroyBlipsAttachedTo ( player ) if ( players[player] ) then createBlipAttachedTo ( player, 0, 2, players[source][1], players[source][2], players[source][3] ) else createBlipAttachedTo ( player, 0, 2, color[r], color[g], color[b] ) -- and this end end end end function setBlipColor ( source, commandName, r, g, b ) if ( tonumber ( b ) ) then destroyBlipsAttachedTo ( source ) players[source] = { tonumber ( r ), tonumber ( g ), tonumber ( b ) } createBlipAttachedTo ( source, 0, 2, players[source][1], players[source][2], players[source][3] ) end end addCommandHandler ( "setblipscolor", setBlipsColor ) addCommandHandler ( "setblipcolor", setBlipColor ) addEventHandler ( "onResourceStart", resourceRoot, onResourceStart ) addEventHandler ( "onPlayerSpawn", root, onPlayerSpawn ) addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) addEventHandler ( "onPlayerWasted", root, onPlayerWasted ) function destroyBlipsAttachedTo(player) local attached = getAttachedElements ( player ) if ( attached ) then for k,element in ipairs(attached) do if getElementType ( element ) == "blip" then destroyElement ( element ) end end end end Link to comment
SDK Posted September 5, 2011 Share Posted September 5, 2011 You're getting the team from root (which is not a player) and only once when the resource starts .. Use it at resourcestart for every player and when a player spawns (revert your other changes) function onResourceStart ( resource ) for id, player in ipairs( getElementsByType ( "player" ) ) do if ( players[player] ) then createBlipAttachedTo ( player, 0, 2, players[source][1], players[source][2], players[source][3] ) elseif getPlayerTeam(player) then local r, g, b = getTeamColor(getPlayerTeam(player)) createBlipAttachedTo ( player, 0, 2, r, g, b ) else createBlipAttachedTo ( player, 0, 2, color[1], color[2], color[3] ) end end end function onPlayerSpawn ( spawnpoint ) if ( players[source] ) then createBlipAttachedTo ( source, 0, 2, players[source][1], players[source][2], players[source][3] ) elseif getPlayerTeam(player) then local r, g, b = getTeamColor(getPlayerTeam(player)) createBlipAttachedTo ( player, 0, 2, r, g, b ) else createBlipAttachedTo ( source, 0, 2, color[1], color[2], color[3] ) end end Link to comment
FWCentral Posted September 5, 2011 Author Share Posted September 5, 2011 Hey thanks for the reply SDK i did post back earlier but wasnt logged in again the script you posted kinda works, when resource starts the blip is set the right color but when the player respawns his color goes black the color[1] [2] [3] is 0 0 0 so this is why it went black but yet i was still in a team so it should be the team color Link to comment
SDK Posted September 5, 2011 Share Posted September 5, 2011 Arrr, change player to source Link to comment
FWCentral Posted September 5, 2011 Author Share Posted September 5, 2011 Thanks SDK work perfect Link to comment
FWCentral Posted September 6, 2011 Author Share Posted September 6, 2011 One more quick question please, Im creating mechanic job and i want to create a blip attached to vehicles after 20 seconds of them leaving it but i dont know how i can get the players vehicle. function abandonveh() local veh = ?? createBlipAttachedTo(veh, 55, getTeamFromName("Mechanic")) end function startvehtime() setTimer(abandonveh, 20000, 1) end addEventHandler ( "onVehicleExit", getRootElement(), startvehtime ) Link to comment
Castillo Posted September 6, 2011 Share Posted September 6, 2011 Simple, 'source' is the element of the vehicle the player just exit. function abandonveh(veh) createBlipAttachedTo(veh, 55, getTeamFromName("Mechanic")) end function startvehtime() setTimer(abandonveh, 20000, 1, source) end addEventHandler ( "onVehicleExit", getRootElement(), startvehtime ) Link to comment
FWCentral Posted September 6, 2011 Author Share Posted September 6, 2011 Damn how stupid works great thanks Solidsnake! what about a vehicle attached to a towtruck how do i get the source of the vehicle attached? Link to comment
Castillo Posted September 6, 2011 Share Posted September 6, 2011 I think you should use this: https://wiki.multitheftauto.com/wiki/Get ... ingVehicle Link to comment
FWCentral Posted September 6, 2011 Author Share Posted September 6, 2011 yeah i think i can use that for what i need thank you 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