Vai al contenuto
Roblox

Scripting

Script Luau per giochi Roblox: sistemi di gioco, meccaniche e codice di utilità, scritti per essere letti e riutilizzati.

4.5 su 515 asset

Mega Dodgeball

6 assetScripting Lua avanzato: meccaniche della palla basate sulla fisica, sincronizzazione multigiocatore in tempo reale, sistemi di progressione e una gestione completa dello stato della partita.
Pagina del gioco
VideoMenu delle impostazioni
0:00 / 0:00
Un'anteprima del menu delle impostazioni, con interruttori e cursori trascinabili per il volume e altro
VideoSistema di scelta della mappa
0:00 / 0:00
Un'anteprima del sistema di scelta della mappa, con l'elenco delle mappe e gli avatar dei giocatori che hanno votato ciascuna
VideoSistema di equipaggiamento e personalizzazione
0:00 / 0:00
Un video del sistema di equipaggiamento e personalizzazione, con l'elenco degli oggetti e la personalizzazione che si applica equipaggiandoli
VideoEliminazioni e round
0:00 / 0:00
Il sistema di eliminazioni e round: cosa succede quando un giocatore ne elimina un altro e come l'ultima eliminazione chiude il round
Ball Physics System
local ball = script.Parent -- Ball object
local runService = game:GetService("RunService") -- RunService for time tracking

local function playBounceSound(ballVelocity)
	local speed = ballVelocity.magnitude -- Get the speed of the ball

	-- volume and playback rate based on speed
	local volume = math.clamp(speed / 40, 0, 1) 
	local playbackRate = math.clamp(speed / 50, 0.85, 1.15)

	ball.BallBounce:Play()
	ball.BallBounce.Volume = volume
	ball.BallBounce.PlaybackSpeed = playbackRate

	local currentTime = runService.Stepped:Wait() -- Get the current time
	lastSoundTime = currentTime -- Update the last sound time
end
Dodgeball Physics Based Sound
local tool = script.Parent
local ball = tool.Handle
ball.CanTouch = false

function shootBall(direction)

	tool.Handle.BallBounce:Play()

	local vCharacter = tool.Parent
	local vPlayer = game.Players:GetPlayerFromCharacter(vCharacter)
	
	local missile:MeshPart = ball:Clone()
	local dangerball = tool.DangerBall
	local spawnPos = vCharacter.PrimaryPart.Position

	spawnPos  = spawnPos + (direction * 5)

	missile.Position = spawnPos
	missile.AssemblyLinearVelocity = direction * 200
	missile.CustomPhysicalProperties = PhysicalProperties.new(
		1.6,			-- Density
		1.55,		 	-- Friction
		0.85			-- Elasticity
	)
	missile.CanCollide = true	
	missile.CanTouch = true
		
	missile.isDangerous.Value = true
	
	dangerball.Enabled = true
	dangerball.Parent = missile
	
	
	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = vPlayer
	creator_tag.Name = "creator"
	creator_tag.Parent = missile
	
	missile.Parent = workspace.Balls
	tool:Destroy()
end

Helliox RNG

5 assetHo sviluppato il sistema RNG con modificatori di fortuna esponenziali, i sistemi di inventario ed equipaggiamento, la gestione delle statistiche e la persistenza dei dati. È stato il mio primo grande progetto di scripting, in cui ho imparato Lua con tutorial e pratica.
Pagina del gioco
RNG System Core
return {
	getRandomIndex = function(chances, luckModifier)
		print(luckModifier)
		local totalWeight = 0
		local weightedItems = {}

		-- Calculate weights with an exponential impact of the luck modifier
		for _, item in ipairs(chances) do
			-- Instead of dividing directly, use an exponential adjustment
			local adjustedChance = item.chance ^ (1 / luckModifier)
			local weight = 1 / adjustedChance -- Inverse of the adjusted chance
			table.insert(weightedItems, {item = item, weight = weight})
			totalWeight = totalWeight + weight
		end

		-- Generate a random number within the total weight
		local randomWeight = math.random() * totalWeight

		-- Select the item based on the random weight
		local cumulativeWeight = 0
		for _, weightedItem in ipairs(weightedItems) do
			cumulativeWeight = cumulativeWeight + weightedItem.weight
			if randomWeight <= cumulativeWeight then
				local item = weightedItem.item
				return {name = item.name, chance = item.chance, color = item.color, image = item.image, flavour = item.flavour}
			end
		end
	end
}
Weapon Chances System
local Weapons = game.ReplicatedStorage:WaitForChild("Weapons")

