Avagard Posted May 8, 2017 Share Posted May 8, 2017 hello... there is a problem i have in my code when the player enters the ColShape nothing happens.. no errors no nothing code: function giveBombToRandomPlayer1() local randomPlayer = getRandomPlayer () local tT = getTeamFromName ("Terrorists") local playerTeam = getPlayerTeam ( randomPlayer ) if ( playerTeam ) == tT then outputChatBox("You have the bomb!", randomPlayer, 255, 0, 0) setElementData(randomPlayer,"hasBomb1",true) end end bombA = createRadarArea ( 3118.7380371094, -1407.4719238281, 20, 20, 255, 0, 0, 150 ) bombAEnter = createColRectangle( 3118.7380371094, -1407.4719238281, 20, 20) function whenEnterbomb1(hitPlayer) if getElementType(hitPlayer)=="player" then if getElementData(hitPlayer,"hasBomb1") == true then outputChatBox("Press 'g' to plant the bomb!",hitPlayer, 255, 0, 0) setElementData(hitPlayer,"canPlant1",true) end end end addEventHandler( "onColShapeHit", bombAEnter, whenEnterbomb1) function whenLeaveBomb1(hitPlayer) if getElementType(hitPlayer)=="player"then if getElementData(hitPlayer,"hasBomb1") == true then setElementData(hitPlayer,"canPlant1",false) setElementData(hitPlayer,"hasBomb1",false) end end end addEventHandler( "onColShapeLeave", bombAEnter,whenLeaveBomb1) Link to comment
Addlibs Posted May 8, 2017 Share Posted May 8, 2017 Seems like everything should work. On another note however, why are you removing the player's bomb when he leaves the colshape even if he doesn't use it? (Line 28) Link to comment
pa3ck Posted May 8, 2017 Share Posted May 8, 2017 Are you sure you call the function "giveBombToRandomPlayer1" somehow? Event, command? 1 Link to comment
Avagard Posted May 8, 2017 Author Share Posted May 8, 2017 (edited) yes.. it output you have the bomb but the other output doesn't show when i enter the col nvm i fixed it, but just a question.. will it always give to a random player from tT team? Edited May 8, 2017 by Avagard Link to comment
pa3ck Posted May 8, 2017 Share Posted May 8, 2017 No, you will need a loop to get a new random player until it finds one that's in that team. It would be easier to get the list of players in that team using getPlayersInTeam and use math.random to get a random player from the returned table. 1 Link to comment
Avagard Posted May 8, 2017 Author Share Posted May 8, 2017 thank you..one more question.. how can i enable crouching with rpg? Link to comment
undefined Posted May 8, 2017 Share Posted May 8, 2017 setWeaponProperty(weapon,level,"flag_anim_crouch", false) Link to comment
Avagard Posted May 10, 2017 Author Share Posted May 10, 2017 On 5/8/2017 at 17:12, pa3ck said: No, you will need a loop to get a new random player until it finds one that's in that team. It would be easier to get the list of players in that team using getPlayersInTeam and use math.random to get a random player from the returned table. will this work? function giveBombToRandomPlayer1() local players = getPlayersInTeam ( T ) for playerKey, playerValue in ipairs ( players ) do local randomPlayer = getRandomPlayer () setTimer(function() outputChatBox("You have the bomb!", randomPlayer, 255, 0, 0) outputChatBox("Remember when you enter site.. switch to the C4 to plant!", randomPlayer, 255, 0, 0) giveWeapon ( randomPlayer, 14,1,true) end,6000,1) end end Link to comment
pa3ck Posted May 10, 2017 Share Posted May 10, 2017 (edited) No, look at this code: function giveBombToRandomPlayer() local teamElement = getTeamFromName ("Terrorists") local teamMembers if isElement(teamElement) then teamMembers = getPlayersInTeam(teamElement) else outputChatBox("Team is not available") return end if(teamMembers and #teamMembers > 0 then) local randomIndex = math.random(1, #teamMembers) -- get a random index: between 1 and the length of the table local randomPlayer = teamMembers[randomIndex] -- we already have a random index, now get it from the table setTimer(function() if not isElement(randomPlayer) then -- there's a 6 seconds timer here, there's a chance the terrorist we picked got disconnected, if so, find a new one outputChatBox("Player is no longer available, finding new player...") giveBombToRandomPlayer() return end outputChatBox("You have the bomb!", randomPlayer, 255, 0, 0) outputChatBox("Remember when you enter site.. switch to the C4 to plant!", randomPlayer, 255, 0, 0) giveWeapon ( randomPlayer, 14,1,true) end,6000,1) else outputChatBox("Couldn't find any Terrorists") end end PS. this code editor is so annoying, I miss the old one, this one always fks up the indentation... not to mention the copy code function, it copies the line numbers and empty lines after each statement... It is not tested, if you get any errors and you can't solve it yourself, feel free to come back with the errors you're getting. Edited May 10, 2017 by pa3ck 1 Link to comment
Avagard Posted May 10, 2017 Author Share Posted May 10, 2017 thank you.. there was a problem just a small one and i fixed it.. Link to comment
Avagard Posted May 10, 2017 Author Share Posted May 10, 2017 i just realized that i want to give the bomb to the players in Dimension 0... i want to know where should i put this line? if getElementDimension ( randomPlayer ) == 0 then Link to comment
pa3ck Posted May 10, 2017 Share Posted May 10, 2017 function giveBombToRandomPlayer() local teamElement = getTeamFromName ("Terrorists") local teamMembers = {} if isElement(teamElement) then for k, p in ipairs(getPlayersInTeam(teamElement)) do if getElementDimension(p) == 0 then table.insert(teamMembers, p ) end end else outputChatBox("Team is not available") return end if(teamMembers and #teamMembers > 0 then) local randomIndex = math.random(1, #teamMembers) -- get a random index: between 1 and the length of the table local randomPlayer = teamMembers[randomIndex] -- we already have a random index, now get it from the table setTimer(function() if not isElement(randomPlayer) then -- there's a 6 seconds timer here, there's a chance the terrorist we picked got disconnected, if so, find a new one outputChatBox("Player is no longer available, finding new player...") giveBombToRandomPlayer() return end outputChatBox("You have the bomb!", randomPlayer, 255, 0, 0) outputChatBox("Remember when you enter site.. switch to the C4 to plant!", randomPlayer, 255, 0, 0) giveWeapon ( randomPlayer, 14,1,true) end,6000,1) else outputChatBox("Couldn't find any Terrorists") end end That should work 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