Razor Enhanced Basics

From UO Eventine Wiki
Jump to navigation Jump to search

This page will add some basics to know and help when coding things in Razor Enhanced. The attempt on writing this is to make it as easy as possible to understand some things and will just give a basic example and try to not get too technical to keep learning as easy.

Indent

An Indent is a very important part of Python. Indents can be made by hitting the Tab key or space bar to create 4 empty spaces. Using Indents are required to add actions or responses to use when a query/condition is met.


EXAMPLE:

If Player.Hits < 20:
    Player.ChatSay("Health is low!")
    Misc.Pause(3500)  
Misc.Pause(50)
Misc.SendMessage("No Longer inside Query")
‎

With this above example, we can see that when the query of if your player has less than 20 hitpoints, it will say 'Health is low!" and then pause for 3.5 seconds. It will then exit what to do after as there are no more direct lines beneath that are in the same indent. This will result in a pause of 50ms and the send message "No Longer inside Query" to go if hits are 20 or over or go after the above conditions actions are finished.


Having actions for a query/condition met inside the first would require a new indent to be placed.


EXAMPLE:

If Player.Hits < 20:
    Player.ChatSay("Health is low!")
    Misc.Pause(3500)
    If Player.Stam > 200:
        Player.ChatSay("But our stamina is over 200!")
        Misc.Pause(2500)
Misc.Pause(50)
Misc.SendMessage("No Longer inside Query")
‎

With this code, we added a check to see when our hits are under 20 if our stamina is over 200. This query/condition when met will result in it having the player say "But our stamina is over 200!" and then pause for 2500. This query/condition can only be accessed if the first query/condition is met of the player's hit points being under 20.

Methods

A method can be a sample of code to run that is only called upon when needed and will not force razor enhanced to only call it when part of the code requires it.

EXAMPLE:

self = Mobiles.FindBySerial(Player.Serial)

def castHealOnSelf():
    Spells.Cast("Greater Heal")
    Target.WaitForTarget(3500,False)
    Target.TargetExecute(self)
    
while Player.Connected:
    if Player.Hits < 50:
        castHealOnSelf()
    Misc.Pause(650)

Let's break down the above code into parts to see what is going on to learn more about what is happening.

self = Mobiles.FindBySerial(Player.Serial) This code is setting the 'self' variable to be linked to the player and tells Razor Enhanced that the variable is also a mobile so we can call on it later without having to write too much code every time.

def castHealOnSelf(): is the method that can be called at any time in this script by using "castHealOnSelf()". This will run all lines that are indented under it before a line that is not indented appears, which in this case, is 3 lines.

notice the next three lines are indented to tell razor enhanced they will run with the above method

Spells.Cast("Greater Heal") tells the game to cast the spell "Greater Heal".

Target.WaitForTarget(3500,False) is telling the script to not go further until a target appears on screen or 3500ms goes past (3.5 seconds). If the target does not appear it will just continue through as well so setting the wait time can vary on latency or your isps routing to a server.

Target.TargetExecute(self) is having the spell target yourself with the 'self' variable we set at the top stating it is for your player.

while Player.Connected: means that the code will run as long as the player is connected to the game. If they are not this code will stop.

these next three lines are indented so they will only run if your player is connected to the game.

if Player.Hits < 50: is a condition that needs to be met to run the following lines again. This one will only run the below code if your hit points go under 50.

castHealOnSelf() is where the script itself is calling the method to heal yourself we set above.

Misc.Pause(650) is set to pause for 650ms either after the healing method runs to heal yourself, or your hits are above 50 and do not go to the method. It is always good to have a pause here when this script will loop of some sort to help your pc from a potential crash from running too fast and having an error occur.

Lists

Import

Gumps

Looping