Jump to content

Help !! :)


Recommended Posts

Hello community,,

i want help in something, well, i want to make an event onPlayerWasted and get who killed the WastedPlayer so i can givehimMoney or what ever i just need this help because im creating a hit system ..

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 ) 
cancelEvent () 
else 
amount = tonumber(moneyAmount) 
if amount > 500000 then 
outputChatBox ( "Maximum hit amount is $500000", thePlayer,255,0,0, false ) 
cancelEvent () 
else 
if amount < 50000 then 
outputChatBox ( "Minimum hit amount is $50000", thePlayer,255,0,0, false ) 
cancelEvent () 
else 
if ( getElementData ( thePlayer, 'Player' ) == 'Hit' ) then 
outputChatBox ( "You are already a hit", thePlayer,255,0,0, false ) 
cancelEvent () 
else 
local playername = getPlayerName ( thePlayer ) 
hitBlip = createBlipAttachedTo ( thePlayer, 26 ) 
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 .. ".",thePlayer,255,235,0, false ) 
end 
end 
end 
end 
end 
addCommandHandler ("hitme", hitme) 
  
function ondie () 
removeElementData( source, 'Player', "Hit" ) 
destroyElement ( hitBlip ) 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), ondie ) 

i just wrote this code now but i still need to know how to get the killer of thePlayer to finish this Script. Thanks

Link to comment
  • Moderators

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 ) 

Link to comment
  • Moderators
Are you kidding me ? you just changed outputs -.- and added another Date to the player.. and checks if the amount is number ..

and my ques is i want to check who killed the hit .. to get the money ..

Fixed your nasty code. You're welcome.

Link to comment
Are you kidding me ? you just changed outputs -.- and added another Date to the player.. and checks if the amount is number ..

and my ques is i want to check who killed the hit .. to get the money ..

Fixed your nasty code. You're welcome.

look at my ques ..pfft -.-

Link to comment
  • Moderators

Just don't forget you are here because you need help and to learn from others.

I fixed this nasty code and add a lot of comments (how to cancel a function, how to use elseif properly, how to use an element data instead of a global variable on the server side and other good practices like verifying what you get before performing an action on it).

But the only reaction you get is: "Learn to read you idiot !" (yeah it sounds pretty much the same).

If you don't want to listen about other advices, then alright ! do whatever you want, but you will stay a long time on this forum asking for help again and again because your script doesn't work when you get more that 1 player (Because that was exactly one of the problem of your script, if two players would use /hitme ammountHere at the same time, then code won't work for the first one who would use it).

I'll say it one more time: You are here because you need help and advices from others, not to yell on the first one who won't give you what exactly you wanted to get.

Hope you will understand my point of view and also that you won't go far in this community if you are acting like you just did with me.

Best regards,

Citizen

Link to comment
  • Moderators
You just took it wrong side .. i just mean that's not my ques not "learn to read you idiot" anyway if you thought this then you are wrong :) im not that rude. and sorry anyway .. :wink:

Ok fine. I'm okay.

So for your initial question, solstice gave you the answer:

function ondie ( totalAmmo, theKiller ) 

theKiller will just be the player who killed another one. So if the dead player had a blip in his element data "hitBlip" then it means he did the /hitme command and was waiting for himself to die.

I also just realised that you need another element data to know the moneyAmount the player wrote using /hitme to then get it in the ondie function and give him to the killer.

Link to comment
  • Moderators
about the player money, i will just remove local before playermoney define :)

rofl :lol: And then you will create another topic on this forum asking this:

Hello community,

I have a problem with my script. The problem is that it doesn't work properly when two players uses /hitme. Here are the step I did:

1 - Player1 uses /hitme 50000

2 - Player2 uses /hitme 120000

3 - Player3 kills Player1 and won $120000 instead of $50000

anyone can help ??

So stop thinking you are smarter that me and I'm just a noob. Pretty much all the advices/solutions I gave so far are clean and bugfree (anyone here to say I don't ?!).

So when I say you to use an element data, then use that damned elemrnt data.

I won't repeat again, and I won't help you anymore if you just don't give a sh*t about what I can say.

Thought you understood since my last post, but you still didn't ...

Link to comment
about the player money, i will just remove local before playermoney define :)

rofl :lol: And then you will create another topic on this forum asking this:

Hello community,

I have a problem with my script. The problem is that it doesn't work properly when two players uses /hitme. Here are the step I did:

1 - Player1 uses /hitme 50000

2 - Player2 uses /hitme 120000

3 - Player3 kills Player1 and won $120000 instead of $50000

