Author Topic: c# scripting problem  (Read 9987 times)

0 Members and 1 Guest are viewing this topic.

Offline miezaTopic starter

  • Newbie
  • *
  • Posts: 4
  • Activity:
    0%
  • Reputation Power: 1
  • mieza has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
c# scripting problem
« on: January 14, 2015, 09:25:28 AM »
0
Code: [Select]
namespace firstMacro
{
    class Program
    {
        static DateTime lastBandage;
        static DateTime nextBandage;
        static double bandageDelay;

        static void Main(string[] args)
        {
            lastBandage = DateTime.Now;
            while (true)
            {
                int hp = Stealth.Script_GetSelfLife();
                int maxHp = Stealth.Script_GetSelfMaxLife();
                if (hp < maxHp)
                {
                    BandageSelf();
                }

            }
        }

        public static void BandageSelf()
        {
            bandageDelay = 5.0 + (0.5 * ((double)(120 - Stealth.Script_GetSelfDex()) / 10));
            nextBandage = lastBandage.AddSeconds(bandageDelay + 0.2); // + 0.2s is just for testing.

            if (nextBandage <= DateTime.Now)
            {
                Stealth.Script_SendTextToUO("[band");   // [band is a server command for bandaging.
                lastBandage = DateTime.Now;
            }
        }
        
    }
}


The problems are;
1- Stealth does'nt get hitpoints and any other stats instantly. (because of this, the script can't start to aid instantly)
2- After aiding successfuly, if hitpoints equals to maxhits, the script starts to wait the delay even if the character gets wounded in that time. (this could be related to script)

Stealth version : 6.0.0
Client version : 6.0.1.10
(if i want to update my stealth version, there becomes lots of problems, its the most stable version for me right now)



« Last Edit: January 14, 2015, 11:14:17 AM by mieza »

Offline Crome969

  • Moderator
  • *
  • *****
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +211
  • Referrals: 10
    • View Profile
    • ScriptSDK
Re: c# scripting problem
« Reply #1 on: January 14, 2015, 10:16:04 AM »
0
A Solution about API was posted here : http://www.scriptuo.com/index.php?topic=11628.msg107053#msg107053

API as it is currently still is a lot of slower (except in delphi) we are working on it..

Offline miezaTopic starter

  • Newbie
  • *
  • Posts: 4
  • Activity:
    0%
  • Reputation Power: 1
  • mieza has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: c# scripting problem
« Reply #2 on: January 14, 2015, 11:45:08 AM »
0
Ty for reply. A small question about time-based events. Which way do u prefer in c# if you need to use timers? Can you give an example :)

Offline Orich

  • Jr. Member
  • **
  • Posts: 77
  • Activity:
    0%
  • Reputation Power: 3
  • Orich has no influence.
  • Respect: +12
  • Referrals: 1
    • View Profile
Re: c# scripting problem
« Reply #3 on: February 14, 2015, 11:43:37 AM »
0
Ty for reply. A small question about time-based events. Which way do u prefer in c# if you need to use timers? Can you give an example :)

There is nothing wrong with your method.  You could, however, use the Timer class to clean things up.

Code: [Select]


private Timer _btimer = new Timer(bandageDelay * 1000); // convert seconds to miliseconds
_btimer.AutoReset = true; // make sure it recycles itself
_btimer.Elapsed += new ElapsedEventHandler(bandageSelf);
_btimer.Start();


private static void bandageSelf(object sender, ElapsedEventArgs e)
{
   Stealth.Script_SendTextToUO("[band");
}

Since it looks like what you're doing is buffering bandage cooldowns, you'd need to add the delay checks you're using.

This was just to give you an example of using the class.
Member of the Stealth development team.
Author of Stealth .NET DLL

Offline unisharp

  • Elite
  • ***
  • *
  • Posts: 196
  • Activity:
    0%
  • Reputation Power: 4
  • unisharp has no influence.
  • Gender: Male
  • Respect: +40
  • Referrals: 0
    • View Profile
Re: c# scripting problem
« Reply #4 on: March 22, 2015, 03:39:28 PM »
0
This works with the latest version of Stealth, ScriptAPI.cs and ScriptDotNet2

Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace firstMacro
{
    using ScriptDotNet2;
    using ScriptAPI;

    class Program
    {

        public static void BandageSelf(Item Bandage)
        {
            Bandage.Use();
            Stealth.Default.WaitTargetSelf();
            Console.WriteLine("Bandaging self...");
            Stealth.Default.WaitJournalLine(DateTime.Now, "You finish applying the bandages|You apply the bandages, but they barely help|You heal what little damage your patient had|You did not stay close enough to heal your patient|That is too far away", 15000);
        }

        static void Main(string[] args)
        {
            List<Item> Bandages = Find.FindItems(3617, Self.Backpack.ID);

            if (Bandages.Count == 0)
            {
                Console.WriteLine("No bandages found.");
                Environment.Exit(0);
            }

            Item Bandage = Bandages[0];


            while (Profile.IsConnected)
                if (Self.HP < Self.MaxHP)
                    BandageSelf(Bandage);
        }

    }
}

You can get the latest version of Stealth and ScriptDotNet2 here: http://www.scriptuo.com/index.php?topic=13054.msg108171#msg108171
Latest version of ScriptAPI.cs here: http://www.scriptuo.com/index.php?topic=13054.msg108167#msg108167

It started bandaging as soon as it took any damage and retries until full health.

EDIT: If anyone reads this and sees a way to shorten/improve on code please post so I learn! :)
« Last Edit: March 22, 2015, 03:41:52 PM by sibble »

Tags: