hey everyone im trying to make simple script to learn lua and stuff like that
but i cant
i want to make console command like
giveweapon <name> <weapon>
i made script but its not that i want
autorun/server/sv_weapon.lua :
[CODE]util.AddNetworkString("Weapon")
net.Receive("Weapon", function(length, ply)
local TheWeapon = net.ReadString()
if TheWeapon == "weapon" then
ply:Give(WEAPON_NAME)
end
end)[/CODE]
autorun/client/cl_weapon.lua :
[CODE]function weapon()
net.Start("Weapon")
net.WriteString("weapon")
net.SendToServer()
end
concommand.Add("giveweapon", weapon)
[/CODE]
autorun/config.lua :
[CODE]WEAPON_NAME = "manhack_welder"[/CODE]
( sorry my english is bad )
The command 'give' is already implemented. I believe you use it 'give NameOfPlayer weapon_rpg'
[QUOTE=freshmintyy;47404874]The command 'give' is already implemented. I believe you use it 'give NameOfPlayer weapon_rpg'[/QUOTE]
i think i need v:Nick and LocalPlayer()
You don't need any client side scripts to make this happen
[B]autorun/server/sv_weapon.lua[/B]
[lua]local function cc_giveWeapon( pl, cmd, args ) local wep = args[1];
local pl = findPlayer( args[2] );
if ( pl:IsPlayer() ) then
pl:Give( wep );
end
end
concommand.Add( "giveweapon", cc_giveWeapon );
local function findPlayer( name )
for k, v in pairs( player.GetAll() ) do
if ( string.lower(v:Nick()) == string.lower(name) ) then
return v;
end
end
end[/lua]
[QUOTE=Annoyed Tree;47404909]You don't need any client side scripts to make this happen
[B]autorun/server/sv_weapon.lua[/B]
local function cc_giveWeapon( pl, cmd, args ) local wep = args[2]; local pl = findPlayer( args[2] ); if ( pl:IsPlayer() ) then pl:Give( wep ); endendconcommand.Ad( "giveweapon", cc_giveWeapon );local function findPlayer( name ) for k,v in pairs( player.GetAll() ) do if ( string.lower(v:Nick()) == string.lower(name) ) then return v; end endend[/QUOTE]
oh thanks but i got this eror
[CODE][ERROR] lua/autorun/server/sv_weapon.lua:2: attempt to call global 'findPlayer'
(a nil value)
1. unknown - lua/autorun/server/sv_weapon.lua:2
2. unknown - lua/includes/modules/concommand.lua:54
[/CODE]
[lua]local function findPlayer( name )
for k, v in pairs( player.GetAll() ) do
if ( string.find(string.lower(v:Nick()), string.lower(name)) ) then
return v;
end
end
return nil;
end
local function cc_giveWeapon( pl, cmd, args )
local wep = args[2];
local pl = findPlayer( args[1] );
if ( pl && pl:IsPlayer() ) then
pl:Give( wep );
pl:SelectWeapon( wep );
end
end
concommand.Add( "giveweapon", cc_giveWeapon );[/lua]
This should work
[QUOTE=Annoyed Tree;47404975][lua]local function findPlayer( name )
for k, v in pairs( player.GetAll() ) do
if ( string.find(string.lower(v:Nick()), string.lower(name)) ) then
return v;
end
end
return nil;
end
local function cc_giveWeapon( pl, cmd, args )
local wep = args[2];
local pl = findPlayer( args[1] );
if ( pl && pl:IsPlayer() ) then
pl:Give( wep );
pl:SelectWeapon( wep );
end
end
concommand.Add( "giveweapon", cc_giveWeapon );[/lua]
This should work[/QUOTE]
oh man thank you soo much !
Just for future reference, this'd probably be better suited to the [URL="http://facepunch.com/showthread.php?t=1411111"]Problems That Don't Need Their Own Thread[/URL] Thread
Sorry, you need to Log In to post a reply to this thread.