Jump to content

Creating a random number


Hae

Recommended Posts

Hi! I am trying to change this mod.

The mod teleports the player to a tile in the world. 

I would like to find a random tile in one area. This is to prevent campers or to build a structure to box the player inside the fixed tile. 

 

 

Something like:
math.randomseed(os.time()) -- seed the random number generator with the current time
random_number1 = math.random(12712, 12788)
random_number2 = math.random(1434, 1372)
X = random_number1
Y = random_number2

 

 

ISInventoryMenuElements = ISInventoryMenuElements or {};
 
function ISInventoryMenuElements.ContextTeleporter()
    local self = ISMenuElement.new();
    self.invMenu = ISContextManager.getInstance().getInventoryMenu();
 
    function self.init()
    end
 
    function self.createMenu( _item )
        if _item:getFullType() == "Base.BusTicket" then
            local teleMenu = self.invMenu.context:addOption( "Travel", self.invMenu, nil );
            local telePoints = SSDart.Transporter.GetAvailablePoints();
            local submenu = self.invMenu.context:getNew( self.invMenu.context );
            self.invMenu.context:addSubMenu( teleMenu, submenu );
            print("======================> Processing '" .. #telePoints .. "' traveling points" );
            for _, pointName in ipairs(telePoints) do
                submenu:addOption( "Travel to '" .. pointName .."'", self.invMenu, self.TeleportTo, pointName );
            end
            if SSDart.Transporter.CanReturn() then
                submenu:addOption( "Return", self.invMenu, self.Return );
            end
        end
    end
 
    function self.TeleportTo( items, player, pointName )
        SSDart.Transporter.MoveTo( items, player );
    end
 
    function self.Return( player )
        SSDart.Transporter.Return( player );
    end
 
    function self.openMovableCursor( _p, _item )    
        local tpx = 12697;
        local tpy = 2347;
        local tpz = 0;
       
        local player = _p.player;
        player:setX(tpx);
        player:setY(tpy);
        player:setZ(tpz);
        player:setLx(player:getX());
        player:setLy(player:getY());
        player:setLz(player:getZ());
    end
 
    return self;
end
 
 
SSDart = SSDart or {};
 
local function transporterInit()
    local transporter = {
        _regPoints = {},
        _returnPoint = {}
    }
 
    function transporter.AddPoint( id, x, y, z )
        if not id then
            error("There was no ID given", 2 );
        end
        if type(id) ~= "string" then
            error("The given ID is not a string", 2 );
        end
        transporter._regPoints[ id ] = {
            X = x,
            Y = y,
            Z = z or 0
        }
    end
 
    function transporter.MoveTo( player, id )
        print("=======================> Moving player '" .. tostring(player) .. "' to point '" .. id .. "'");
        player = player.player;
        print("=======================> Moving player '" .. tostring(player) .. "' to point '" .. id .. "'");
        local lastPos = {
            X = player:getX(),
            Y = player:getY(),
            Z = player:getZ()
        }
        local newPoint = transporter.GetPoint( id );
       
        player:setX( newPoint.X );
        player:setY( newPoint.Y );
        player:setZ( newPoint.Z );
        player:setLx( newPoint.X );
        player:setLy( newPoint.Y );
        player:setLz( newPoint.Z );
        transporter._returnPoint.Last = lastPos;
    end
 
    function transporter.GetAvailablePoints()
        local points = {};
        for pointName, _ in pairs(transporter._regPoints) do
            table.insert(points, pointName);
        end
        return points;
    end
 
    function transporter.GetPoint( id )
        for pointName, point in pairs(transporter._regPoints) do
            if pointName == id then
                return point;
            end
        end
        error("There is no point with ID of '" .. id .. "'", 2 );
    end
 
    function transporter.CanReturn()
        if not transporter._returnPoint.Last then
            return false;
        else
            return true;
        end
    end
 
    function transporter.Return( player )
        player = player.player;
        local returnPoint = transporter._returnPoint.Last;
        player:setX( returnPoint.X );
        player:setY( returnPoint.Y );
        player:setZ( returnPoint.Z );
        player:setLx( returnPoint.X );
        player:setLy( returnPoint.Y );
        player:setLz( returnPoint.Z );
        transporter._returnPoint.Last = nil;
    end
 
    return {
        AddPoint = transporter.AddPoint,
        MoveTo = transporter.MoveTo,
        GetAvailablePoints = transporter.GetAvailablePoints,
        CanReturn = transporter.CanReturn,
        Return = transporter.Return
    }
   
end
 
SSDart.Transporter = transporterInit();
 
SSDart.Transporter.AddPoint(
    "Louisville",
    12697,
    2347
);
 
SSDart.Transporter.AddPoint(
    "Rosewood",
    8093,
    11658
);
 
SSDart.Transporter.AddPoint(
    "WestPoint",
    11927,
    6886
);
 
SSDart.Transporter.AddPoint(
    "Muldraugh",
    10604,
    9934
);
 
SSDart.Transporter.AddPoint(
    "Riverside",
    6538,
    5309
);
 
SSDart.Transporter.AddPoint(
    "MarchRidge",
    10009,
    12706
);
 
SSDart.Transporter.AddPoint(
    "Raven Creek",
    4018,
    11245
);
 
SSDart.Transporter.AddPoint(
    "Ashenwood",
    11459,
    11230
);
BT.Transporter.AddPoint(
    "Grapeseed",
    7312,
    11192
);
 
BT.Transporter.AddPoint(
    "Blackwood",
    8095,
    10735
);
 
BT.Transporter.AddPoint(
    "Ekron",
    7272,
    8540
);
 
BT.Transporter.AddPoint(
    "Chestown",
    4546,
    6792
);



 
Link to comment
Share on other sites

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
×
×
  • Create New...