Hello! Im getting this error when running my script.
[IMG]http://gyazo.com/c3e768c35f4023a651367e2c03c67336.png?1355424871[/IMG]
When im running this code.
[CODE]for k, v in pairs(player.GetAll()) do
local n = v:GetName()
if string.find(string.lower(n),name) then
hit = v
name = n
break
end
end[/CODE]
I hope someone can help me out!
Cheers in advance!
What are you trying to do first of all it might help, and post the whole code not parts of it.
[QUOTE=NinjaS;38817261]What are you trying to do first of all it might help, and post the whole code not parts of it.[/QUOTE]
Alright :) Im trying to make a script for my bounty board from TPS so i tried to make it over to gmod13. I made a folder in modules like Hungermod is made. and made the functions in their, the bounty board is in showteamtabs. Here is the whole code.
[CODE]AddCSLuaFile(GM.FolderName.."/gamemode/modules/mercenary/cl_init.lua")
include(GM.FolderName.."/gamemode/modules/mercenary/sv_player.lua")
local TPS = { }
-- If this is false, you can't place more than one hit on one person
TPS_SH.AllowMultipleHits = false
-- If this is true, you can place hits on yourself
TPS_SH.CanPlaceHitOnSelf = false
-- Minumum amount you can place for a hit
TPS_SH.MinHitPrice = 1000
-- Maximum amount you can place for a hit
TPS_SH.MaxHitPrice = 10000
for k, v in pairs(player.GetAll()) do
local n = v:GetName()
if string.find(string.lower(n),name) then
hit = v
name = n
break
end
end
local MultiHit,SelfHit = TPS_SH.AllowMultipleHits,TPS_SH.CanPlaceHitOnSelf
function TPS.BountyHit(ply,cmd,args)
if ply:Team() == TEAM_MERC then GAMEMODE:Notify(ply, 1, 4, "You can't place hits a mercenary.") return end
local cost,name = args[2],args[1]
local hit
if !MultiHit and hit and hit.Bountied and table.HasValue(hit.Bountied.O,ply) then GAMEMOE:Notify(ply, 1, 4, "You can't place more than 1 hit on a player") return end
if !SelfHit and hit == ply then Notify(ply, 1, 4, "You can't place a hit on yourself") return end
cost = tonumber(cost)
if hit and hit:IsValid() then
if cost < TPS_SH.MinHitPrice or cost > TPS_SH.MaxHitPrice then ply:ChatPrint("Hit price must be above $" .. TPS_SH.MinHitPrice .. " and below $" .. TPS_SH.MaxHitPrice) return end
if ply:CanAfford(cost) then
hit:SetBountied(cost,ply)
GAMEMOE:Notify(ply, 1, 4, "You set a hit on " .. name .. " for $" .. cost)
else
GAMEMOE:Notify(ply, 1, 4, "You don't have $" .. cost .. " for that hit.")
end
end
end
concommand.Add("_bt",TPS.BountyHit)[/CODE]
[editline]13th December 2012[/editline]
Need more information? Or cant you guys help.
[editline]13th December 2012[/editline]
Since no one could help me with OP, maybe you can answer me on this error.
[CODE]if !SelfHit and hit == ply then GAMEMODE:Notify(ply, 1, 4, "You can't place a hit on yourself") return end[/CODE]
This is the error.
[ERROR] ...es/darkrp/gamemode/modules/mercenary/sv_mercenarymod.lua:34: attempt to call method 'Notify' (a nil value)
1. unknown - ...es/darkrp/gamemode/modules/mercenary/sv_mercenarymod.lua:34
2. unknown - lua/includes/modules/concommand.lua:69
Try this one
[lua]AddCSLuaFile(GM.FolderName.."/gamemode/modules/mercenary/cl_init.lua")
include(GM.FolderName.."/gamemode/modules/mercenary/sv_player.lua")
local TPS = { }
TPS_SH = {}
-- If this is false, you can't place more than one hit on one person
TPS_SH.AllowMultipleHits = false
-- If this is true, you can place hits on yourself
TPS_SH.CanPlaceHitOnSelf = false
-- Minumum amount you can place for a hit
TPS_SH.MinHitPrice = 1000
-- Maximum amount you can place for a hit
TPS_SH.MaxHitPrice = 10000
function FindPlayerName(name)
name = tostring(name)
for k,v in pairs( player.GetAll() ) do
if string.find( string.lower( v:Nick() ), string.lower( name ) ) then
return v
end
end
end
local MultiHit,SelfHit = TPS_SH.AllowMultipleHits,TPS_SH.CanPlaceHitOnSelf
local GM = GAMEMODE
function TPS.BountyHit(ply,cmd,args)
if ply:Team() == TEAM_MERC then ply:SendLua[[GAMEMODE:AddNotify("You can't place hits a mercenary.",NOTIFY_HINT, 5)]] return end
local name = FindPlayerName( args[1] ):Nick()
local cost = args[2]
name = tostring(name)
cost = tonumber(cost)
local hit = FindPlayerName( args[1] )
if !MultiHit and hit and hit.Bountied and table.HasValue(hit.Bountied.O,ply) then ply:SendLua[[GAMEMODE:AddNotify("You can't place more than 1 hit on a player",NOTIFY_HINT, 5)]] return end
if !SelfHit and hit == ply then ply:SendLua[[GAMEMODE:AddNotify("You can't place a hit on yourself",NOTIFY_HINT, 5)]] return end
if hit and hit:IsValid() then
if cost < TPS_SH.MinHitPrice or cost > TPS_SH.MaxHitPrice then ply:ChatPrint("Hit price must be above $" .. TPS_SH.MinHitPrice .. " and below $" .. TPS_SH.MaxHitPrice) return end
if ply:CanAfford(cost) then
hit:SetBountied(cost,ply)
ply:SendLua("GAMEMODE:AddNotify('You set a hit on " .. name .. " for $".. cost .."',NOTIFY_HINT, 5)")
else
ply:SendLua("GAMEMODE:AddNotify('You don\\'t have $" .. cost .. " for that hit.',NOTIFY_HINT, 5)")
end
end
end
concommand.Add("_bt",TPS.BountyHit)[/lua]
For real? Thats great, thought people was ignoring because they dident have time to do it. If you get more news please add
Steam: DJarthas
I haven't tested [lua]if !MultiHit and hit and hit.Bountied and table.HasValue(hit.Bountied.O,ply) then ply:SendLua[[GAMEMODE:AddNotify("You can't place more than 1 hit on a player",NOTIFY_HINT, 5)]] return end[/lua] Because I don't have the code.. so if it errors comment out that line I can remake it for you, but the rest should work fine. :smile:
[QUOTE=NinjaS;38819632]I haven't tested [lua]if !MultiHit and hit and hit.Bountied and table.HasValue(hit.Bountied.O,ply) then ply:SendLua[[GAMEMODE:AddNotify("You can't place more than 1 hit on a player",NOTIFY_HINT, 5)]] return end[/lua] Because I don't have the code.. so if it errors comment out that line I can remake it for you, but the rest should work fine. :smile:[/QUOTE]
Awesome! If it dosent work, can you please help me over Teamviewer or something. I will ofcourse pay you for the time you spend, so it dosent go to waste.
Edit: Having English test atm, and im done lol. But i will test when i come home I really thank you for your time!
Sincerly Djarthas
Got home and tested.
Error:
[ERROR] ...es/darkrp/gamemode/modules/mercenary/sv_mercenarymod.lua:45: attempt to call method 'SetBountied' (a nil value)
1. unknown - ...es/darkrp/gamemode/modules/mercenary/sv_mercenarymod.lua:45
2. unknown - lua/includes/modules/concommand.lua:69
Edit: My fault, i frogot my player meta in another file, now for the next problem i have. When the Merc kills a player with a bounty he receives the cost. I have the code for Receive function but its not working or saying and error, im not good at troubleshooting I can try and see if i can figure it out or maybe you will help? :) Im really gratefull.
[CODE]TPS_SH = { }
local TPS = { }
function TPS.PlayerDeathHit(ply,inf,killer)
local Check = ply.Bountied
if killer:IsValid() and killer:IsPlayer() and killer:Team() == TEAM_MERC and Check then
killer:AddMoney(Check.C)
local nam = ply:GetName()
local str = "Received $" .. Check.C .. " for completion on the hit of " .. nam
killer:ChatPrint(str)
GAMEMODE:Notify(killer, 4, 4, str)
GAMEMODE:NotifyAll(1, 6, "Hit on " .. nam .. " was completed.")
for k,v in pairs(Check.O) do
if v:IsValid() then
local str2 = "Your hit on " .. nam .. " has been finished."
v:ChatPrint(str2)
GAMEMOE:Notify(v, 4, 4, str2)
end
end
for k,v in pairs(team.GetPlayers(TEAM_MERC)) do
umsg.Start("SendHit",v)
umsg.Entity(ply)
umsg.Float(0)
umsg.End()
end
ply.Bountied = nil
end
end
hook.Add("PlayerDeath","Gives the bounty cash for a finished bounty.", TPS.PlayerDeathHit)
function TPS.ReceiveHit(um)
local p,c = um:ReadEntity(),um:ReadFloat()
local was,name = p.hit,p:GetName()
p.hit = c
chat.AddText(Color(255,0,0), "[BOUNTY] ", Color(255,255,255), (!was and "There is a hit on " .. name .. " for $" .. c .. ".") or "The hit on " .. name .. " was updated to $" .. c .. "!")
end
usermessage.Hook("SendHit", TPS.ReceiveHit)[/CODE]
This is the code for receive cost, and a signal who there is a hit on in my F4 menu.
Edit: My fault, In showteamtabs i have the codes for the tab in F4 but they pretty much work fine, if you want to see the codes for that then just ask :)
It should all work fine if you have it set up properly.
and change
[lua]ply.Bountied = nil[/lua]
to
[lua]ply.Bountied = ""[/lua]
[QUOTE=NinjaS;38826570]It should all work fine if you have it set up properly.
and change
[lua]ply.Bountied = nil[/lua]
to
[lua]ply.Bountied = ""[/lua][/QUOTE]
I dont think i have it set up correctly since its not reading TPS.PlayerDeathHit and TPS_ReceiveHit
[editline]14th December 2012[/editline]
Updated, I made the set up right. heres the new error.
[ERROR] ...es/darkrp/gamemode/modules/mercenary/sv_mercenarymod.lua:57: bad key to string index (number expected, got string)
1. error - [C]:-1
2. __index - lua/includes/extensions/string.lua:265
3. v - ...es/darkrp/gamemode/modules/mercenary/sv_mercenarymod.lua:57
4. unknown - lua/includes/modules/hook.lua:82
5. TakeDamage - [C]:-1
6. unknown - gamemodes/darkrp/entities/weapons/stunstick/shared.lua:152
Error line code
[CODE]function TPS.PlayerDeathHit(ply,inf,killer)
local Check = ply.Bountied
if killer:IsValid() and killer:IsPlayer() and killer:Team() == TEAM_MERC and Check then
killer:AddMoney(Check.C) --- THIS IS LINE 57
local nam = ply:GetName()
local str = "Received $" .. Check.C .. " for completion on the hit of " .. nam
killer:ChatPrint(str)
GAMEMODE:Notify(killer, 4, 4, str)
GAMEMODE:NotifyAll(1, 6, "Hit on " .. nam .. " was completed.")
for k,v in pairs(Check.O) do
if v:IsValid() then
local str2 = "Your hit on " .. nam .. " has been finished."
v:ChatPrint(str2)
GAMEMODE:Notify(v, 4, 4, str2)
end
end
for k,v in pairs(team.GetPlayers(TEAM_MERC)) do
umsg.Start("SendHit",v)
umsg.Entity(ply)
umsg.Float(0)
umsg.End()
end
ply.Bountied = ""
end
end
hook.Add("PlayerDeath","Gives the bounty cash for a finished bounty.", TPS.PlayerDeathHit)[/CODE]
use [ lua] tags [/ lua] plz
And you need to global it so you can get the value on death
You need to use ply.Bountied.C
[lua]
local Check = ply.Bountied.C
killer:AddMoney(Check)
[/lua]
Sorry, you need to Log In to post a reply to this thread.