Jump to content

Fix a script..


WiBox

Recommended Posts

Timer10 = setTimer(
    function ()
        time0 = 1
        for _,plrs in ipairs(getElementsByType("player")) do
            if ( getElementDimension (plrs) == 0 ) then
                if ( not addCommandHandler("usemedkit", usethemedkit) ) then
                    addCommandHandler("usemedkit", usethemedkit)  
                    addCommandHandler("acceptmedkit", healOthers)
                    addEventHandler("meds.giveMedKit", root, giveMedKit)
                    addEventHandler("meds.useMedKitOnOther", root, usemedkitanother)    
                end                    
                if ( addCommandHandler("usemedkit", usethemedkit) ) then
                    killTimer(Timer10)
                end
                if ( getElementDimension (plrs) == 336 ) then
                    if ( addCommandHandler("usemedkit", usethemedkit) ) then
                        killTimer(Timer10)
                    end
                    if ( not addCommandHandler("usemedkit", usethemedkit) ) then
                        resetTimer(Timer10)
                    end
                if ( addCommandHandler("usemedkit", usethemedkit) ) then
                    killTimer(Timer10)
                end
                timer0 = timer0 - 1
                if ( timer0 < 0 ) then
                    killTimer(Timer10)
                end
            end
        end
    end
end, 1000, 0)    

I made that script but my problem is it's saying in console: addEventHandler ['meds.useMedKit with this function is already handled], I tried like 6 times fix it so it stop spamming in the console but it isn't working.. Can someone help please? I just need a way to stop the spams in my console.. I tried killTimer but didn't work, I appreciate who help and thanks.

Link to comment

I made a script which disable medkits in dimension 336. the thing is, it work but it spam that                 addEventHandler ['meds.useMedKit with this function is already handled]

I want a way for I stop that spam, those spam come from the 2 lines 9, 10.

Link to comment

Why do you have that inside of a timer?

This is what you're doing
 

function usethemedkit()
	--code
end
addCommandHandler("usemedkit", usethemedkit)
addCommandHandler("usemedkit", usethemedkit)
addCommandHandler("usemedkit", usethemedkit)........

and it will keep adding command handlers to the same functions over and over

if you want to disable a function in a dimension just check the player's dimension when they use the command.

  • Thanks 1
Link to comment

That's why I'm trying to kill the Timer, I just want it too add one time the command handler if it wasn't created.. 

I need a way that, if the command handler already created then the timer get destroyed, any hints please?

Edited by SSKE
Link to comment

Then just add the commands don't put it in a timer.

function name(player)
  if getElementDimension(player) == 0 then -- only execute if the player's dimension is 0
  	--code
  end
end
addCommandHandler("usemedkit", name)

-- or 

function name(player)
  if getElementDimension(player) ~= 336 then -- only execute if the player's dimension is not 336
  	--code
  end
end
addCommandHandler("usemedkit", name)

 

  • Thanks 1
Link to comment

Dude I'll explain from the beginning, I made a code which if the player go back to the main dimension it re add:

addCommandHandler("usemedkit", usethemedkit)
addCommandHandler("acceptmedkit", healOthers)
addEventHandler("meds.giveMedKit", root, giveMedKit)
addEventHandler("meds.useMedKitOnOther", root, usemedkitanother)  

Those 4 I remove them with a command and I can back them with a command, but if he goes back to the main dimension I want for those 4 get added automatically. That's all

 

Edited by SSKE
Link to comment

You used command handler to back them.. If the player used a command for leave the dimension 336 before I use the command for back his medkits.. how should I back his medkit? Won't work like you told me..

 

  1. Timer10 = setTimer(
        function ()
            time0 = 1
            for _,plrs in ipairs(getElementsByType("player")) do
                if ( getElementDimension (plrs) == 0 ) then
                    if ( not addCommandHandler("usemedkit", usethemedkit) ) then
                        addCommandHandler("usemedkit", usethemedkit)  
                        addCommandHandler("acceptmedkit", healOthers)
                        addEventHandler("meds.giveMedKit", root, giveMedKit)
                        addEventHandler("meds.useMedKitOnOther", root, usemedkitanother)    
                    end                    
                    if ( addCommandHandler("usemedkit", usethemedkit) ) then
                        killTimer(Timer10)
                    end
                    if ( getElementDimension (plrs) == 336 ) then
                        if ( addCommandHandler("usemedkit", usethemedkit) ) then
                            killTimer(Timer10)
                        end
                        if ( not addCommandHandler("usemedkit", usethemedkit) ) then
                            resetTimer(Timer10)
                        end
                    if ( addCommandHandler("usemedkit", usethemedkit) ) then
                        killTimer(Timer10)
                    end
                    timer0 = timer0 - 1
                    if ( timer0 < 0 ) then
                        killTimer(Timer10)
                    end
                end
            end
        end
    end, 1000, 0)    

I made the code and it worked! But I just need to stop the spam which come from the lines 9 and 10. I need a way to kill the timer once the commandhandler and event handler get added.. 

https://imgur.com/a/nHDP3Nv 

This spam I mean.. 

Edited by SSKE
Link to comment

In line 9 and 10, you have added root element to the event, means, when this for loop run it's first time, event already added to all players. So no need to add that event again to other. So I suggest to change the argument 2 of event handlers in line 9 and 10 to plrs.

 

And what about the using of local variable called "executed" ??

local executed = false -- executed is false when resource starts --

Timer10 = setTimer(
    function ()
        time0 = 1
        for _,plrs in ipairs(getElementsByType("player")) do
            if ( getElementDimension (plrs) == 0 ) then
                if ( executed == false ) then
                    addCommandHandler("usemedkit", usethemedkit)  
                    addCommandHandler("acceptmedkit", healOthers)
                    addEventHandler("meds.giveMedKit", root, giveMedKit)
                    addEventHandler("meds.useMedKitOnOther", root, usemedkitanother)    
                    executed = true
                end                    
                if ( executed ) then
                    killTimer(Timer10)
                end
                if ( getElementDimension (plrs) == 336 ) then
                    if ( executed ) then
                        killTimer(Timer10)
                    end
                    if ( executed == false ) then
                        resetTimer(Timer10)
                    end
                if ( executed ) then
                    killTimer(Timer10)
                end
                timer0 = timer0 - 1
                if ( timer0 < 0 ) then
                    killTimer(Timer10)
                end
            end
        end
    end
end, 1000, 0)    
  • Thanks 1
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...