Author Topic: Ulx shock function  (Read 5731 times)

0 Members and 1 Guest are viewing this topic.

Offline Masamune

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Ulx shock function
« on: April 22, 2012, 07:14:33 AM »
I recently decided to make a shock function for ulx for a server I'm admin on.
Features:
-Very similar to slap but damage defaults to the maximum health possible to have.
-You can specify damage, !shock bob alone will kill them instantly while !shock bob 50 will deal 50 damage.
-Ungods people so damage will work.
-When it kills a player it disintegrates them as if they had been shot by a combine ball.
-Default access is superadmin only but you can easily change that.
-Plays a sound at the point where the player got shocked.

Leave a comment with any suggestions you have, also if anyone can tell me how to get it to echo to chat that would be great, haven't managed to figure it out.
This is the first addon that I've ever shared with anyone else so go easy on me.
To install simply create a folder in addons and checkout this svn link:
http://masas-custom-ulx-lua-funcs.googlecode.com/svn/trunk/

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Ulx shock function
« Reply #1 on: April 22, 2012, 08:45:41 AM »
Nice idea there Masamune!

Suggestions -
Look into shaking affected player screen a second or two while sound is playing, then give them the view of themselves being disintegrated.
Sorry, not sure how to do this myself.

As for code review ... here are 2.
1) ULX (ULib commands actually) don't require "return true". They are presumed. Try without it.
2) Recent versions of ULX don't use the "ulx.addToMenu" command.
3) See http://ulyssesmod.net/docs/files/lua/ulib/shared/messages-lua.html#tsayError and perhaps use it instead of tsay for your death/exclusivity checking.
4) Fixing 1 and 2 may fix your echo to chat, IF all your other ulx commands echo fine.

If all of the commands you run aren't echoing, see your data/ulx/configs.txt file. There are some settings there for echo.
From my review, I can't see any other reason it wouldn't echo to chat other than the possibilities above.
« Last Edit: April 22, 2012, 08:53:27 AM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Ulx shock function
« Reply #2 on: April 23, 2012, 09:45:17 AM »
Ooh, this sounds interesting, I should fire up gmod and test it out when I'm not at work :D   (And I should then work on some XGUI while I'm at it  :-\ lol)

Look into shaking affected player screen a second or two while sound is playing, ...

Taken from ULib's slap code, looks like the ent:ViewPunch command might be what you're looking for:

Code: [Select]
function ULib.slap( ent, damage, power, nosound )
if ent:GetMoveType() == MOVETYPE_OBSERVER then return end -- Nothing we can do.

<... removed code for brevity ...>

local angle_punch_pitch = math.Rand( -20, 20 )
local angle_punch_yaw = math.sqrt( 20*20 - angle_punch_pitch * angle_punch_pitch )
if math.random( 0, 1 ) == 1 then
angle_punch_yaw = angle_punch_yaw * -1
end
ent:ViewPunch( Angle( angle_punch_pitch, angle_punch_yaw, 0 ) )

<...>
end
« Last Edit: April 23, 2012, 09:48:28 AM by Stickly Man! »
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Masamune

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Ulx shock function
« Reply #3 on: April 26, 2012, 02:31:28 PM »
I updated it with the changes that JamminR suggested, the screen shake worked but still isnt echoing at all. anyone got any ideas?