ULX

Author Topic: Teleportating gun  (Read 2980 times)

0 Members and 3 Guests are viewing this topic.

Offline Digital Spit

  • Jr. Member
  • **
  • Posts: 79
  • Karma: 1
Teleportating gun
« on: February 27, 2012, 11:25:56 AM »
So I had this thought just randomly but, would it be possible to script a SWEP but have it include ULX/ULib? Just thinkin'

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Teleportating gun
« Reply #1 on: February 27, 2012, 02:08:11 PM »
Absolutely.
You'd just need to program the SWEP to do various functions.
Megiddo even tinkered with a 'targetting site' Radial Menu many years ago.
I see no reason it couldn't be tied into a SWEP with more advanced features/better GUI, etc.

BTW, that Radial menu is 3+ years old, though I've not tested, it's doubtful it still works.
Just using it as an example that could be tied to a SWEP with Right/left clicks and other features.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline kropp

  • Newbie
  • *
  • Posts: 16
  • Karma: 0
Re: Teleportating gun
« Reply #2 on: February 27, 2012, 06:09:02 PM »
I might be able to make this. Give me some time since I'm new to coding.

I got this so far,
Help fix this up if you can lol
Code: [Select]
if SERVER then
AddCSLuaFile("shared.lua")
end

if CLIENT then
SWEP.PrintName = "Teleport"
SWEP.Slot = 0
SWEP.SlotPos = 3
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
end

SWEP.Base = "weapon_cs_base2"

SWEP.Author = "Kropp"
SWEP.Instructions = "Left Click to Teleport"
SWEP.Contact = "james-kropp@hotmail.com"
SWEP.Purpose = "Teleport"
SWEP.IconLetter = "w"

SWEP.ViewModelFOV = 62
SWEP.ViewModelFlip = false
SWEP.AnimPrefix = "stunstick"

SWEP.Spawnable = false
SWEP.AdminSpawnable = true

SWEP.NextStrike = 0

SWEP.ViewModel = Model("models/weapons/v_stunbaton.mdl")
SWEP.WorldModel = Model("models/weapons/w_stunbaton.mdl")

SWEP.Sound = Sound("weapons/stunstick/stunstick_swing1.wav")

SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = ""

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = 0
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = ""

function SWEP:Deploy()

function SWEP:Initialize()
self:SetWeaponHoldType("normal")

self.Hit = {
Sound("weapons/stunstick/stunstick_impact1.wav"),
Sound("weapons/stunstick/stunstick_impact2.wav")
}

self.FleshHit = {
Sound("weapons/stunstick/stunstick_fleshhit1.wav"),
Sound("weapons/stunstick/stunstick_fleshhit2.wav")
}
end

function SWEP:PrimaryAttack()
if CurTime() < self.NextStrike then return end

self:SetWeaponHoldType("melee")
timer.Simple(0.3, function(wep) if wep:IsValid() then wep:SetWeaponHoldType("normal") end end, self)

self.Owner:SetAnimation(PLAYER_ATTACK1)
self.Weapon:EmitSound(self.Sound)
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)

self.NextStrike = CurTime() + .3

if CLIENT then return end

local trace = self.Owner:GetEyeTrace();
       
    local Gear = self.Owner:GetTable().CurGear or 1;

function("Teleport", "Teleports you to a targeted location.", true,
function ( Player, Trace )
local EndPos = Player:GetEyeTrace().HitPos;
local CloserToUs = (Player:GetPos() - EndPos):Angle():Forward();

Player:SetPos(EndPos + (CloserToUs * 20));
Player:PrintMessage(HUD_PRINTTALK, "Teleported.");
end

function SWEP:SecondaryAttack()
if CurTime() < self.NextStrike then return end

self.Owner:SetAnimation(PLAYER_ATTACK1)
self.Weapon:EmitSound(self.Sound)
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)

self.NextStrike = CurTime() + .3

self:SetWeaponHoldType("melee")
timer.Simple(0.3, function(wep) if wep:IsValid() then wep:SetWeaponHoldType("normal") end end, self)

if CLIENT then return end

("Kill Player", "Aim at a player to slay him.", false,
function ( Player, Trace )
if IsValid(Trace.Entity) and Trace.Entity:IsPlayer() then
Trace.Entity:Kill();
Player:PrintMessage(HUD_PRINTTALK, "Player killed.");
end
end
);


function SWEP:Reload()
self:SetWeaponHoldType("melee")
timer.Destroy("rp_stunstick_threaten")
timer.Create("rp_stunstick_threaten", 1, 1, function() self:SetWeaponHoldType("normal") end)

if not SERVER then return end

if self.LastReload and self.LastReload > CurTime() - 0.1 then self.LastReload = CurTime() return end
self.LastReload = CurTime()
self.Owner:EmitSound("weapons/stunstick/spark"..math.random(1,3)..".wav")
end

if CLIENT then
local function StunStickFlash()
local alpha = 255
hook.Add("HUDPaint", "Teleport Stick", function()
alpha = Lerp(0.05, alpha, 0)
surface.SetDrawColor(255,255,255,alpha)
surface.DrawRect(0,0,ScrW(), ScrH())

if math.Round(alpha) == 0 then
hook.Remove("HUDPaint", "Teleport Stick")
end
end)
end
usermessage.Hook("StunStickFlash", StunStickFlash)
end
« Last Edit: February 27, 2012, 06:28:37 PM by kropp »

