Solved ParallelTimer

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
ParallelTimer is not callingback? No errors.
I need a second pair of eyes to go over this.. I've been over this a million times and can not find out why its not calling back.
Tried on 1.1.6 and 1.1.7D
Python:
        elif cmd == "vtp":
            users = self.getUserIni()
            if users.GetSetting(Player.SteamID, "VTP") == "true" or Player.Admin:
                if len(args) == 0:
                    ds = DataStore.Keys("DonatorRank")
                    count = 1
                    Player.Message("Usage: /vtp [Number]")
                    for key in ds:
                        if key == "VTP" + str(count):
                            Player.Message(str(count) + ") - " + DataStore.Get("DonatorRank", key))
                            count += 1
                elif len(args) == 1:
                    waittime = int(DataStore.Get("DonatorRank", "VTPCoolDown"))
                    time = DataStore.Get("VTPCooldown", Player.SteamID)
                    time = int(time)
                    if time is None:
                        time = 0
                    calc = System.Environment.TickCount - time
                    if DataStore.Get("DonatorRank", "VTP" + args[0]) is not None:
                        if calc >= waittime or Player.Admin:
                            delay = DataStore.Get("DonatorRank", "VTPDELAY")
                            locname = DataStore.Get("DonatorRank", "VTP" + args[0])
                            Data = Plugin.CreateDict()
                            Data["PlayerID"] = Player.SteamID
                            Data["LocationName"] = locname
                            Data["Location"] = DataStore.Get("DonatorRank", locname).split(",")
                            Plugin.CreateParallelTimer("TeleportDelay", delay * 1000, Data).Start()
                            Player.Message("Teleporting in " + str(delay) + " seconds.")
                            #DataStore.Add("VTPCooldown", Player.SteamID, System.Environment.TickCount)
                            Player.MessageFrom("DEBUG", "Sending: " + Player.FindBySteamID(List["PlayerID"]).Name + " to location: " + List["LocationName"])
                            Player.MessageFrom("DEBUG", List["LocationName"] + " = " + str(List["Location"][0] + "," + List["Location"][1] + "," + List["Location"][2]))
                        else:
                            workingout = (round(waittime / 1000, 2) / 60) - round(int(calc) / 1000, 2) / 60
                            current = round(workingout, 2)
                            Player.Message(str(current) + " Minutes remaining before you can use this.")
                    else:
                        Player.Message("Usage: /vtp [Number]")
                else:
                    Player.Message("Usage: /vtp [Number]")
            else:
                Player.Message("You don't have permission to use this command!")

    def TeleportDelayCallback(self, timer):
        timer.Kill()
        Util.Log("CALLED BACK")
        Data = timer.Args
        Player = Player.FindBySteamID(Data["PlayerID"])
        if Player is not None:
            locname = Data["LocationName"]
            loc = Data["Location"]
            Player.TeleportTo(float(loc[0]), float(loc[1]), float(loc[2]))
            Player.InventoryNotice(locname)
        else:
            Util.Log("Failed")
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
ParallelTimer is not callingback? No errors.
I need a second pair of eyes to go over this.. I've been over this a million times and can not find out why its not calling back.
Tried on 1.1.6 and 1.1.7D
Python:
        elif cmd == "vtp":
            users = self.getUserIni()
            if users.GetSetting(Player.SteamID, "VTP") == "true" or Player.Admin:
                if len(args) == 0:
                    ds = DataStore.Keys("DonatorRank")
                    count = 1
                    Player.Message("Usage: /vtp [Number]")
                    for key in ds:
                        if key == "VTP" + str(count):
                            Player.Message(str(count) + ") - " + DataStore.Get("DonatorRank", key))
                            count += 1
                elif len(args) == 1:
                    waittime = int(DataStore.Get("DonatorRank", "VTPCoolDown"))
                    time = DataStore.Get("VTPCooldown", Player.SteamID)
                    time = int(time)
                    if time is None:
                        time = 0
                    calc = System.Environment.TickCount - time
                    if DataStore.Get("DonatorRank", "VTP" + args[0]) is not None:
                        if calc >= waittime or Player.Admin:
                            delay = DataStore.Get("DonatorRank", "VTPDELAY")
                            locname = DataStore.Get("DonatorRank", "VTP" + args[0])
                            Data = Plugin.CreateDict()
                            Data["PlayerID"] = Player.SteamID
                            Data["LocationName"] = locname
                            Data["Location"] = DataStore.Get("DonatorRank", locname).split(",")
                            Plugin.CreateParallelTimer("TeleportDelay", delay * 1000, Data).Start()
                            Player.Message("Teleporting in " + str(delay) + " seconds.")
                            #DataStore.Add("VTPCooldown", Player.SteamID, System.Environment.TickCount)
                            Player.MessageFrom("DEBUG", "Sending: " + Player.FindBySteamID(List["PlayerID"]).Name + " to location: " + List["LocationName"])
                            Player.MessageFrom("DEBUG", List["LocationName"] + " = " + str(List["Location"][0] + "," + List["Location"][1] + "," + List["Location"][2]))
                        else:
                            workingout = (round(waittime / 1000, 2) / 60) - round(int(calc) / 1000, 2) / 60
                            current = round(workingout, 2)
                            Player.Message(str(current) + " Minutes remaining before you can use this.")
                    else:
                        Player.Message("Usage: /vtp [Number]")
                else:
                    Player.Message("Usage: /vtp [Number]")
            else:
                Player.Message("You don't have permission to use this command!")

    def TeleportDelayCallback(self, timer):
        timer.Kill()
        Util.Log("CALLED BACK")
        Data = timer.Args
        Player = Player.FindBySteamID(Data["PlayerID"])
        if Player is not None:
            locname = Data["LocationName"]
            loc = Data["Location"]
            Player.TeleportTo(float(loc[0]), float(loc[1]), float(loc[2]))
            Player.InventoryNotice(locname)
        else:
            Util.Log("Failed")
Nothing much I think.

delay = DataStore.Get("DonatorRank", "VTPDELAY")

I think that's a string (Atleast i suspect that you store it as a string)

try doing
delay = int(DataStore.Get("DonatorRank", "VTPDELAY"))

If all the messages appeared that should be the only problem.

Suggestion:

Data["PlayerID"] = Player.SteamID

Data["Player"] = Player

That should also make the plugin a lot more faster.
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
Before:
Plugin.CreateParallelTimer("TeleportDelay", delay * 1000, Data).Start()
After:
Plugin.CreateParallelTimer("TeleportDelay", int(delay) * 1000, Data).Start()
int() the delay seemed to have worked, It was saved in the DataStore as a int() and even if I did Player.Message(delay) it would throw an error because it was expecting a str not an int, Interesting stuff but it works! Thanks DreTaX