PatrykPro Posted June 11, 2014 Posted June 11, 2014 Welcome. I have a problem with hiding some parts of standard GTA HUD. I would like to hide: - ammo - clock - money - weapon - wanted I'm newbie and I don't know, how to script it. Sorry for my bad english.
undefined Posted June 11, 2014 Posted June 11, 2014 (edited) Use this: SetPlayerHudComponentVisible Edited June 11, 2014 by Guest
mint3d Posted June 11, 2014 Posted June 11, 2014 Try this.. addEventHandler ( "onPlayerJoin", root, function () setPlayerHudComponentVisible ( source, "ammo", false ) -- Hide the ammo displays for the newly joined player setPlayerHudComponentVisible ( source, "weapon", false ) -- Hide the weapon displays for the newly joined player setPlayerHudComponentVisible ( source, "clock", false ) -- Hide the clock displays for the newly joined player setPlayerHudComponentVisible ( source, "money", false ) -- Hide the money displays for the newly joined player setPlayerHudComponentVisible ( source, "wanted", false ) -- Hide the wanted displays for the newly joined player end )
PatrykPro Posted June 11, 2014 Author Posted June 11, 2014 mint3d: Everything works OK. HUD disappears, when I start this script after spawning, but when I start this before spawning, I'm still getting this thing: (original HUD with added HUD)
PatrykPro Posted June 11, 2014 Author Posted June 11, 2014 I don't know, how to do that. Here is the script of gamemode: --[[ ]] cdm_root = getRootElement() function cdm_initialize() outputDebugString( "Initializing Classic Deathmatch..." ) local teams = getElementsByType( "team" ) if ( #teams < 2 ) then outputDebugString( "* CDM Error: There are not enough teams. Minimum is 2", 1 ) cdm_error = true return end teamRoot = {} for k,v in ipairs(teams) do teamRoot[k] = {} teamRoot[k].name = getElementData( v, "name" ) if ( teamRoot[k].name == false ) then outputDebugString( "* CDM Error: Team #" .. k .. " doesn't have a name.", 1 ) cdm_error = true return end local weapons = getChildren ( v, "weapon" ) teamRoot[k].weapons = {} local str = "" for i,j in ipairs(weapons) do teamRoot[k].weapons[i] = {} teamRoot[k].weapons[i].id, teamRoot[k].weapons[i].ammo = tonumber(getElementData( j, "model" )), tonumber(getElementData( j, "ammo" )) if ( teamRoot[k].weapons[i].id == false ) then outputDebugString( "* CDM Error: All weapon IDs should be numeric.", 1 ) cdm_error = true return elseif ( teamRoot[k].weapons[i].ammo == false ) then outputDebugString( "* CDM Error: All ammo values should be numeric.", 1 ) cdm_error = true return end str = str .. teamRoot[k].weapons[i].ammo .. "x " .. getWeaponNameFromID ( teamRoot[k].weapons[i].id ) .. "\n" end local skins = getChildren ( v, "skin" ) teamRoot[k].skins = {} if ( #skins == 0 ) then teamRoot[k].skins[1] = 0 outputDebugString( "* CDM Warning: No skins were found in team #" .. k .. ". Defaulting to 0.", 2 ) end for i,j in ipairs(skins) do teamRoot[k].skins[i] = tonumber(getElementData( j, "model" )) if ( teamRoot[k].skins[i] == false ) then outputDebugString( "* CDM Error: All skin IDs should be numeric.", 1 ) cdm_error = true return end end local spawnpoints = getChildren ( v, "spawnpoint" ) if ( #spawnpoints == 0 ) then outputDebugString( "* CDM Error: Team #" .. k .. " doesn't have enough spawnpoints. Minimum is 1.", 1 ) cdm_error = true return end teamRoot[k].spawnpoints = {} for i,j in ipairs(spawnpoints) do teamRoot[k].spawnpoints[i] = {} teamRoot[k].spawnpoints[i].posX, teamRoot[k].spawnpoints[i].posY, teamRoot[k].spawnpoints[i].posZ, teamRoot[k].spawnpoints[i].rot = tonumber(getElementData( j, "posX" )), tonumber(getElementData( j, "posY" )), tonumber(getElementData( j, "posZ" )), tonumber(getElementData( j, "rot" )) if ( ( teamRoot[k].spawnpoints[i].posX == false ) or ( teamRoot[k].spawnpoints[i].posY == false ) or ( teamRoot[k].spawnpoints[i].posZ == false ) or ( teamRoot[k].spawnpoints[i].rot == false ) ) then outputDebugString( "* CDM Error: All spawnpoint values should be numeric.", 1 ) cdm_error = true return end end local camera = getChildren ( v, "camera" ) teamRoot[k].camera = {} teamRoot[k].camera.posX, teamRoot[k].camera.posY, teamRoot[k].camera.posZ, teamRoot[k].camera.lookX, teamRoot[k].camera.lookY, teamRoot[k].camera.lookZ = tonumber(getElementData( camera[1], "posX" )), tonumber(getElementData( camera[1], "posY" )), tonumber(getElementData( camera[1], "posZ" )), tonumber(getElementData( camera[1], "lookX" )), tonumber(getElementData( camera[1], "lookY" )), tonumber(getElementData( camera[1], "lookZ" )) if ( ( teamRoot[k].camera.posX == false ) or ( teamRoot[k].camera.posY == false ) or ( teamRoot[k].camera.posZ == false ) or ( teamRoot[k].camera.lookX == false ) or ( teamRoot[k].camera.lookY == false ) or ( teamRoot[k].camera.lookZ == false )) then teamRoot[k].camera.posX, teamRoot[k].camera.posY, teamRoot[k].camera.posZ, teamRoot[k].camera.lookX, teamRoot[k].camera.lookY, teamRoot[k].camera.lookZ = 0, 0, 0, 0, 0, 0 outputDebugString( "* CDM Warning: Something went wrong with the camera in team #" .. k .. " and it's your fault. Defaulting to 0, 0, 0.", 2 ) end teamRoot[k].red, teamRoot[k].green, teamRoot[k].blue = tonumber(getElementData( v, "red" )), tonumber(getElementData( v, "green" )), tonumber(getElementData( v, "blue" )) if (( teamRoot[k].red == false ) or ( teamRoot[k].green == false ) or ( teamRoot[k].blue == false )) then teamRoot[k].red, teamRoot[k].green, teamRoot[k].blue = 255, 255, 255 outputDebugString( "* CDM Warning: Something went wrong with the colors in team #" .. k .. " and it's your fault. Defaulting to 255, 255, 255.", 2 ) end teamRoot[k].display = textCreateDisplay () teamRoot[k].text1 = textCreateTextItem ( getElementData( v, "name" ), 0.5, 0.23, "high", teamRoot[k].red, teamRoot[k].green, teamRoot[k].blue, 255, 2.5 ) teamRoot[k].text2 = textCreateTextItem ( str, 0.5, 0.35, "high", 240, 240, 240, 255, 1.75 ) textDisplayAddText ( teamRoot[k].display, teamRoot[k].text1 ) textDisplayAddText ( teamRoot[k].display, teamRoot[k].text2 ) teamRoot[k].team = createTeam( tostring(teamRoot[k].name), tonumber(teamRoot[k].red), tonumber(teamRoot[k].green), tonumber(teamRoot[k].blue) ) end cdm_error = false outputDebugString( "Done." ) end function cdm_showScreen( player ) local last = getElementData( player, "lastSpawn" ) if ( last == false ) then setElementData( player, "lastSpawn", 1 ) last = 1 end spawnPlayer( player, 10000, 10000, 10000, 0, 0 ) setElementPosition( player, teamRoot[last].camera.posX, teamRoot[last].camera.posY, teamRoot[last].camera.posZ - 100 ) setPedGravity ( player, 0 ) textDisplayAddObserver ( teamRoot[last].display, player ) setCameraMatrix ( player, teamRoot[last].camera.posX, teamRoot[last].camera.posY, teamRoot[last].camera.posZ, teamRoot[last].camera.lookX, teamRoot[last].camera.lookY, teamRoot[last].camera.lookZ ) bindKey ( player, "enter", "down", "Spawn" ) bindKey ( player, "arrow_l", "down", "Next_team", "arrow_l" ) bindKey ( player, "arrow_r", "down", "Previous_team", "arrow_r" ) end function cdm_changeSpawn( player, commandName, key ) local last = getElementData( player, "lastSpawn" ) textDisplayRemoveObserver ( teamRoot[last].display, player ) if ( key == "arrow_l" ) then last = last - 1 else last = last + 1 end if ( last < 1 ) then last = #teamRoot end if ( last > #teamRoot ) then last = 1 end textDisplayAddObserver ( teamRoot[last].display, player ) setElementPosition( player, teamRoot[last].camera.posX, teamRoot[last].camera.posY, teamRoot[last].camera.posZ - 100 ) setCameraMatrix( player, teamRoot[last].camera.posX, teamRoot[last].camera.posY, teamRoot[last].camera.posZ, teamRoot[last].camera.lookX, teamRoot[last].camera.lookY, teamRoot[last].camera.lookZ ) setElementData( player, "lastSpawn", last ) end function cdm_spawn( player ) teamNum = getElementData( player, "lastSpawn" ) textDisplayRemoveObserver ( teamRoot[teamNum].display, player ) unbindKey ( player, "enter", "down", "Spawn" ) unbindKey ( player, "arrow_l", "down", "Next_team" ) unbindKey ( player, "arrow_r", "down", "Previous_team" ) local randSpawn = math.random(1, #teamRoot[teamNum].spawnpoints) local randSkin = math.random(1, #teamRoot[teamNum].skins) local team = getTeamFromName(teamRoot[teamNum].name) setPlayerNametagColor ( player, teamRoot[teamNum].red, teamRoot[teamNum].green, teamRoot[teamNum].blue ) setPedGravity ( player, 0.008 ) spawnPlayer ( player, 0, 0, 1000, 0, 1 ) setTimer( cdm_spawnTwo, 550, 1, player, teamNum, randSpawn, randSkin, team ) end function cdm_spawnTwo( player, teamNum, randSpawn, randSkin, team ) setCameraTarget( player, player ) setPlayerTeam ( player, team ) spawnPlayer ( player, teamRoot[teamNum].spawnpoints[randSpawn].posX, teamRoot[teamNum].spawnpoints[randSpawn].posY, teamRoot[teamNum].spawnpoints[randSpawn].posZ, teamRoot[teamNum].spawnpoints[randSpawn].rot, teamRoot[teamNum].skins[randSkin], 0, 0, team ) createBlipAttachedTo ( player, 0, 2, teamRoot[teamNum].red, teamRoot[teamNum].green, teamRoot[teamNum].blue ) for k,v in ipairs(teamRoot[teamNum].weapons) do giveWeapon ( player, teamRoot[teamNum].weapons[k].id, teamRoot[teamNum].weapons[k].ammo ) end end function cdm_killAll() local players = getElementsByType( "player" ) for k,v in ipairs(players) do if ( isPedDead( v ) == false ) then killPed( v ) end end end function cdm_gamemodeMapStart( startedMap ) cdm_initialize() if ( cdm_error == false ) then local sTime = getElementsByType( "respawn" ) if ( sTime ) then respawnTime = tonumber(getElementData( sTime[1], "time" )) else respawnTime = 4500 end local players = getElementsByType( "player" ) for k,v in ipairs(players) do setElementData( v, "score", 0 ) spawnPlayer( v, 10000, 10000, 10000, 0, 0 ) cdm_showScreen( v ) fadeCamera ( v, true ) end end end function cdm_playerJoin() setElementData( source, "score", 0 ) cdm_showScreen( source ) fadeCamera ( source, true ) end function cdm_playerQuit() destroyBlipsAttachedTo ( source ) end function cdm_playerWasted( totalAmmo, killer ) setPlayerTeam ( source, nil ) if ( killer ) then if ( killer ~= source ) then setElementData( killer, "score", getElementData( source, "score" ) + 1 ) else setElementData( killer, "score", getElementData( source, "score" ) - 1 ) end end destroyBlipsAttachedTo ( source ) local x, y, z = getElementPosition( source ) local deathBlip = createBlip ( x, y, z, 0, 2, 200, 200, 200 ) if ( getPedOccupiedVehicle ( source ) ) then if ( respawnTime > 200 ) then setTimer( removePedFromVehicle, respawnTime-200, 1, source ) else removePedFromVehicle( source ) end end setTimer( destroyElement, respawnTime, 1, deathBlip ) setTimer( cdm_showScreen, respawnTime, 1, source ) end function destroyBlipsAttachedTo( source ) local elements = getAttachedElements ( source ) for k,v in ipairs( elements ) do if ( getElementType( v ) == "blip" ) then destroyElement( v ) end end end function getChildren ( root, type ) local elements = getElementsByType ( type ) local result = {} for elementKey,elementValue in ipairs(elements) do if ( getElementParent( elementValue ) == root ) then result[ table.getn( result ) + 1 ] = elementValue end end return result end addCommandHandler("Spawn", cdm_spawn) addCommandHandler("Next_team", cdm_changeSpawn) addCommandHandler("Previous_team", cdm_changeSpawn) addEventHandler ( "onPlayerJoin", cdm_root, cdm_playerJoin ) addEventHandler ( "onPlayerQuit", cdm_root, cdm_playerQuit ) addEventHandler ( "onPlayerWasted", cdm_root, cdm_playerWasted ) addEventHandler ( "onGamemodeMapStart", cdm_root, cdm_gamemodeMapStart )
MTA Team qaisjp Posted June 11, 2014 MTA Team Posted June 11, 2014 You need to use these: addEventHandler "onPlayerSpawn" setPlayerHudComponentVisible
PatrykPro Posted June 11, 2014 Author Posted June 11, 2014 I'm too big noob to combine this with CDM script. I'll try tomorrow to do something. D:
mint3d Posted June 11, 2014 Posted June 11, 2014 Try this.. addEventHandler ( "onPlayerSpawn", root, function () setPlayerHudComponentVisible ( source, "ammo", false ) -- Hide the ammo displays for the newly joined player setPlayerHudComponentVisible ( source, "weapon", false ) -- Hide the weapon displays for the newly joined player setPlayerHudComponentVisible ( source, "clock", false ) -- Hide the clock displays for the newly joined player setPlayerHudComponentVisible ( source, "money", false ) -- Hide the money displays for the newly joined player setPlayerHudComponentVisible ( source, "wanted", false ) -- Hide the wanted displays for the newly joined player end )
PatrykPro Posted June 11, 2014 Author Posted June 11, 2014 Same thing. Script works, but still after respawn the original HUD comes back. >.< Do I need to add this somewhere in gamemode's script? BTW I tested another HUD resource and same problem, so maybe it's something in the script?
Max+ Posted June 12, 2014 Posted June 12, 2014 Try add this , at very bottem of the script , addEventHandler("onPlayerspawn",root,function() for k, v in ipairs({"ammo","weapon","clock","money","wanted"}) do showPlayerHudComponent(source,v,false) end end)
ZeyadGTX Posted June 12, 2014 Posted June 12, 2014 i use this , it works addEventHandler("onPlayerspawn",root,function() for k, v in ipairs({"ammo","weapon","clock","money","wanted"}) do showPlayerHudComponent(source,v,false) end end)
PatrykPro Posted June 12, 2014 Author Posted June 12, 2014 Max+: Really big thanks for you! Everything works perfect. Thread can be closed.
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