Limelight Forums

Full Version: Adding /roll
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Suggestion for <in-game.>

In detail, explain your suggestion:

Simply put, just a /roll command from 1-100 for those who wish to add a bit of flavor to their RPs.

Why should this be implemented?

For those wanting to add more detail to their RPs its often times not exactly easy to decide who does what in say a fist fight.


If i attempt to grab ones arm to gain the upperhand, how do we decide who actualy pulls it off?

Often times both want theirs to succeed but choseing isnt exactly easy, with this just /roll and essentialy have it decided for you, depending on how much higher the roll decides just how successfull the action was.

This would be optional and meerly there for those who want to make use of it.

Me being talked to by an officer about my improperly parked car, that is also a getaway vehicle, i ask the officer if hes willing to go along with a more detailed Roll RP, he agrees.

[me=BlackDog]attempts to kick the officer in the balls[/me]
/roll (86)
Officer rolls to avoid /roll (15)

In this case he just got sacked and has no ground to attempt a counter as his roll was so much lower and since he agreed to go along with it, would RP accordingly, adding a bit of flavor to the situation for those involved.

Of course if the roll's were reversed, good chance he could now counter the attack and the RP would move in an entirely different direction where neither party is sure how it will end, but that in the end the results we're unexpected, but fair
Do it, and do it now.
+support
+1
This would be a great addition.
[move]
[Image: sgk3r5.png]
[/move]
+Support
Approved.
It would be a nice addition to be able to specify the range of your rolls for some casino/gambling RP (eg. Blackjack)
Following the WoW system would be nice.

You'd also have to distinguish the color from that of /its etc, as scripts could be set up easily enough.
+Support
Why not make it so you can change the number that it is out of, and the multiple it could be of? For example, roll a d20, /roll 1d20.

+support
Got bored while sitting around on holiday, so here is a dice system for you guys.