Offline Digital Spit

  • Jr. Member
  • **
  • Posts: 79
  • Karma: 1
Re: Teleportating gun
« Reply #3 on: February 29, 2012, 11:34:19 AM »
I might be able to make this. Give me some time since I'm new to coding.

I got this so far,
Help fix this up if you can lol
Code: [Select]
if SERVER then
AddCSLuaFile("shared.lua")
end

if CLIENT then
SWEP.PrintName = "Teleport"
SWEP.Slot = 0
SWEP.SlotPos = 3
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
end

SWEP.Base = "weapon_cs_base2"

SWEP.Author = "Kropp"
SWEP.Instructions = "Left Click to Teleport"
SWEP.Contact = "james-kropp@hotmail.com"
SWEP.Purpose = "Teleport"
SWEP.IconLetter = "w"

SWEP.ViewModelFOV = 62
SWEP.ViewModelFlip = false
SWEP.AnimPrefix = "stunstick"

SWEP.Spawnable = false
SWEP.AdminSpawnable = true

SWEP.NextStrike = 0

SWEP.ViewModel = Model("models/weapons/v_stunbaton.mdl")
SWEP.WorldModel = Model("models/weapons/w_stunbaton.mdl")

SWEP.Sound = Sound("weapons/stunstick/stunstick_swing1.wav")

SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = ""

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = 0
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = ""

function SWEP:Deploy()

function SWEP:Initialize()
self:SetWeaponHoldType("normal")

self.Hit = {
Sound("weapons/stunstick/stunstick_impact1.wav"),
Sound("weapons/stunstick/stunstick_impact2.wav")
}

self.FleshHit = {
Sound("weapons/stunstick/stunstick_fleshhit1.wav"),
Sound("weapons/stunstick/stunstick_fleshhit2.wav")
}
end

function SWEP:PrimaryAttack()
if CurTime() < self.NextStrike then return end

self:SetWeaponHoldType("melee")
timer.Simple(0.3, function(wep) if wep:IsValid() then wep:SetWeaponHoldType("normal") end end, self)

self.Owner:SetAnimation(PLAYER_ATTACK1)
self.Weapon:EmitSound(self.Sound)
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)

self.NextStrike = CurTime() + .3

if CLIENT then return end

local trace = self.Owner:GetEyeTrace();
       
    local Gear = self.Owner:GetTable().CurGear or 1;

function("Teleport", "Teleports you to a targeted location.", true,
function ( Player, Trace )
local EndPos = Player:GetEyeTrace().HitPos;
local CloserToUs = (Player:GetPos() - EndPos):Angle():Forward();

Player:SetPos(EndPos + (CloserToUs * 20));
Player:PrintMessage(HUD_PRINTTALK, "Teleported.");
end

function SWEP:SecondaryAttack()
if CurTime() < self.NextStrike then return end

self.Owner:SetAnimation(PLAYER_ATTACK1)
self.Weapon:EmitSound(self.Sound)
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)

self.NextStrike = CurTime() + .3

self:SetWeaponHoldType("melee")
timer.Simple(0.3, function(wep) if wep:IsValid() then wep:SetWeaponHoldType("normal") end end, self)

if CLIENT then return end

("Kill Player", "Aim at a player to slay him.", false,
function ( Player, Trace )
if IsValid(Trace.Entity) and Trace.Entity:IsPlayer() then
Trace.Entity:Kill();
Player:PrintMessage(HUD_PRINTTALK, "Player killed.");
end
end
);


function SWEP:Reload()
self:SetWeaponHoldType("melee")
timer.Destroy("rp_stunstick_threaten")
timer.Create("rp_stunstick_threaten", 1, 1, function() self:SetWeaponHoldType("normal") end)

if not SERVER then return end

if self.LastReload and self.LastReload > CurTime() - 0.1 then self.LastReload = CurTime() return end
self.LastReload = CurTime()
self.Owner:EmitSound("weapons/stunstick/spark"..math.random(1,3)..".wav")
end

if CLIENT then
local function StunStickFlash()
local alpha = 255
hook.Add("HUDPaint", "Teleport Stick", function()
alpha = Lerp(0.05, alpha, 0)
surface.SetDrawColor(255,255,255,alpha)
surface.DrawRect(0,0,ScrW(), ScrH())

if math.Round(alpha) == 0 then
hook.Remove("HUDPaint", "Teleport Stick")
end
end)
end
usermessage.Hook("StunStickFlash", StunStickFlash)
end


I'm going to test this out and see if it works o.O

Offline kropp

  • Newbie
  • *
  • Posts: 16
  • Karma: 0
Re: Teleportating gun
« Reply #4 on: February 29, 2012, 04:17:47 PM »
This does not work. Its a rough draft need some one to fix it up.

Offline Digital Spit

  • Jr. Member
  • **
  • Posts: 79
  • Karma: 1
Re: Teleportating gun
« Reply #5 on: February 29, 2012, 05:04:00 PM »
How long have you been learning lua for?

Offline kropp

  • Newbie
  • *
  • Posts: 16
  • Karma: 0
Re: Teleportating gun
« Reply #6 on: February 29, 2012, 09:55:58 PM »
Just started thats why it does not work yet. Need some help