NodZen_42 Posted July 13, 2018 Share Posted July 13, 2018 Hi guys, i need help with script. The idea is if the player is "mercenarios" then create a image in the screen of that player. But, my script doesn't work. Any help? function isPlayerInTeam(player, team) assert(isElement(player) and getElementType(player) == "player", "Bad argument 1 @ isPlayerInTeam [player expected, got " .. tostring(player) .. "]") assert((not team) or type(team) == "string" or (isElement(team) and getElementType(team) == "team"), "Bad argument 2 @ isPlayerInTeam [nil/string/team expected, got " .. tostring(team) .. "]") return getPlayerTeam(player) == (type(team) == "string" and getTeamFromName(team) or (type(team) == "userdata" and team or (getPlayerTeam(player) or true))) end local screenW, screenH = guiGetScreenSize() function teams_images () local team_mercenarios = isPlayerInTeam(source,"Mercenarios") if team_mercenarios then dxDrawImage(100, 100, 40,40,"mercenarios.png") end end addEventHandler("onClientPlayerSpawn", getLocalPlayer(),teams_images) Link to comment
Infinity# Posted July 13, 2018 Share Posted July 13, 2018 if team_mercenarios then addEventHandler("onClientRender", root, drawTeamImage) end function drawTeamImage() dxDrawImage(100, 100, 40,40,"mercenarios.png") end Then make it onClientPlayerWasted to remove the onClientRender event. Let me know if it works. Link to comment
NodZen_42 Posted July 13, 2018 Author Share Posted July 13, 2018 29 minutes ago, Infinity# said: if team_mercenarios then addEventHandler("onClientRender", root, drawTeamImage) end function drawTeamImage() dxDrawImage(100, 100, 40,40,"mercenarios.png") end Then make it onClientPlayerWasted to remove the onClientRender event. Let me know if it works. I don't understand. That would be all the script? or just a part? Link to comment
Infinity# Posted July 13, 2018 Share Posted July 13, 2018 Add it on to your script. Client-side file. So it would be: function isPlayerInTeam(player, team) assert(isElement(player) and getElementType(player) == "player", "Bad argument 1 @ isPlayerInTeam [player expected, got " .. tostring(player) .. "]") assert((not team) or type(team) == "string" or (isElement(team) and getElementType(team) == "team"), "Bad argument 2 @ isPlayerInTeam [nil/string/team expected, got " .. tostring(team) .. "]") return getPlayerTeam(player) == (type(team) == "string" and getTeamFromName(team) or (type(team) == "userdata" and team or (getPlayerTeam(player) or true))) end local screenW, screenH = guiGetScreenSize() function teams_images () local team_mercenarios = isPlayerInTeam(source,"Mercenarios") if team_mercenarios then addEventHandler("onClientRender", root, drawTeamImage) end end addEventHandler("onClientPlayerSpawn", getLocalPlayer(),teams_images) function drawTeamImage() dxDrawImage(100, 100, 40,40,"mercenarios.png") end But you need to do something because this is suppose to be client-side and 'isPlayerInTeam' is a server-side event. Link to comment
NodZen_42 Posted July 13, 2018 Author Share Posted July 13, 2018 16 minutes ago, Infinity# said: Add it on to your script. Client-side file. So it would be: function isPlayerInTeam(player, team) assert(isElement(player) and getElementType(player) == "player", "Bad argument 1 @ isPlayerInTeam [player expected, got " .. tostring(player) .. "]") assert((not team) or type(team) == "string" or (isElement(team) and getElementType(team) == "team"), "Bad argument 2 @ isPlayerInTeam [nil/string/team expected, got " .. tostring(team) .. "]") return getPlayerTeam(player) == (type(team) == "string" and getTeamFromName(team) or (type(team) == "userdata" and team or (getPlayerTeam(player) or true))) end local screenW, screenH = guiGetScreenSize() function teams_images () local team_mercenarios = isPlayerInTeam(source,"Mercenarios") if team_mercenarios then addEventHandler("onClientRender", root, drawTeamImage) end end addEventHandler("onClientPlayerSpawn", getLocalPlayer(),teams_images) function drawTeamImage() dxDrawImage(100, 100, 40,40,"mercenarios.png") end But you need to do something because this is suppose to be client-side and 'isPlayerInTeam' is a server-side event. It doesn't work bro Link to comment
kieran Posted July 13, 2018 Share Posted July 13, 2018 (edited) @NodZen_42 Try to use getPlayerTeam instead, this is both server and client side, and very reliable. local screenW, screenH = guiGetScreenSize() function drawTheImage () dxDrawImage(100, 100, 40,40,"mercenarios.png") end function teams_images () local playersTeam = getPlayerTeam(localPlayer) local TeamName = getTeamName ( playerTeam ) if TeamName == "Mercenarios" then addEventHandler("onClientRender", root, drawTheImage) outputChatBox('Player is in that team.') --Output a message to check if the script is working and you can't see the image. end end addEventHandler("onClientPlayerSpawn", getLocalPlayer(),teams_images) Apologies if this is wrong, very sleepy. It is untested but I can test it and try make it work if needed. I forgot to mention something VERY important, dx images and anything dx (directX) based, is drawn every frame. So if you just do it when the player spawns, that image is drawn for 1 frame, not for the duration the player is spawned. Now to solve this you can use onClientRender, this will check every frame and make sure the image is there, loading it on every frame until you remove the event handler with removeEventHandler. Edited July 13, 2018 by kieran 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