local function isValidated(weapon)

	local requiredChildren = {
		Chance = "IntValue",
		Equipped = "BoolValue",
		ImageID = "StringValue",
		WeaponColor = "Color3Value",
		WeaponDamage = "IntValue",
		WeaponFlavourName = "StringValue"
	}

	for childName, childType in pairs(requiredChildren) do
		local child = weapon:FindFirstChild(childName)
		if not child or not child:IsA(childType) then
			-- If the child is missing or not the correct type, return false
			return false
		end
	end
	return true
end

local weaponChances = {}
for _, weapon in pairs(Weapons:GetChildren()) do
	if isValidated(weapon) then
		table.insert(weaponChances, {
			name = weapon.Name,
			chance = weapon.Chance.Value,
			color = weapon.WeaponColor.Value,
			image = weapon.ImageID.Value,
			flavour = weapon.WeaponFlavourName.Value
		})
	end
end

table.sort(weaponChances, function(a, b)
	return a.chance < b.chance
end)

return weaponChances
Main RNG Controller
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local rngModules = ReplicatedStorage:WaitForChild("RNGModules")
local RemoteEvents = ReplicatedStorage:WaitForChild("Remotes")
local Weapons = ReplicatedStorage:WaitForChild("Weapons")
local chances = require(rngModules.Chances)
local selectChance = require(rngModules.Rng)
local PlayerDataHandler = require(game.ServerScriptService:WaitForChild("PlayerDataHandler"))

local function playerInventoryAdd(player, weapon)
	local rollScore = player.leaderstats.Rolls
	PlayerDataHandler:Update(player, "Rolls", function(currentRolls)
		return currentRolls + 1
	end)
	rollScore.Value = PlayerDataHandler:Get(player, "Rolls")
	
	print(weapon)
	local WeaponStats = Weapons:FindFirstChild(weapon.name)
	local newItem = {
		id = "" .. player.UserId .. "_" .. player.leaderstats.Rolls.Value,
		name = weapon.name,
		chance = weapon.chance,
		color = tostring(WeaponStats.WeaponColor.Value),
		thumbnail = WeaponStats.ImageID.Value,
		damage = WeaponStats.WeaponDamage.Value,
		flavourName = WeaponStats.WeaponFlavourName.Value,
		equipped = false,
		
	}

	PlayerDataHandler:AddToInventory(player, newItem)
end

RemoteEvents.RollDice.OnServerInvoke = (function(player, isInstant)
	local flavorRolls = isInstant and 1 or 10
	local luckModifier = player.PlayerStats.Luck.Value
	print(`Player's Luck: {luckModifier}`)
	local Rolls = {}
	for i = 1, flavorRolls do
		local rollLuckModifier = i < flavorRolls and luckModifier * 100 or luckModifier
		local roll = selectChance.getRandomIndex(chances, rollLuckModifier)
		table.insert(Rolls, roll)
	end
	
	playerInventoryAdd(player, Rolls[flavorRolls])

	RemoteEvents.RollDiceResult:FireClient(player, Rolls)
	return Rolls
end)
VideoIl peso della fortuna in azione
0:00 / 0:00
Un video del sistema di peso della fortuna: la statistica Fortuna del giocatore aumenta le probabilità di armi più rare, mantenendo l'equilibrio tra rarità basse e alte
VideoTutti i sistemi in azione
0:00 / 0:00
Un video con tutti i sistemi del gioco: RNG, inventario, equipaggiamento, statistiche ed estrazione

Altro

4 asset

Sistema di prompt UGC + dati

1 asset

Un sistema che fa guadagnare monete ai giocatori in modo passivo e permette di riscattare oggetti UGC quando ne hanno abbastanza

VideoPrompt UGC
0:00 / 0:00
Prompt UGC

Ruota del destino pesata

1 asset

Una ruota pesata ispirata a "Wheel of Fait"

VideoRuota del destino pesata
0:00 / 0:00
Le sezioni della ruota sono pesate e cambiano dimensione in base al peso, in modo dinamico. Non è un'immagine statica.

Sistema di dialogo semplice

2 asset

Un sistema di dialogo semplice per una commissione "Guide"

VideoIl sistema di dialogo in azione
0:00 / 0:00
Il sistema di dialogo in azione
  • Come funziona