anyone can help ??

So stop thinking you are smarter that me and I'm just a noob. Pretty much all the advices/solutions I gave so far are clean and bugfree (anyone here to say I don't ?!).

So when I say you to use an element data, then use that damned elemrnt data.

I won't repeat again, and I won't help you anymore if you just don't give a sh*t about what I can say.

Thought you understood since my last post, but you still didn't ...

Look cutie, if u still treat me like this fuc*ing way then shut the fu*k up, okay ? #Weird-Person .. i just said my thought about player money i didnt said " im smarter than u citezen and i will just remove local u stupid " .. i just said what i thought and u can reply no, if u did that then it will deduce that .. try to talk a better way or stfu .. have a nice day. :/

Link to comment
  • Moderators

Just to make everything clear:

1 - You wrote your script here asking for something specific about it.

2 - I replied normally with my version of this script with a lot of comments to explain what you did wrong and what were my changes.

3 - You replied this:

Are you kidding me ? you just changed outputs -.-

4 - Kept my calm and just replied your code was nasty and that I just fixed it.

5 - Instead saying thanks for that you wrote like if my code was 100% useless:

look at my ques ..pfft -.-

6 - Told you that you were forgetting were your place should be (listening to experienced members advices and learn from them, not to kick them out just because it wasn't the answer you were expecting).

7 - You did some kind of apologies

8 - At this point I forgave you and help you with your initial problem and pointed out another problem we both didn't see at the begining, the moneyAmount couldn't be known in the ondie function and told you how to get it (without a global, because you were already using a global with the blip but doing it with a global will just not work if two players use it. That's why I used an element data.)

9 - You just replied sayin you basicaly won't use an element data and just remove the local keyword (to make it global). So here you want to introduce again the same bug from the blip, but for the moneyAmount. I spent (notes here I didn't use wasted, because I never waste my time if it can make others better) time to help you out and fix the problem with the blip by using an element data instead. I also commented everything I changed and why I used element data.

i didnt said " im smarter than u citezen and i will just remove local u stupid "

By not reading my comments, not listening to my advices and by doing it your way, it's exactly the same as if you said it explicitly.

(Oh yeah and you also created another topic to ask the community how to fix the problem with your blip that I already fixed using element datas)

And after all of that you dare tell me to "try to talk a better way or stfu" and I also guess in that post that you did nothing wrong and that it's all my fault ?!

Ok then, it's all my fault, you are right. I'll just stfu because everything I said untill now was just useless, lies and wrong at the same time.

(All the things you need to actually make this script work without bug are in the posts above)

Bye.

Link to comment
Just to make everything clear:

1 - You wrote your script here asking for something specific about it.

2 - I replied normally with my version of this script with a lot of comments to explain what you did wrong and what were my changes.

3 - You replied this:

Are you kidding me ? you just changed outputs -.-

4 - Kept my calm and just replied your code was nasty and that I just fixed it.

5 - Instead saying thanks for that you wrote like if my code was 100% useless:

look at my ques ..pfft -.-

6 - Told you that you were forgetting were your place should be (listening to experienced members advices and learn from them, not to kick them out just because it wasn't the answer you were expecting).

7 - You did some kind of apologies

8 - At this point I forgave you and help you with your initial problem and pointed out another problem we both didn't see at the begining, the moneyAmount couldn't be known in the ondie function and told you how to get it (without a global, because you were already using a global with the blip but doing it with a global will just not work if two players use it. That's why I used an element data.)

9 - You just replied sayin you basicaly won't use an element data and just remove the local keyword (to make it global). So here you want to introduce again the same bug from the blip, but for the moneyAmount. I spent (notes here I didn't use wasted, because I never waste my time if it can make others better) time to help you out and fix the problem with the blip by using an element data instead. I also commented everything I changed and why I used element data.

i didnt said " im smarter than u citezen and i will just remove local u stupid "

By not reading my comments, not listening to my advices and by doing it your way, it's exactly the same as if you said it explicitly.

(Oh yeah and you also created another topic to ask the community how to fix the problem with your blip that I already fixed using element datas)

And after all of that you dare tell me to "try to talk a better way or stfu" and I also guess in that post that you did nothing wrong and that it's all my fault ?!

Ok then, it's all my fault, you are right. I'll just stfu because everything I said untill now was just useless, lies and wrong at the same time.

(All the things you need to actually make this script work without bug are in the posts above)

Bye.

Well, i have no time to read this but anyway im sorry if i hurt your feeling :) but i really dont mean to.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...