shaio Posted November 16, 2016 Share Posted November 16, 2016 This is all server side. I have no errors and no warnings in debugscript. I cannot find what is wrong with this script. Could someone please help me? I'm using just 2 skins for test purposes. I cannot change team or skin. local root = getRootElement() defaultSkin = 0 defaultTeam = "" currentSkin = 1 currentTeam = 1 team = "" enabled = false -------------------------------------------------- Configuration -------------------------------------------------- k = "F4" teams = { {team = "Freeroamer",x = -1980.03125,y = 884.171875,z = 45.203125,camX = -1991.60546875,camY = 883.015625,camZ = 49.198482513428,rot = 0,r = 0,g = 0,b = 0}, {team = "Gangster",x = 2498.328125,y = -1666.9169921875,z = 13.345584869385,camX = 2485.46484375,camY = -1666.2373046875,camZ = 16.649211883545,rot = 0,r = 0,g = 0,b = 0}, {team = "Doctor",x = 1178.6708984375,y = -1323.6162109375,z = 14.131542205811,camX = 1178.6708984375,camY = -1323.6162109375,camZ = 13.531591415405,rot = 0,r = 0,g = 0,b = 0}, {team = "Police",x = 1542.80078125,y = -1674.4306640625,z = 13.555210113525,camX = 1526.4638671875,camY = -1675.212890625,camZ = 19.493789672852,rot = 0,r = 0,g = 0,b = 0}, {team = "Military",x = 201.4443359375,y = 1897.6630859375,z = 17.640625,camX = 204.458984375,camY = 1919.634765625,camZ = 23.877788543701,rot = 0,r = 0,g = 0,b = 0}, {team = "Staff",x = -2025.8017578125,y = 171.3896484375,z = 28.84375,camX = -2002.76171875,camY = 170.9296875,camZ = 39.366466522217,rot = 0,r = 0,g = 0,b = 0} } skins = {} skins["Freeroamer"] = {0,5} skins["Gangster"] = {1,4} skins["Doctor"] = {2,3} skins["Police"] = {3,2} skins["Military"] = {4,1} skins["Staff"] = {5,0} ------------------------------------------------------------------------------------------------------------------- addEventHandler("onPlayerLogin",root,function() setAccountData(getPlayerAccount(source),"firstTime",true) bindKey(source,k,"down",deathChangeTeam) firstChange(source) end) for i,t in pairs(teams) do createTeam(t.team,t.r,t.g,t.b) end function firstChange(player) if getElementType(player) == "player" then defaultSkin = getElementModel(player) if getPlayerTeam(player) then defaultTeam = getPlayerTeam(player) end team = "Freeroamer" if currentSkin == #skins[tostring(team)] then currentSkin = 1 else currentSkin = currentSkin + 1 end updateSkin(player) for i,te in pairs(teams) do if te.team == team then setElementPosition(player,tonumber(te.x),tonumber(te.y),tonumber(te.z)) setCameraMatrix(player,tonumber(te.camX),tonumber(te.camY),tonumber(te.camZ),tonumber(te.x),tonumber(te.y),tonumber(te.z),0,70) end end setElementFrozen(player,true) bindKey(player,"arrow_u","down",changeTeam) bindKey(player,"arrow_d","down",changeTeam) bindKey(player,"arrow_l","down",changeSkin) bindKey(player,"arrow_r","down",changeSkin) bindKey(player,"enter","down",finishSelection) if getAccountData(getPlayerAccount(player),"firstTime") == false then bindKey(player,"backspace","down",exitSelection) end toggleAllControls(player,false) end end function changeSkin(player,key) if key == "arrow_l" then if currentSkin == 1 then currentSkin = #skins[tostring(team)] else currentSkin = currentSkin - 1 end elseif key == "arrow_r" then if currentSkin == #skins[tostring(team)] then currentSkin = 1 else currentSkin = currentSkin + 1 end end updateSkin(player) end function changeTeam(player,key) if key == "arrow_d" then if currentTeam == 1 then currentTeam = #teams else currentTeam = currentTeam - 1 end elseif key == "arrow_u" then if currentTeam == #teams then currentTeam = 1 else currentTeam = currentTeam + 1 end end updateTeam(player) end function updateSkin(player) for i,s in pairs(skins[tostring(team)]) do if i == currentSkin then setElementModel(player,tonumber(s)) end end end function updateTeam(player) for i,t in pairs(teams) do if i == currentTeam then if t.team == team then team = t.team updateSkin(player) setElementPosition(player,tonumber(t.x),tonumber(t.y),tonumber(t.z)) setCameraMatrix(player,tonumber(t.camX),tonumber(t.camY),tonumber(t.camZ),tonumber(t.x),tonumber(t.y),tonumber(t.z),0,70) end end end end function deathChangeTeam(player,key) if key == "f4" then addEventHandler("onPlayerWasted",root,function() if source == player then if getAccountData(getPlayerAccount(source),"firstTime") == false then if enabled == false then firstChange(source) outputChatBox("You will now be entered into team selection when you die.",player,0,255,255) enabled = true elseif enabled == true then outputChatBox("Team selection cancelled!",player,0,255,255) enabled = false end end end end) end end function finishSelection(player,key) if key == "enter" then setCameraTarget(player,player) setElementFrozen(player,false) toggleAllControls(player,true) setPlayerTeam(player,getTeamFromName(team)) unbindKey(player,"arrow_u","down",changeTeam) unbindKey(player,"arrow_d","down",changeTeam) unbindKey(player,"arrow_l","down",changeSkin) unbindKey(player,"arrow_r","down",changeSkin) unbindKey(player,"enter","down",finishSelection) unbindKey(player,"backspace","down",exitSelection) setAccountData(getPlayerAccount(player),"firstTime",true) end end function exitSelection(player,key) if key == "backspace" then setElementModel(player,tonumber(defaultSkin)) setPlayerTeam(player,defaultTeam) setCameraTarget(player,player) setElementFrozen(player,false) toggleAllControls(player,true) unbindKey(player,"arrow_u","down",changeTeam) unbindKey(player,"arrow_d","down",changeTeam) unbindKey(player,"arrow_l","down",changeSkin) unbindKey(player,"arrow_r","down",changeSkin) unbindKey(player,"enter","down",finishSelection) unbindKey(player,"backspace","down",exitSelection) end end Link to comment
shaio Posted November 17, 2016 Author Share Posted November 17, 2016 Could somebody please help me with this?? Link to comment
shaio Posted November 18, 2016 Author Share Posted November 18, 2016 Cmon for real, would someone please look at this script?? I really need some help.. And for :Os sake it all server side, It can't be leaked, I'll make client side dxDraw for it when I get the damn thing to work. I made it myself.. Please help me.. Link to comment
LoPollo Posted November 18, 2016 Share Posted November 18, 2016 (edited) Are you starting the resource when already connected? Also there are parts i don't understand: if currentSkin == #skins[tostring(team)] then currentSkin = 1 and currentskin is the model of the player... why compare to table lenght? Edited November 18, 2016 by LoPollo Link to comment
shaio Posted November 19, 2016 Author Share Posted November 19, 2016 (edited) Are you starting the resource when already connected? Also there are parts i don't understand: if currentSkin == #skins[tostring(team)] then currentSkin = 1 and currentskin is the model of the player... why compare to table lenght? I want to be able to change skins, and go in order with the table index. Edited November 19, 2016 by shaio Link to comment
Simple0x47 Posted November 19, 2016 Share Posted November 19, 2016 Why don't you make the index be numeric values? Link to comment
pa3ck Posted November 19, 2016 Share Posted November 19, 2016 Are you for real? Triple posting and begging for help at midnight? What do you expect like... my god... 1 Link to comment
LoPollo Posted November 19, 2016 Share Posted November 19, 2016 I was trying to understand the code but i gave up since i have no much time right now... there's client logic inside a server side script... i'm talking about the first variables like currentSkin, currentTeam... also you are forcing with tostring something that will be for sure a string (you set it in the script and it'is not touched otherwise, so if you set it only as string it will be always a string ) also rename some variables, like "k", i think stands for key... but k is a common variable in for loops, and even if that's not the case this practice can lead to errors. And me to not understand other variables to rename are team and player. Another thing to be aware is that in deathChangeTeam you are adding an handler, which will be added and added and added and added, everytime the function is called. This handler is also bound to root, but you are using "if source == player then" so what about binding it directly to what you need to check? (the player) I think it's better to rewrite some parts of the script, using tables when needed Ignore below, it's just the script correctly tabbed with the very first questions that passed in my mind... Spoiler Ignore, i posted it just cause originally i wanted to ask these question, but since i now think that a code rewrite would be better, it's here only to give an idea about what i thought local root = getRootElement() defaultSkin = 0 defaultTeam = "" currentSkin = 1 currentTeam = 1 team = "" enabled = false -------------------------------------------------- Configuration -------------------------------------------------- k = "F4" teams = { {team = "Freeroamer",x = -1980.03125,y = 884.171875,z = 45.203125,camX = -1991.60546875,camY = 883.015625,camZ = 49.198482513428,rot = 0,r = 0,g = 0,b = 0}, {team = "Gangster",x = 2498.328125,y = -1666.9169921875,z = 13.345584869385,camX = 2485.46484375,camY = -1666.2373046875,camZ = 16.649211883545,rot = 0,r = 0,g = 0,b = 0}, {team = "Doctor",x = 1178.6708984375,y = -1323.6162109375,z = 14.131542205811,camX = 1178.6708984375,camY = -1323.6162109375,camZ = 13.531591415405,rot = 0,r = 0,g = 0,b = 0}, {team = "Police",x = 1542.80078125,y = -1674.4306640625,z = 13.555210113525,camX = 1526.4638671875,camY = -1675.212890625,camZ = 19.493789672852,rot = 0,r = 0,g = 0,b = 0}, {team = "Military",x = 201.4443359375,y = 1897.6630859375,z = 17.640625,camX = 204.458984375,camY = 1919.634765625,camZ = 23.877788543701,rot = 0,r = 0,g = 0,b = 0}, {team = "Staff",x = -2025.8017578125,y = 171.3896484375,z = 28.84375,camX = -2002.76171875,camY = 170.9296875,camZ = 39.366466522217,rot = 0,r = 0,g = 0,b = 0} } skins = {} skins["Freeroamer"] = {0,5} skins["Gangster"] = {1,4} skins["Doctor"] = {2,3} skins["Police"] = {3,2} skins["Military"] = {4,1} skins["Staff"] = {5,0} for i,t in pairs(teams) do createTeam(t.team,t.r,t.g,t.b) end ------------------------------------------------------------------------------------------------------------------- addEventHandler("onPlayerLogin",root, function() setAccountData(getPlayerAccount(source),"firstTime",true) --firstTime is too generic, append the res name to differentiate: getResourceName ( resource ).."_firstTime" bindKey(source,k,"down",deathChangeTeam) firstChange(source) end ) function firstChange(player) if getElementType(player) == "player" then defaultSkin = getElementModel(player) --default skin is for all players, it should be a table if getPlayerTeam(player) then defaultTeam = getPlayerTeam(player) end team = "Freeroamer" --same as above --i still don't understand this: could you explain what this should do? if currentSkin == #skins[tostring(team)] then currentSkin = 1 else currentSkin = currentSkin + 1 end ------------------------------------------------------------------------ updateSkin(player) for i,te in pairs(teams) do if te.team == team then setElementPosition(player,tonumber(te.x),tonumber(te.y),tonumber(te.z)) setCameraMatrix(player,tonumber(te.camX),tonumber(te.camY),tonumber(te.camZ),tonumber(te.x),tonumber(te.y),tonumber(te.z),0,70) end end setElementFrozen(player,true) bindKey(player,"arrow_u","down",changeTeam) bindKey(player,"arrow_d","down",changeTeam) bindKey(player,"arrow_l","down",changeSkin) bindKey(player,"arrow_r","down",changeSkin) bindKey(player,"enter","down",finishSelection) if not getAccountData(getPlayerAccount(player),"firstTime") then bindKey(player,"backspace","down",exitSelection) end toggleAllControls(player,false) end end function changeSkin(player,key) if key == "arrow_l" then if currentSkin == 1 then currentSkin = #skins[tostring(team)] else currentSkin = currentSkin - 1 end elseif key == "arrow_r" then if currentSkin == #skins[tostring(team)] then currentSkin = 1 else currentSkin = currentSkin + 1 end end updateSkin(player) end function changeTeam(player,key) if key == "arrow_d" then if currentTeam == 1 then currentTeam = #teams else currentTeam = currentTeam - 1 end elseif key == "arrow_u" then if currentTeam == #teams then currentTeam = 1 else currentTeam = currentTeam + 1 end end updateTeam(player) end function updateSkin(player) for i,s in pairs(skins[tostring(team)]) do if i == currentSkin then -- don't understand this also setElementModel(player,tonumber(s)) end end end function updateTeam(player) for i,t in pairs(teams) do if i == currentTeam then if t.team == team then team = t.team updateSkin(player) setElementPosition(player,tonumber(t.x),tonumber(t.y),tonumber(t.z)) setCameraMatrix(player,tonumber(t.camX),tonumber(t.camY),tonumber(t.camZ),tonumber(t.x),tonumber(t.y),tonumber(t.z),0,70) end end end end function deathChangeTeam(player,key) if key == "f4" then addEventHandler("onPlayerWasted",root, function() if source == player then if not getAccountData(getPlayerAccount(source),"firstTime") then if not enabled then firstChange(source) outputChatBox("You will now be entered into team selection when you die.",player,0,255,255) enabled = true elseif enabled then outputChatBox("Team selection cancelled!",player,0,255,255) enabled = false end end end end ) end end function finishSelection(player,key) if key == "enter" then setCameraTarget(player,player) setElementFrozen(player,false) toggleAllControls(player,true) setPlayerTeam(player,getTeamFromName(team)) unbindKey(player,"arrow_u","down",changeTeam) unbindKey(player,"arrow_d","down",changeTeam) unbindKey(player,"arrow_l","down",changeSkin) unbindKey(player,"arrow_r","down",changeSkin) unbindKey(player,"enter","down",finishSelection) unbindKey(player,"backspace","down",exitSelection) setAccountData(getPlayerAccount(player),"firstTime",true) end end function exitSelection(player,key) if key == "backspace" then setElementModel(player,tonumber(defaultSkin)) setPlayerTeam(player,defaultTeam) setCameraTarget(player,player) setElementFrozen(player,false) toggleAllControls(player,true) unbindKey(player,"arrow_u","down",changeTeam) unbindKey(player,"arrow_d","down",changeTeam) unbindKey(player,"arrow_l","down",changeSkin) unbindKey(player,"arrow_r","down",changeSkin) unbindKey(player,"enter","down",finishSelection) unbindKey(player,"backspace","down",exitSelection) end end Link to comment
shaio Posted November 23, 2016 Author Share Posted November 23, 2016 On 11/19/2016 at 6:12 AM, LoPollo said: I was trying to understand the code but i gave up since i have no much time right now... there's client logic inside a server side script... i'm talking about the first variables like currentSkin, currentTeam... also you are forcing with tostring something that will be for sure a string (you set it in the script and it'is not touched otherwise, so if you set it only as string it will be always a string ) also rename some variables, like "k", i think stands for key... but k is a common variable in for loops, and even if that's not the case this practice can lead to errors. And me to not understand other variables to rename are team and player. Another thing to be aware is that in deathChangeTeam you are adding an handler, which will be added and added and added and added, everytime the function is called. This handler is also bound to root, but you are using "if source == player then" so what about binding it directly to what you need to check? (the player) I think it's better to rewrite some parts of the script, using tables when needed Ignore below, it's just the script correctly tabbed with the very first questions that passed in my mind... Hide contents Ignore, i posted it just cause originally i wanted to ask these question, but since i now think that a code rewrite would be better, it's here only to give an idea about what i thought local root = getRootElement()defaultSkin = 0defaultTeam = ""currentSkin = 1currentTeam = 1team = ""enabled = false-------------------------------------------------- Configuration --------------------------------------------------k = "F4"teams = { {team = "Freeroamer",x = -1980.03125,y = 884.171875,z = 45.203125,camX = -1991.60546875,camY = 883.015625,camZ = 49.198482513428,rot = 0,r = 0,g = 0,b = 0}, {team = "Gangster",x = 2498.328125,y = -1666.9169921875,z = 13.345584869385,camX = 2485.46484375,camY = -1666.2373046875,camZ = 16.649211883545,rot = 0,r = 0,g = 0,b = 0}, {team = "Doctor",x = 1178.6708984375,y = -1323.6162109375,z = 14.131542205811,camX = 1178.6708984375,camY = -1323.6162109375,camZ = 13.531591415405,rot = 0,r = 0,g = 0,b = 0}, {team = "Police",x = 1542.80078125,y = -1674.4306640625,z = 13.555210113525,camX = 1526.4638671875,camY = -1675.212890625,camZ = 19.493789672852,rot = 0,r = 0,g = 0,b = 0}, {team = "Military",x = 201.4443359375,y = 1897.6630859375,z = 17.640625,camX = 204.458984375,camY = 1919.634765625,camZ = 23.877788543701,rot = 0,r = 0,g = 0,b = 0}, {team = "Staff",x = -2025.8017578125,y = 171.3896484375,z = 28.84375,camX = -2002.76171875,camY = 170.9296875,camZ = 39.366466522217,rot = 0,r = 0,g = 0,b = 0}}skins = {}skins["Freeroamer"] = {0,5}skins["Gangster"] = {1,4}skins["Doctor"] = {2,3}skins["Police"] = {3,2}skins["Military"] = {4,1}skins["Staff"] = {5,0}for i,t in pairs(teams) do createTeam(t.team,t.r,t.g,t.b)end-------------------------------------------------------------------------------------------------------------------addEventHandler("onPlayerLogin",root, function() setAccountData(getPlayerAccount(source),"firstTime",true) --firstTime is too generic, append the res name to differentiate: getResourceName ( resource ).."_firstTime" bindKey(source,k,"down",deathChangeTeam) firstChange(source) end)function firstChange(player) if getElementType(player) == "player" then defaultSkin = getElementModel(player) --default skin is for all players, it should be a table if getPlayerTeam(player) then defaultTeam = getPlayerTeam(player) end team = "Freeroamer" --same as above --i still don't understand this: could you explain what this should do? if currentSkin == #skins[tostring(team)] then currentSkin = 1 else currentSkin = currentSkin + 1 end ------------------------------------------------------------------------ updateSkin(player) for i,te in pairs(teams) do if te.team == team then setElementPosition(player,tonumber(te.x),tonumber(te.y),tonumber(te.z)) setCameraMatrix(player,tonumber(te.camX),tonumber(te.camY),tonumber(te.camZ),tonumber(te.x),tonumber(te.y),tonumber(te.z),0,70) end end setElementFrozen(player,true) bindKey(player,"arrow_u","down",changeTeam) bindKey(player,"arrow_d","down",changeTeam) bindKey(player,"arrow_l","down",changeSkin) bindKey(player,"arrow_r","down",changeSkin) bindKey(player,"enter","down",finishSelection) if not getAccountData(getPlayerAccount(player),"firstTime") then bindKey(player,"backspace","down",exitSelection) end toggleAllControls(player,false) endendfunction changeSkin(player,key) if key == "arrow_l" then if currentSkin == 1 then currentSkin = #skins[tostring(team)] else currentSkin = currentSkin - 1 end elseif key == "arrow_r" then if currentSkin == #skins[tostring(team)] then currentSkin = 1 else currentSkin = currentSkin + 1 end end updateSkin(player)endfunction changeTeam(player,key) if key == "arrow_d" then if currentTeam == 1 then currentTeam = #teams else currentTeam = currentTeam - 1 end elseif key == "arrow_u" then if currentTeam == #teams then currentTeam = 1 else currentTeam = currentTeam + 1 end end updateTeam(player)endfunction updateSkin(player) for i,s in pairs(skins[tostring(team)]) do if i == currentSkin then -- don't understand this also setElementModel(player,tonumber(s)) end endendfunction updateTeam(player) for i,t in pairs(teams) do if i == currentTeam then if t.team == team then team = t.team updateSkin(player) setElementPosition(player,tonumber(t.x),tonumber(t.y),tonumber(t.z)) setCameraMatrix(player,tonumber(t.camX),tonumber(t.camY),tonumber(t.camZ),tonumber(t.x),tonumber(t.y),tonumber(t.z),0,70) end end endendfunction deathChangeTeam(player,key) if key == "f4" then addEventHandler("onPlayerWasted",root, function() if source == player then if not getAccountData(getPlayerAccount(source),"firstTime") then if not enabled then firstChange(source) outputChatBox("You will now be entered into team selection when you die.",player,0,255,255) enabled = true elseif enabled then outputChatBox("Team selection cancelled!",player,0,255,255) enabled = false end end end end ) endendfunction finishSelection(player,key) if key == "enter" then setCameraTarget(player,player) setElementFrozen(player,false) toggleAllControls(player,true) setPlayerTeam(player,getTeamFromName(team)) unbindKey(player,"arrow_u","down",changeTeam) unbindKey(player,"arrow_d","down",changeTeam) unbindKey(player,"arrow_l","down",changeSkin) unbindKey(player,"arrow_r","down",changeSkin) unbindKey(player,"enter","down",finishSelection) unbindKey(player,"backspace","down",exitSelection) setAccountData(getPlayerAccount(player),"firstTime",true) endendfunction exitSelection(player,key) if key == "backspace" then setElementModel(player,tonumber(defaultSkin)) setPlayerTeam(player,defaultTeam) setCameraTarget(player,player) setElementFrozen(player,false) toggleAllControls(player,true) unbindKey(player,"arrow_u","down",changeTeam) unbindKey(player,"arrow_d","down",changeTeam) unbindKey(player,"arrow_l","down",changeSkin) unbindKey(player,"arrow_r","down",changeSkin) unbindKey(player,"enter","down",finishSelection) unbindKey(player,"backspace","down",exitSelection) endend The code works. It's just the two functions updateTeam and updateSkin that wont run.. Link to comment
Dzsozi (h03) Posted November 23, 2016 Share Posted November 23, 2016 https://wiki.multitheftauto.com/wiki/Character_Skins Notes: Last valid skin ID: 312 The following pairs of IDs produce same character (1st ID used in lists, 2nd disabled) 118:119 148:149 Non-working IDs <---- 3 4 5 6 8 42 65 74 86 119 149 208 273 289 <---- Change the non-valid numbers in the tables (3, 5, etc.) to something else and see if it works. 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