THASMOG Posted April 24, 2013 Share Posted April 24, 2013 Hello, i am very new at mta scripting. And wanted to ask how to make scripts that autokills battleloggers. I try to explain. There is two players: Player 1 and Player 2. If Player 1 shots Player 2. Player 2 gets timer at bottom of his/her screen that countdowns 60 to 0. If he logouts before 0 he dies. So that means he cant run away from kill. But if Player 1 kills Player 2 before 0 the countdown just dissapears. And if Player 2 shots Player 1 back, they both would have timer. Maybe it's possible to make it only from other player dmg. Like if Player 1 jumps off cliff and getgs damage he wont get timer. I tryed to find it from online and tryed to make something myself. This is what i made from tutorials. function battlelogger ( attacker, weapon, bodypart, loss ) if ( bodypart == 9,8,7,6,5,4,3) then countdown = time outputChatBox(time) setTimer(reduceCountdown, 1000, countdown) end addEventHandler ( "onPlayerDamage", getRootElement (), battlelogger ) addCommandHandler("starttimer", startTimer) function reduceCountdown() countdown = countdown - 1 outputChatBox(countdown) if (countdown == 0) then outputChatBox("Start") end end function createBattleTimer() local sWidth, sHeight = guiGetScreenSize() local Width,Height = 800,45 local X = (sWidth/2) - (Width/2) local Y = sHeight - (Height/2) battleGridlist = guiCreateGridList(X,Y,Width,Height,false) battleLabel = guiCreateLabel(X,Y,Width,Height/2,"Test text",false,battleGridlist) loadBattleTimer() updateBattleItem(1) currentItem = 1 end addEventHandler("onClientResourceStart",resourceRoot,createBattleTimer) Thanks ! Link to comment
Jaysds1 Posted April 24, 2013 Share Posted April 24, 2013 Is this the full script? BTW, there's a server-side event and a client-side event in the same script, they have to be separated. Link to comment
THASMOG Posted April 24, 2013 Author Share Posted April 24, 2013 No this is my first try. I started learning yesterday. Link to comment
xXMADEXx Posted April 24, 2013 Share Posted April 24, 2013 Replace: if ( bodypart == 9,8,7,6,5,4,3) then with if ( bodypart==9) or (bodypart==8) or (bodypart==7) or (bodypart==6) or (bodypart==5) or (bodypart==4) or (bodypart==3) then Link to comment
Jaysds1 Posted April 24, 2013 Share Posted April 24, 2013 Sorry, but the only thing I can say right now is to learn more about lua. Please read this: https://forum.multitheftauto.com/viewtopic.php?f=148&t=40809 Link to comment
THASMOG Posted April 25, 2013 Author Share Posted April 25, 2013 That tutorial looks nice yeah i'm reading more just hoped u guys can help me more Help: Do it for myself Link to comment
Moderators IIYAMA Posted April 25, 2013 Moderators Share Posted April 25, 2013 You can also try: client + serverside? It reduces CPU lagg. You can use timers, but you are already needed to use direct x for showing the countdown. You can make this with getTickCount and onClientRender. So why not let the client calculate it and trigger it? (check it again on server side) Link to comment
THASMOG Posted April 25, 2013 Author Share Posted April 25, 2013 I readed a bit lua. Maybe the first script is too complicated for me So i start like that: function battlelogger ( attacker, weapon, bodypart, loss ) if ( bodypart==9) or (bodypart==8) or (bodypart==7) or (bodypart==6) or (bodypart==5) or (bodypart==4) or (bodypart==3) then Now i need to add some timer. Link to comment
Moderators IIYAMA Posted April 25, 2013 Moderators Share Posted April 25, 2013 local bodyParts = { [9]=true,[8]=true, [7]=true,[6]=true, [5]=true,[4]=true, [3]=true }--table function battlelogger ( attacker, weapon, bodypart, loss ) if bodyParts[bodypart] then -- check if the value is 3 t/m 9. end-- don't forget the end. end timers for every player local myTimers = {} -- create a place(table) where you store the userdata from the timers. So you will be able to stop the timer for every single player. ------------------------------------------------------------------------------------------------------ -- source is the player that got damaged when you use the event "onPlayerDamage". ------------------------------------------------------------------------------------------------------- -- check if you haven't already a timer that is working with this player. if not myTimers[source] then -- here we set a timer the data location is the player him self also we call it the key or index value. So if you know the player you also know what timer he uses. myTimers[source] = setTimer(reduceCountdown, 1000, countdown) -- and of course an end for every function, loop or "if" end Link to comment
THASMOG Posted April 25, 2013 Author Share Posted April 25, 2013 Thanks very mutch. Like i see there is timer and damage think now i must make player kill if he disconnects before timer and GUI. I try tomorrow now i go to sleep 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