Features two console commands "rtd" and "rtd_last" where the "_last" variant shows your previous roll exactly as last ( there is a clear warning stating it was last roll so ya know can't be used later on by others to cheat and such). Uses the Player Metatable so looks pretty clean when used in other scripts simple "PlayerObject:RollDice(Min, Max, #Dice)".

You are also able to specify the minimum, maximum and no. Of dice to be used on the roll ( all results are printed out, will probably expand when I get back to have multiple different sized "dice" used for different roles e.g. 2 d20 1 d23 3 d100 or something similar)

Cool down is also implemented to prevent spamming but there is no visual indicator that you're on cool down, though it's only 1 second so it's not a huge problem. Anyways onto code etc.

https://hastebin.com/epewudileg.lua link to the syntax highlighted version

Code:
-- Created by Spy (steamcommuntiy.com/id/Snappey)

if SERVER then

    util.AddNetworkString("PlayerRolled")
    util.AddNetworkString("GetLastRoll")
    
    local function PackageResult(tbl)
    local str = "" -- so we cant add other strings to it
        for k,v in pairs(tbl) do
            str = str .. "[ Dice #"..k.."] Rolled " .. v.res .. " (min: " .. v.min ..", max: " .. v.max..") /n" -- newline maybe idk
        end
        return str
    end
    
    local function GetNearbyPlayers(pos)
        local tbl = {}
        for k,v in pairs(ents.FindInSphere(pos, 240)) do -- Think 240 is distance of talking
            if !v:IsPlayer() then return end
            table.insert(tbl, v)
        end
        return tbl
    end
    
    
    local meta = FindMetaTable("Player")
    
    function meta:RollDice(min,max,l)
    self.LastRoll = {} -- reset last roll
        if l == nil then l = 1 end -- incase they dont give a third arg
        for i=1, l do
            self.LastRoll[i] = {res = math.random(min, max), min = min, max = max}
        end
        return self.LastRoll
    end

    concommand.Add("rtd", function(ply,cmd,args)
        if ply.DiceCooldown == nil then ply.DiceCooldown = 0 end -- that should prevent a nil index i believe
        if CurTime() > ply.DiceCooldown + 1 then -- Cooldown to stop people spamming it just change the number
            local str = PackageTable(ply:RollDice(args[1], args[2], args[3]))
            net.Start("PlayerRolled")
                net.WriteString(str)
            net.Send(GetNearbyPlayers(ply:GetPos()))
            ply.DiceCooldown = CurTime()
        else
            -- tell them there is a cooldown
        end
    end)
    
    concommand.Add("rtd_last", function(ply,cmd,args)
        if ply.DiceCooldown == nil then ply.DiceCooldown = 0 end -- same as above
        if CurTime() > ply.DiceCooldown + 1 then -- probably an easy way to simplify this to ome command but whatever
            local str = PackageTable(ply.LastRoll)
            net.Start("GetLastRoll")
                net.WriteString(str)
            net.Send(GetNearbyPlayers(ply:GetPos()))
            ply.DiceCooldown = CurTime()
        else
            -- tell them there is a cooldown
        end
    end)

else

    net.Receive("PlayerRolled", function()
        chat.AddText(net.ReadString()) -- idk how you want it prefixed etc.
        -- iirc last time i used chat.AddText colours just defaulted to bland yellow probs a gamemkde thimg
    end)
    
    net.Receive("GetLastRoll", function()
        chat.AddText("[LAST ROLL] " .. net.ReadString())
    end)
    
end

There is all the code that's used.

Now how to use in its current state, afaik you guys use the inbuilt plugin system I can't remember all the needed functions for that shit so you know here it is in normal form shove it into lua/autorun for the curious who'd like to try it.

How the player can use it is through the console as idk how your chat command system works and there is no need for me to add another not needed hook to your guys GM.

Input: rtd 1 100 5
Rolls 5 dies with the range of 1-100
Arg 1: minimum range
Arg 2: maximum range
Arg 3: amount of times to roll

Output: [Dice #1] Rolled 45 (min: 1, max: 100) and so on for each dice roll thereafter, repeated 5 times in our case

In hind sight there should be a check to ensure that arg1 is smaller than arg2 or some system that switches them around if need be, but cbf to do that now idk if it'll error or not it might be clever itself.

Improvements / changes will no doubt be needed as I have wrote this completely on my phone with no testing or documentation available. Should be fun though might be a small error here and there whatever nothing impossible to fix. Point is general logic and system has been implemented.

One major thing required can't remember if I mentioned it or not you guys probably want to make your own chat commands for it.

Pretty sure that's everything, sorry if  the post is reaaaallly long here is a TLDR

I created a basic roll system on my phone tis completely untested however should work fine after reading over a couple of times. You guys want to make your own chat commands as well.

Thanks, Spy  Smile

Welp, seems like we have an RTD system now.
Alright two things I'd just remembered that literally anyone with a shred of experience in Lua can fix:

1. You can currently go rtd 1 2 100000

You now have chat spammed and or server frozen and or net library refusing to send a string that large

Just limit to 5 I think Joey suggested that was a fine amount

2. You can't actually see who rolled he dice, oversight by me thought I designed it with that in mind turns out I didn't.

In the net.WriteString section add the players name to the start.

Ez fixes sorry for the bugs Big Grin
... What? Why are you utilizing two network variables for this? It does not give sense any sense, you are making the server handle both net.Receive and net.Start lol.

Simply make 1 (or 2 if you want to) concommands on the server-side and handle the rolling and such from there. There is absolutley no need to store a network variable on the player, just store a variable on the player instead.

Note, careful on your variables.
local str = PackageTable(ply:RollDice(args[1], args[2], args[3]))
net.WriteString(str)

Is the same as

net.WriteString(PackageTable(ply:RollDice(args[1], args[2], args[3])))

I know that the above looks better since you store a string, but you are performing 1 extra unnecessary operation.

Also, in your GetNearbyPlayers function, just store 1 table instead before the function, otherwise you will keep adding tables in the stack which is generally a bad idea (unless you want it to overflow lol, I do not believe Lua had a garbage collector). At start, clear the table and then add the players to the table.
(Aug 26, 2015, 03:30 PM)Rayts5 link Wrote: [ -> ]Note, careful on your variables.
local str = PackageTable(ply:RollDice(args[1], args[2], args[3]))
net.WriteString(str)

Is the same as

net.WriteString(PackageTable(ply:RollDice(args[1], args[2], args[3])))

I know that the above looks better since you store a string, but you are performing 1 extra unnecessary operation.

Its easier to read and debug if you do it this way, I do things like this aswell
Pages: 1 2