Script runs twice

Post Reply
User avatar
tabitaru
Posts: 99
Joined: Sun Apr 12, 2015 4:49 am

Script runs twice

Post by tabitaru » Wed Jul 22, 2015 6:26 am

!
Last edited by tabitaru on Sun Oct 18, 2015 7:14 am, edited 1 time in total.

Desufire
Posts: 162
Joined: Sun Feb 22, 2015 2:58 am

Re: Script runs twice

Post by Desufire » Wed Jul 22, 2015 6:58 am

Tab out your ifs and elseifs?

Code: Select all

 
function onGameHour()
local monk=GetMobAction(17682442);
local horror=GetMobAction(17682446);
local rough = math.random(1,50);
print("Random Number = "..rough);
print("Is Spawned Monk = "..monk);
print("Is Spawned Horror = "..horror);
         if(monk ==0) and (rough <=3) and (horror ==0) then
            SpawnMob(17682442);
         elseif (monk ==0) and (horror ==0) and (rough >=49) then
            SpawnMob(17682446);
         elseif (monk ~=0) and (horror ==0) and (rough >=49) then
            DespawnMob(17682442);
            SpawnMob(17682446);
         end
end;

User avatar
tabitaru
Posts: 99
Joined: Sun Apr 12, 2015 4:49 am

Re: Script runs twice

Post by tabitaru » Wed Jul 22, 2015 8:06 am

!
Last edited by tabitaru on Sun Oct 18, 2015 7:15 am, edited 1 time in total.

User avatar
TeoTwawki
Developer
Posts: 527
Joined: Mon Jul 15, 2013 9:50 pm

Re: Script runs twice

Post by TeoTwawki » Wed Jul 22, 2015 11:56 am

Code: Select all

function onGameHour()
    local monk = GetMobAction(17682442);
    local horror = GetMobAction(17682446);
    local rough = math.random(1,50);
    print("Random Number = "..rough);
    print("Is Spawned Monk = "..monk);
    print("Is Spawned Horror = "..horror);
    if (monk == 0 and rough <=3 and horror == 0) then
        SpawnMob(17682442);
    elseif (monk == 0 and horror == 0 and rough >= 49) then
        SpawnMob(17682446);
    elseif (monk ~= 0 and horror == 0 and rough >= 49) then
        DespawnMob(17682442);
        SpawnMob(17682446);
    end
end;
Formatted properly*.
And I see no reason why this code would exec twice on the same game hour trigger.. /shrug

* While lua is not a whitespace sensitive language, its much more difficult on my eyes when ppl mess it up..
Hi, I run The Demiurge server.


Image
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
PLS USE [ code ] CODE TAGS [ /code ] WHEN POSTING CODE
DO NOT PRIVATE MESSAGE ME ABOUT BUGS

User avatar
tabitaru
Posts: 99
Joined: Sun Apr 12, 2015 4:49 am

Re: Script runs twice

Post by tabitaru » Thu Jul 23, 2015 3:54 am

!

Post Reply