|
| 1 | +-- Vote to civilize using ULX vote system |
| 2 | +local PUNISHMENT = "timedcivilize" |
| 3 | +local CATEGORY = "Fun" |
| 4 | +local PERMANENT_EXPIRATION = -1 |
| 5 | + |
| 6 | +if SERVER then |
| 7 | + local function voteCivilizeDone( t, targetNick, targetSteamID, minutes, callingPly ) |
| 8 | + local voteYesCount = t.results[1] or 0 |
| 9 | + local shouldCivilize = voteYesCount > 0 |
| 10 | + |
| 11 | + if not shouldCivilize then |
| 12 | + ulx.fancyLogAdmin( callingPly, "#A's vote to civilize #s did not pass", targetNick ) |
| 13 | + return |
| 14 | + end |
| 15 | + |
| 16 | + -- Check if player is still on server |
| 17 | + local targetPly = player.GetBySteamID64( targetSteamID ) |
| 18 | + local targetStillOnServer = IsValid( targetPly ) |
| 19 | + if not targetStillOnServer then |
| 20 | + ulx.fancyLogAdmin( callingPly, "#A's vote to civilize #s passed, but the player has left", targetNick ) |
| 21 | + return |
| 22 | + end |
| 23 | + |
| 24 | + -- Get calling player's steam ID (or console if they disconnected) |
| 25 | + local callerStillOnServer = IsValid( callingPly ) |
| 26 | + local issuerSteamID = callerStillOnServer and callingPly:SteamID64() or "Console" |
| 27 | + |
| 28 | + -- Calculate expiration time |
| 29 | + local isPermanent = minutes == 0 |
| 30 | + local expirationTime = isPermanent and PERMANENT_EXPIRATION or os.time() + ( minutes * 60 ) |
| 31 | + |
| 32 | + -- Apply the punishment |
| 33 | + TimedPunishments.Punish( targetSteamID, PUNISHMENT, expirationTime, issuerSteamID, "Voted civilized by players" ) |
| 34 | + |
| 35 | + -- Log the result |
| 36 | + local durationStr = isPermanent and "permanently" or ULib.secondsToStringTime( minutes * 60 ) |
| 37 | + ulx.fancyLogAdmin( callingPly, "#A's vote to civilize #s for #s passed", targetNick, durationStr ) |
| 38 | + end |
| 39 | + |
| 40 | + function ulx.votetimedcivilize( callingPly, targetPly, minutes ) |
| 41 | + -- Check if another vote is already in progress |
| 42 | + local anotherVoteInProgress = ulx.voteInProgress |
| 43 | + if anotherVoteInProgress then |
| 44 | + ULib.tsayError( callingPly, "There is already a vote in progress. Please wait for the current one to end.", true ) |
| 45 | + return |
| 46 | + end |
| 47 | + |
| 48 | + -- Format the duration for display |
| 49 | + local isPermanent = minutes == 0 |
| 50 | + local durationStr = isPermanent and "permanently" or ULib.secondsToStringTime( minutes * 60 ) |
| 51 | + |
| 52 | + -- Build the vote title |
| 53 | + local targetName = targetPly:Nick() |
| 54 | + local voteTitle = "Civilize " .. targetName .. " for " .. durationStr .. "?" |
| 55 | + |
| 56 | + -- Start the vote |
| 57 | + local targetSteamID = targetPly:SteamID64() |
| 58 | + ulx.doVote( voteTitle, { "Yes", "No" }, voteCivilizeDone, _, _, _, targetName, targetSteamID, minutes, callingPly ) |
| 59 | + |
| 60 | + -- Log the vote initiation |
| 61 | + ulx.fancyLogAdmin( callingPly, "#A started a vote to civilize #T for #s", targetPly, durationStr ) |
| 62 | + end |
| 63 | +end |
| 64 | + |
| 65 | +-- Create the ULX command |
| 66 | +local voteCmd = ulx.command( CATEGORY, "ulx votetimedcivilize", ulx.votetimedcivilize, "!votetimedcivilize" ) |
| 67 | + |
| 68 | +-- Add parameters |
| 69 | +voteCmd:addParam{ type = ULib.cmds.PlayerArg } |
| 70 | +voteCmd:addParam{ type = ULib.cmds.NumArg, hint = "minutes, 0 for perma", ULib.cmds.allowTimeString, ULib.cmds.optional, min = 0, default = 15 } |
| 71 | + |
| 72 | +-- Configure access and help |
| 73 | +voteCmd:defaultAccess( ULib.ACCESS_ADMIN ) |
| 74 | +voteCmd:help( "Start a public vote to civilize a player" ) |
0 commit comments