Hell-Mate Posted March 5, 2014 Share Posted March 5, 2014 Hello community .. im askinf about tables x2 i have a problem. i have made a hitme script and this script create a blip attached to player and i added an event which when a player dies so the blip get destroyed. my previous problem is the blip is getting destroyed for only the last player who used hitme command when dying and if another player died who yoused the cmd first nothing happen and the blip stays so i asked for help in community and someone told me to create tables and use table.insert so i did that and another problem released -.- now when two or more players are hit and one of them died so the blip getting destroyed to all hits .. hope any one can help and here is the script >> hitBlip = { } function hitme ( thePlayer, commandName, moneyAmount ) local playermoney = getPlayerMoney ( thePlayer ) if playermoney < tonumber(moneyAmount) then outputChatBox ( "You dont have enough money to make hit",thePlayer,255,0,0, false ) else amount = tonumber(moneyAmount) if amount > 500000 then outputChatBox ( "Maximum hit amount is $500000", thePlayer,255,0,0, false ) else if amount < 50000 then outputChatBox ( "Minimum hit amount is $50000", thePlayer,255,0,0, false ) else if ( getElementData ( thePlayer, 'Player' ) == 'Hit' ) then outputChatBox ( "You are already a hit", thePlayer,255,0,0, false ) else local playername = getPlayerName ( thePlayer ) hisBlip = createBlipAttachedTo ( thePlayer, 26 ) table.insert ( hitBlip, hisBlip ) setPlayerNametagColor ( thePlayer, 0, 0, 0 ) takePlayerMoney ( thePlayer, amount ) setElementData ( thePlayer, 'Player', "Hit" ) outputChatBox ( "You have placed a $" .. amount .. " hit on your self",thePlayer,255,235,0, false ) outputChatBox ( "A hit has been placed on " .. playername .. " For $" .. amount .. ".",root,255,235,0, false ) end end end end end addCommandHandler ("hitme", hitme) function ondie () if ( getElementData ( source, 'Player' ) == 'Hit' ) then removeElementData( source, 'Player', "Hit" ) setPlayerNametagColor ( source, 255, 255, 0 ) for key, hisBlip in ipairs( hitBlip ) do destroyElement ( hisBlip ) end end end addEventHandler ( "onPlayerWasted", getRootElement(), ondie ) Link to comment
Hell-Mate Posted March 5, 2014 Author Share Posted March 5, 2014 hmmm, anyone can help ?? Link to comment
Mr_Moose Posted March 5, 2014 Share Posted March 5, 2014 First of all you don't need to loop threw all the hit blips when one of the hits die (that's the reason for removing all blips), secondly the element data looked a little bit wrong as well and you got two end calls to much in the beginning, not sure if it worked or not in the first place but here you go. This should work. hitBlip = { } function hitme ( thePlayer, commandName, moneyAmount ) local playermoney = getPlayerMoney ( thePlayer ) if playermoney < tonumber(moneyAmount) then outputChatBox ( "You dont have enough money to make hit",thePlayer,255,0,0, false ) else amount = tonumber(moneyAmount) if amount > 500000 then outputChatBox ( "Maximum hit amount is $500000", thePlayer,255,0,0, false ) elseif amount < 50000 then outputChatBox ( "Minimum hit amount is $50000", thePlayer,255,0,0, false ) elseif ( getElementData ( thePlayer, 'Player' ) == 'Hit' ) then outputChatBox ( "You are already a hit", thePlayer,255,0,0, false ) else local playername = getPlayerName ( thePlayer ) hisBlip = createBlipAttachedTo ( thePlayer, 26 ) hitBlip[thePlayer] = hisBlip -- Store the hitblip assigned to the hit player in the global table setPlayerNametagColor ( thePlayer, 0, 0, 0 ) takePlayerMoney ( thePlayer, amount ) setElementData ( thePlayer, "isHit", true ) outputChatBox ( "You have placed a $" .. amount .. " hit on your self",thePlayer,255,235,0, false ) outputChatBox ( "A hit has been placed on " .. playername .. " For $" .. amount .. ".",root,255,235,0, false ) end end end addCommandHandler ("hitme", hitme) function ondie () if getElementData ( source, "isHit" ) then removeElementData( source, "isHit" ) setPlayerNametagColor ( source, 255, 255, 0 ) destroyElement( hitBlip[source] ) end end addEventHandler ( "onPlayerWasted", getRootElement(), ondie ) The table will now store the blip pointer and assign it to the player which is a hit, when he dies, he's blip will be removed, element data is now a value named "isHit" which is set to true when a player is a hit, verifyed by getElementData and finally removed by removeElementData using correct syntax, by using indentation it's also way more easy to read the code which I recomend you to use in the future. Good luck with this now. Link to comment
Hell-Mate Posted March 5, 2014 Author Share Posted March 5, 2014 how it will add the blips to the table without table.insert ?? Link to comment
WhoAmI Posted March 5, 2014 Share Posted March 5, 2014 Normally. For example blips = { } -- creating a table function addBlip ( player ) blips[ player ] = "this is a blip" -- inserting to the table "this is a blip" with player as key end addCommandHandler ( "addblip", addBlip ) And then function removeBlip ( player ) blips[ player ] = nil -- removing "this is a blip" from table saved in player as key end addCommandHandler ( "removeblip", removeblip ) /addblip would insert "this a blip" into table /removeblip would delete it from table. Link to comment
Moderators Citizen Posted March 5, 2014 Moderators Share Posted March 5, 2014 Hello community .. im askinf about tables x2i have a problem. i have made a hitme script and this script create a blip attached to player and i added an event which when a player dies so the blip get destroyed. my previous problem is the blip is getting destroyed for only the last player who used hitme command when dying and if another player died who yoused the cmd first nothing happen and the blip stays so i asked for help in community and someone told me to create tables and use table.insert so i did that and another problem released -.- now when two or more players are hit and one of them died so the blip getting destroyed to all hits .. hope any one can help and here is the script >> hitBlip = { } function hitme ( thePlayer, commandName, moneyAmount ) local playermoney = getPlayerMoney ( thePlayer ) if playermoney < tonumber(moneyAmount) then outputChatBox ( "You dont have enough money to make hit",thePlayer,255,0,0, false ) else amount = tonumber(moneyAmount) if amount > 500000 then outputChatBox ( "Maximum hit amount is $500000", thePlayer,255,0,0, false ) else if amount < 50000 then outputChatBox ( "Minimum hit amount is $50000", thePlayer,255,0,0, false ) else if ( getElementData ( thePlayer, 'Player' ) == 'Hit' ) then outputChatBox ( "You are already a hit", thePlayer,255,0,0, false ) else local playername = getPlayerName ( thePlayer ) hisBlip = createBlipAttachedTo ( thePlayer, 26 ) table.insert ( hitBlip, hisBlip ) setPlayerNametagColor ( thePlayer, 0, 0, 0 ) takePlayerMoney ( thePlayer, amount ) setElementData ( thePlayer, 'Player', "Hit" ) outputChatBox ( "You have placed a $" .. amount .. " hit on your self",thePlayer,255,235,0, false ) outputChatBox ( "A hit has been placed on " .. playername .. " For $" .. amount .. ".",root,255,235,0, false ) end end end end end addCommandHandler ("hitme", hitme) function ondie () if ( getElementData ( source, 'Player' ) == 'Hit' ) then removeElementData( source, 'Player', "Hit" ) setPlayerNametagColor ( source, 255, 255, 0 ) for key, hisBlip in ipairs( hitBlip ) do destroyElement ( hisBlip ) end end end addEventHandler ( "onPlayerWasted", getRootElement(), ondie ) Man it's a fucking joke right ?? I just fixed that problem in your previous post where you were asking how to get the player who killed the guy who used /hitme Using element data is good enough and as you can see faster than using a table ... I gave you the fixed code but you didn't took it just because I didn't reply to your initial question :facepalm: From Help !! Hi, check all my comments ! function hitme ( thePlayer, commandName, moneyAmount ) if not moneyAmount or not tonumber(moneyAmmount) then --if he just wrote /hitme or if moneyAmount isn't a number. outputChatBox( "SYNTAX: /hitme ", thePlayer, 255, 0, 0 ) -- Show him how the cmd syntax return --This is how you stop the execution of a function, and not cancelEvent() as u did ... end moneyAmount = tonumber( moneyAmount ) -- transform the text (i.e: "50000") into a number (i.e: 50000). It's not becoming a global here ! local playermoney = getPlayerMoney ( thePlayer ) if playermoney < tonumber(moneyAmount) then outputChatBox ( "You don't have enough money to make hit", thePlayer, 255, 0, 0 ) else if moneyAmount >= 500000 then --I added a = otherwise the max would be $499.999 outputChatBox ( "Maximum hit amount is $500000", thePlayer, 255, 0, 0 ) elseif moneyAmount <= 50000 then --I added a = otherwise the min would be $50.001 outputChatBox ( "Minimum hit amount is $50000", thePlayer, 255, 0, 0 ) elseif getElementData ( thePlayer, "hitBlip" ) then --if the player has a value in the element data "hitBlip", then he already used /hitme and didn't die yet outputChatBox ( "You are already a hit", thePlayer, 255, 0, 0 ) else local playername = getPlayerName ( thePlayer ) local hitBlip = createBlipAttachedTo ( thePlayer, 26 ) --never do such global on serverside !! use a setElementData on the player instead ! setElementData ( thePlayer, "hitBlip", hitBlip ) --here is the setElementData to store the player's blip setPlayerNametagColor ( thePlayer, 0, 0, 0 ) takePlayerMoney ( thePlayer, moneyAmount ) outputChatBox ( "You have placed a $" .. moneyAmount .. " hit on yourself", thePlayer, 255, 235, 0 ) outputChatBox ( "A hit has been placed on " .. playername .. " For $" .. moneyAmount .. ".", root, 255, 235, 0 ) end end end addCommandHandler ("hitme", hitme) function ondie () local hitBlip = getElementData ( source, "hitBlip" ) -- here is the setElementData to get the player's blip we stored if hitBlip and isElement( hitBlip ) then -- make sure the player who died did the /hitme cmd removeElementData( source, 'hitBlip' ) -- to make sure he can do /hitme again (I know you already done it) destroyElement ( hitBlip ) end end addEventHandler ( "onPlayerWasted", getRootElement(), ondie ) What do you have to say about that ? (Wasting time of members by asking to fix a problem someone already did in one of your hundreds topics). Link to comment
Hell-Mate Posted March 5, 2014 Author Share Posted March 5, 2014 It now fixing the problem .. it will just destroy the blip of the last one who use /hitme when dying for example : 1) i used /hitme, 2) my friend used /hitme after me used it 3) me or my friend died = my friend blip will only get destroyed and the element data will get removed from me and my friend. got it ? Link to comment
Moderators Citizen Posted March 5, 2014 Moderators Share Posted March 5, 2014 It now fixing the problem .. it will just destroy the blip of the last one who use /hitme when dying for example : 1) i used /hitme, 2) my friend used /hitme after me used it 3) me or my friend died = my friend blip will only get destroyed and the element data will get removed from me and my friend. got it ? Hahaha you are cute Do you really think you are good enough to say what will really do my script without testing it ? By saying that, you just prove another time that you don't understand that much. 1 - Use my code and test it. It will work and fix your problem. 2 - Please read the wiki and learn (specially about element datas). Link to comment
Mr_Moose Posted March 5, 2014 Share Posted March 5, 2014 Well that was kind of wasted time then... Link to comment
Moderators Citizen Posted March 5, 2014 Moderators Share Posted March 5, 2014 Well that was kind of wasted time then... Yup totally, but in the end, he will finally use my code and add the parameters on the ondie function ( totalAmmo and theKiller ) we (initially Solstice. and then I) told him to get who killed the guy who used /hitme. Link to comment
Hell-Mate Posted March 5, 2014 Author Share Posted March 5, 2014 Well that was kind of wasted time then... Yup totally, but in the end, he will finally use my code and add the parameters on the ondie function ( totalAmmo and theKiller ) we (initially Solstice. and then I) told him to get who killed the guy who used /hitme. Your code really helped me and now i made it 100% and added a new ElementData to the amount to store every Amount when player do /hitme amount and i took with your advice and opened wiki and learned ElementData fanction --Finally i want to say thanks bro Link to comment
Moderators Citizen Posted March 5, 2014 Moderators Share Posted March 5, 2014 Well that was kind of wasted time then... Yup totally, but in the end, he will finally use my code and add the parameters on the ondie function ( totalAmmo and theKiller ) we (initially Solstice. and then I) told him to get who killed the guy who used /hitme. Your code really helped me and now i made it 100% and added a new ElementData to the amount to store every Amount when player do /hitme amount and i took with your advice and opened wiki and learned ElementData fanction --Finally i want to say thanks bro You are welcome I was about to help you out with your dxDrawText problem, but Solidsnake were faster. There is no need to stay angry at someone who apologized. 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