Ulysses

General => Developers Corner => Topic started by: LuaTenshi on April 11, 2014, 11:55:21 AM

Title: DarkRP ULX Commands
Post by: LuaTenshi on April 11, 2014, 11:55:21 AM
As easy as copy and pasting...

Code: [Select]
-- local GAMEM = GAMEMODE.Name or GM.Name or "darkrp"
--if GAMEM ~= "darkrp" and GAMEM ~= "DarkRP" then return end -- DarkRP Only.

/*-------------------------------------------------------------------------------------------------------------------------
RP EndHit for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.rpEndHit( calling_ply, target_plys )
local affected_plys = {}

for  i=1, #target_plys do
local v = target_plys[ i ]
if( v and IsValid(v) and v:hasHit() ) then
v.finishHit()
table.insert(affected_plys, v)
end
end

if( #affected_plys <= 0 ) then
calling_ply:ChatPrint("Selected Player(s) does not have a hit.")
else
ulx.fancyLogAdmin( calling_ply, "#A ended hit for #T", affected_plys )
end
end
local rpEndHit = ulx.command( "Roleplay Utility", "ulx rpendhit", ulx.rpEndHit, "!endhit" )
rpEndHit:addParam{ type=ULib.cmds.PlayersArg }
rpEndHit:defaultAccess( ULib.ACCESS_SUPERADMIN )
rpEndHit:help( "End the hit of the target(s)." )

/*-------------------------------------------------------------------------------------------------------------------------
RP SetMoney for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
local startingcash = ( GM and GM.Config and GM.Config.startingmoney) or ( GAMEMODE and GAMEMODE.Config and GAMEMODE.Config.startingmoney ) or 500

function ulx.rpSetMoney( calling_ply, target_ply, amount )
local target = target_ply
local amount = math.floor(tonumber(amount)) or 0

DarkRP.storeMoney(target, amount)
target:setDarkRPVar("money", amount)
target:PrintMessage(2, DarkRP.getPhrase("x_set_your_money", "ULX", DarkRP.formatMoney(amount), ""))

ulx.fancyLogAdmin( calling_ply, "#A set money for #T to "..tostring(amount)..".", target_ply )
end
local rpSetMoney = ulx.command( "Roleplay Utility", "ulx rpsetmoney", ulx.rpSetMoney, "!setmoney" )
rpSetMoney:addParam{ type=ULib.cmds.PlayerArg }
rpSetMoney:addParam{ type=ULib.cmds.NumArg, min=0, default=startingcash, hint="amount", ULib.cmds.round, ULib.cmds.optional }
rpSetMoney:defaultAccess( ULib.ACCESS_SUPERADMIN )
rpSetMoney:help( "Set the money of the target." )


/*-------------------------------------------------------------------------------------------------------------------------
RP UnOwn for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.rpUnOwn( calling_ply, target_plys )
for  i=1, #target_plys do
local v = target_plys[ i ]
v:keysUnOwnAll()
end

ulx.fancyLogAdmin( calling_ply, "#A unowned the entities of #T", target_plys )
end
local rpUnOwn = ulx.command( "Roleplay Utility", "ulx rpunown", ulx.rpUnOwn, "!rpunown" )
rpUnOwn:addParam{ type=ULib.cmds.PlayersArg }
rpUnOwn:defaultAccess( ULib.ACCESS_SUPERADMIN )
rpUnOwn:help( "UnOwn the items of the target(s)." )

/*-------------------------------------------------------------------------------------------------------------------------
ULX RPName for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/

function ulx.rpname( calling_ply, target_ply, newname )
local target = target_ply
local name = tostring(newname)
------------
local oldname = target:Nick()
oldname = tostring(oldname)
------------
DarkRP.storeRPName(target, name)
target:setDarkRPVar("rpname", name)
target:PrintMessage(2, DarkRP.getPhrase("x_set_your_name", "ULX", name))

ulx.fancyLogAdmin( calling_ply, "#A set the name of #T(" .. oldname .. ") to " .. name .. ".", target_ply )
end
local rpName = ulx.command( "Roleplay Utility", "ulx rpname", ulx.rpname, "!rpname" )
rpName:addParam{ type=ULib.cmds.PlayerArg }
rpName:addParam{ type=ULib.cmds.StringArg, hint="John Doe", ULib.cmds.takeRestOfLine }
rpName:defaultAccess( ULib.ACCESS_ADMIN )
rpName:help( "Set a persons RP name." )


/*-------------------------------------------------------------------------------------------------------------------------
RP Veto for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.rpveto( calling_ply )
DarkRP.destroyLastVote()
ulx.fancyLogAdmin( calling_ply, "#A called veto on the last DarkRP vote.", target_plys )
end
local rpveto = ulx.command( "Roleplay Utility", "ulx rpveto", ulx.rpveto, "!rpveto" )
rpveto:defaultAccess( ULib.ACCESS_SUPERADMIN )
rpveto:help( "Stop the latest RP vote. (EXPERIMENTAL)" )

/*-------------------------------------------------------------------------------------------------------------------------
RP Arrest for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.rparrest( calling_ply, target_plys, override, should_unarrest )
if ( should_unarrest or string.len(tostring(override)) >= 1 ) then
for  i=1, #target_plys do
local v = target_plys[ i ]
v:unArrest( calling_ply )
end
else
for  i=1, #target_plys do
local v = target_plys[ i ]
v:arrest( _, calling_ply )
end
end

if ( should_unarrest or string.len(tostring(override)) >= 1 ) then
ulx.fancyLogAdmin( calling_ply, "#A unarrested #T", target_plys )
else
ulx.fancyLogAdmin( calling_ply, "#A arrested #T", target_plys )
end
end
local rparrest = ulx.command( "Roleplay Utility", "ulx rparrest", ulx.rparrest, "!arrest" )
rparrest:addParam{ type=ULib.cmds.PlayersArg }
rparrest:addParam{ type=ULib.cmds.StringArg, hint="Force Unarrest", ULib.cmds.optional }
rparrest:defaultAccess( ULib.ACCESS_SUPERADMIN )
rparrest:help( "Arrest a player(s)." )
rparrest:setOpposite( "ulx rpunarrest", {_, _, true}, "!unarrest" )

/*-------------------------------------------------------------------------------------------------------------------------
RP Lockdown for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.rplockdown( calling_ply, _, end_lockdown )
if tobool(GetConVarNumber("DarkRP_Lockdown")) then
RunConsoleCommand("rp_unlockdown")
ulx.fancyLogAdmin( calling_ply, "#A ended the lockdown.", target_plys )
else
RunConsoleCommand("rp_lockdown")
ulx.fancyLogAdmin( calling_ply, "#A started a lockdown.", target_plys )
end
end
local rplockdown = ulx.command( "Roleplay Utility", "ulx rplockdown", ulx.rplockdown, "!lockdown" )
rplockdown:defaultAccess( ULib.ACCESS_SUPERADMIN )
rplockdown:help( "Start a lockdown." )

Feel free to yell at me about how bad the code is, but I will revise it later.

I have updated the code above so there should be little to no errors, I have tested it on SP but I have not tested it on a server yet so please be patient.
Title: Re: DarkRP ULX Commands
Post by: MrPresident on April 11, 2014, 05:14:44 PM
Thanks for contributing LuaTenshi. I decided to move this thread to the Developers Corner for 2 reasons.

1. It's not structured as a release.
2. You claim it's untested. You wouldn't release code without testing it.

If you or someone else tests this and determines that it is error free and works as intended, I'll move the thread back into the releases section.
Title: Re: DarkRP ULX Commands
Post by: rainbowdash on May 01, 2014, 11:53:37 PM
I'm gonna go ahead and implement this on my in-dev server. If EndHit is what I think it is, this will certainly give me a boner over random hits.

EDIT

Code: [Select]
[ERROR] addons/ulx/lua/ulx/modules/sh/darkrp.lua:1: attempt to index global 'GAMEMODE' (a nil value)
  1. unknown - addons/ulx/lua/ulx/modules/sh/darkrp.lua:1
   2. include - [C]:-1
    3. unknown - addons/ulx/lua/ulx/cl_init.lua:17
     4. include - [C]:-1
      5. unknown - addons/ulx/lua/ulib/modules/ulx_init.lua:4
       6. include - [C]:-1
        7. unknown - addons/ulib/lua/ulib/cl_init.lua:23
         8. include - [C]:-1
          9. unknown - addons/ulib/lua/autorun/ulib_init.lua:5


There you go. Test failed.

Further issues...

Code: [Select]
[ERROR] addons/ulx/lua/ulx/modules/sh/darkrp.lua:61: attempt to index global 'rpname' (a nil value)
  1. unknown - addons/ulx/lua/ulx/modules/sh/darkrp.lua:61

Didn't define a command first.

Also you spelt warrent wrong. Its warrant.

Code: [Select]

[ERROR] gamemodes/darkrp/gamemode/libraries/fn.lua:54: Tried to use a NULL entity!
  1. unknown - [C]:-1
   2. f - gamemodes/darkrp/gamemode/libraries/fn.lua:54
    3. unknown - gamemodes/darkrp/gamemode/libraries/fn.lua:146
     4. isMayor - gamemodes/darkrp/gamemode/libraries/fn.lua:54
      5. unknown - addons/ulx/lua/ulx/modules/sh/darkrp.lua:169


This is the mayor code at L168-L175

I don't fully understand the purpose of this code, but with it, and its associating and following code removed, the command doesn't work. (Probably for a reason). But then again it doesn't drag the rest of its down.

Anyway, I'll leave that for you to think about.
Title: Re: DarkRP ULX Commands
Post by: LuaTenshi on June 13, 2014, 10:15:35 PM
Sorry for the necro but...
I have updated the code above, here is the new code again in case you missed it...

Code: [Select]
-- local GAMEM = GAMEMODE.Name or GM.Name or "darkrp"
--if GAMEM ~= "darkrp" and GAMEM ~= "DarkRP" then return end -- DarkRP Only.

/*-------------------------------------------------------------------------------------------------------------------------
RP EndHit for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.rpEndHit( calling_ply, target_plys )
local affected_plys = {}

for  i=1, #target_plys do
local v = target_plys[ i ]
if( v and IsValid(v) and v:hasHit() ) then
v.finishHit()
table.insert(affected_plys, v)
end
end

if( #affected_plys <= 0 ) then
calling_ply:ChatPrint("Selected Player(s) does not have a hit.")
else
ulx.fancyLogAdmin( calling_ply, "#A ended hit for #T", affected_plys )
end
end
local rpEndHit = ulx.command( "Roleplay Utility", "ulx rpendhit", ulx.rpEndHit, "!endhit" )
rpEndHit:addParam{ type=ULib.cmds.PlayersArg }
rpEndHit:defaultAccess( ULib.ACCESS_SUPERADMIN )
rpEndHit:help( "End the hit of the target(s)." )

/*-------------------------------------------------------------------------------------------------------------------------
RP SetMoney for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
local startingcash = ( GM and GM.Config and GM.Config.startingmoney) or ( GAMEMODE and GAMEMODE.Config and GAMEMODE.Config.startingmoney ) or 500

function ulx.rpSetMoney( calling_ply, target_ply, amount )
local target = target_ply
local amount = math.floor(tonumber(amount)) or 0

DarkRP.storeMoney(target, amount)
target:setDarkRPVar("money", amount)
target:PrintMessage(2, DarkRP.getPhrase("x_set_your_money", "ULX", DarkRP.formatMoney(amount), ""))

ulx.fancyLogAdmin( calling_ply, "#A set money for #T to "..tostring(amount)..".", target_ply )
end
local rpSetMoney = ulx.command( "Roleplay Utility", "ulx rpsetmoney", ulx.rpSetMoney, "!setmoney" )
rpSetMoney:addParam{ type=ULib.cmds.PlayerArg }
rpSetMoney:addParam{ type=ULib.cmds.NumArg, min=0, default=startingcash, hint="amount", ULib.cmds.round, ULib.cmds.optional }
rpSetMoney:defaultAccess( ULib.ACCESS_SUPERADMIN )
rpSetMoney:help( "Set the money of the target." )


/*-------------------------------------------------------------------------------------------------------------------------
RP UnOwn for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.rpUnOwn( calling_ply, target_plys )
for  i=1, #target_plys do
local v = target_plys[ i ]
v:keysUnOwnAll()
end

ulx.fancyLogAdmin( calling_ply, "#A unowned the entities of #T", target_plys )
end
local rpUnOwn = ulx.command( "Roleplay Utility", "ulx rpunown", ulx.rpUnOwn, "!rpunown" )
rpUnOwn:addParam{ type=ULib.cmds.PlayersArg }
rpUnOwn:defaultAccess( ULib.ACCESS_SUPERADMIN )
rpUnOwn:help( "UnOwn the items of the target(s)." )

/*-------------------------------------------------------------------------------------------------------------------------
ULX RPName for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/

function ulx.rpname( calling_ply, target_ply, newname )
local target = target_ply
local name = tostring(newname)
------------
local oldname = target:Nick()
oldname = tostring(oldname)
------------
DarkRP.storeRPName(target, name)
target:setDarkRPVar("rpname", name)
target:PrintMessage(2, DarkRP.getPhrase("x_set_your_name", "ULX", name))

ulx.fancyLogAdmin( calling_ply, "#A set the name of #T(" .. oldname .. ") to " .. name .. ".", target_ply )
end
local rpName = ulx.command( "Roleplay Utility", "ulx rpname", ulx.rpname, "!rpname" )
rpName:addParam{ type=ULib.cmds.PlayerArg }
rpName:addParam{ type=ULib.cmds.StringArg, hint="John Doe", ULib.cmds.takeRestOfLine }
rpName:defaultAccess( ULib.ACCESS_ADMIN )
rpName:help( "Set a persons RP name." )


/*-------------------------------------------------------------------------------------------------------------------------
RP Veto for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.rpveto( calling_ply )
DarkRP.destroyLastVote()
ulx.fancyLogAdmin( calling_ply, "#A called veto on the last DarkRP vote.", target_plys )
end
local rpveto = ulx.command( "Roleplay Utility", "ulx rpveto", ulx.rpveto, "!rpveto" )
rpveto:defaultAccess( ULib.ACCESS_SUPERADMIN )
rpveto:help( "Stop the latest RP vote. (EXPERIMENTAL)" )

/*-------------------------------------------------------------------------------------------------------------------------
RP Arrest for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.rparrest( calling_ply, target_plys, override, should_unarrest )
if ( should_unarrest or string.len(tostring(override)) >= 1 ) then
for  i=1, #target_plys do
local v = target_plys[ i ]
v:unArrest( calling_ply )
end
else
for  i=1, #target_plys do
local v = target_plys[ i ]
v:arrest( _, calling_ply )
end
end

if ( should_unarrest or string.len(tostring(override)) >= 1 ) then
ulx.fancyLogAdmin( calling_ply, "#A unarrested #T", target_plys )
else
ulx.fancyLogAdmin( calling_ply, "#A arrested #T", target_plys )
end
end
local rparrest = ulx.command( "Roleplay Utility", "ulx rparrest", ulx.rparrest, "!arrest" )
rparrest:addParam{ type=ULib.cmds.PlayersArg }
rparrest:addParam{ type=ULib.cmds.StringArg, hint="Force Unarrest", ULib.cmds.optional }
rparrest:defaultAccess( ULib.ACCESS_SUPERADMIN )
rparrest:help( "Arrest a player(s)." )
rparrest:setOpposite( "ulx rpunarrest", {_, _, true}, "!unarrest" )

/*-------------------------------------------------------------------------------------------------------------------------
RP Lockdown for ULX Git/ULib Git by LuaTenshi
-------------------------------------------------------------------------------------------------------------------------*/
function ulx.rplockdown( calling_ply, _, end_lockdown )
if tobool(GetConVarNumber("DarkRP_Lockdown")) then
RunConsoleCommand("rp_unlockdown")
ulx.fancyLogAdmin( calling_ply, "#A ended the lockdown.", target_plys )
else
RunConsoleCommand("rp_lockdown")
ulx.fancyLogAdmin( calling_ply, "#A started a lockdown.", target_plys )
end
end
local rplockdown = ulx.command( "Roleplay Utility", "ulx rplockdown", ulx.rplockdown, "!lockdown" )
rplockdown:defaultAccess( ULib.ACCESS_SUPERADMIN )
rplockdown:help( "Start a lockdown." )
I hope to see this on allot of servers soon.



If you are having any problems or if DarkRP made a major change please post here so that I can update the code accordingly.
Yes, I am still working on this, that is why its in the developers corner...
Title: Re: DarkRP ULX Commands
Post by: XRAYBlake on February 10, 2015, 02:16:31 PM
Sorry for bump, but has this been fixed, so it should work with no errors?
Title: Re: DarkRP ULX Commands
Post by: shmevan8or on February 20, 2016, 08:42:41 AM
Where would we put this? I'm new to this whole thing and I'm not sure.
Title: Re: DarkRP ULX Commands
Post by: XxLMM13xX on March 05, 2016, 05:37:10 AM
Sorry for bump, but has this been fixed, so it should work with no errors?

I believe I released some darkrp commands out in the release section that work for 1.6 and up