Random Weapon Drop!

i have working on a random weapon drop to my server and my gamemode so far i have this

function GM:PlayerDeath( Victim, Weapon, Killer )

local RamdomNumber = math.random(1,3)
local SpawmHight = 128
local Pos = victim:GetPos()

if RandomNumber == 1 then
local Drop = ents.Create(“item_healthkit”)
Drop:SetPos(Pos+Vector(0,0,SpawnHight))
Drop:Spawn()
Drop:Activate()

elseif RandomNumber == 2 then
local Drop = ents.Create(“item_ammo_pistol”)
Drop:SetPos(Pos+Vector(0,0,SpawnHight))
Drop:Spawn()
Drop:Activate()

elseif RandomNumber == 3 then
local Drop = ents.Create(“item_ammo_smg1”)
Drop:SetPos(Pos+Vector(0,0,SpawnHight))
Drop:Spawn()
Drop:Activate()
end
end

thats the code i dont know if its right or something but i got 2 codes and 1 of them maes the gamemode cracking
Secound Code

function FirstSpawn( ply )
ply:ChatPrint("----------------------------------------------")
ply:ChatPrint(“Welcome to the Server!”)
ply:ChatPrint("----------------------------------------------")
end
hook.Add( “FirstSpawn”, “FirstSpawn”, FirstSpawn )

is there any errors in them or does any1 have tryd to make this before?

need help pls


hook.Add( "PlayerInitialSpawn", "WelcomeMsg", function(ply)
ply:ChatPrint("----------------------------------------------")
ply:ChatPrint("Welcome to the Server!")
ply:ChatPrint("----------------------------------------------")
end )


What… the… shit…

[lua]hook.Add(“PlayerInitialSpawn”, “Welome”, function(ply)
ply:ChatPrint("----------------------------------------------")
ply:ChatPrint(“Welcome to the Server!”)
ply:ChatPrint("----------------------------------------------")
end)[/lua]

Thanks ALOT allmost finnish now

[editline]03:34PM[/editline]

but

hook.Add( “OnEntityCreated”, “WelcomeMsg”, function(ent)
if ent!=LocalPlayer() then return nil end
hook.Remove(“OnEntityCreated”, “WelcomeMsg”)
ply:ChatPrint("----------------------------------------------")
ply:ChatPrint(“Welcome to the Server!”)
ply:ChatPrint("----------------------------------------------")
end )

that dosent work!

this does :smiley:

hook.Add( “PlayerInitialSpawn”, “WelcomeMsg”, function(ply)
ply:ChatPrint("----------------------------------------------")
ply:ChatPrint(“Welcome to the Server!”)
ply:ChatPrint("----------------------------------------------")
end )

Exactly that, I was first like oh clientside but then noticed he wanted it serverside for some reason. The text is not dynamic and ChatPrint is shared so why not :slight_smile:

EDIT:

Not tested but here it goes:
[LUA]hook.Add( “PlayerDeath”, “RandWepDrop”, function( victim, weapon, killer )
local DropEnt=ents.Create(table.Random(
{
“item_healthkit”,
“item_ammo_pistol”,
“item_ammo_smg1”
}))
if not DropEnt or not DropEnt:IsValid() then return end
DropEnt:SetPos(victim:GetPos()+Vector(0,0,128))
DropEnt:Spawn()
DropEnt:Activate()
end )
[/LUA]
You could use traces and such to check if it can actually be spawned but I’m not in a mood of doing that.

It works fine but a littel hard when i have a bug on my server