You can't do that, because Reciever is a string.
Instead, try using something like this:
[lua]
Players = player.GetAll()
for _,v in pairs(Players) do
if(string.find(v:Nick(), args[1])) then
Receiver = v
end
end
[/lua]
[QUOTE=PortalGod;24780988]You can't do that, because Reciever is a string.
Instead, try using something like this:
[lua]
Players = player.GetAll()
for _,v in pairs(Players) do
if(string.find(v:Nick(), args[1])) then
Receiver = v
end
end
[/lua][/QUOTE]
thanks, let's see if it works.
[editline]11:10AM[/editline]
now it gives me this:
[code]
Hook 'ChatCommand.ParseChat' Failed: [gamemodes\sandboxrp\gamemode\init.lua:179] attempt to index global 'Reciever' (a nil value)[/code]
for
[lua]function GiveMoney(ply,cmd,args)
if(!args[1]) then
ply:ChatPrint("Please specify a player.")
end
if(!args[2]) then
ply:ChatPrint("Please specify an amount.")
return
end
Players = player.GetAll()
for _,v in pairs(Players) do
if(string.find(v:Nick(), args[1])) then
Receiver = v
end
end
if(args[1] && args[2]) then
ply:TakeMoney(args[2])
ply:ChatPrint("You gave "..Reciever:Nick().." $"..args[2]..".")
Reciever:GiveMoney(args[2])
Reciever:ChatPrint("You recieved $"..args[2].." from "..ply:Nick()..".")
end
end[/lua]
[lua]
function GiveMoney(ply,cmd,args)
if(!args[1]) then
ply:ChatPrint("Please specify a player.")
end
if(!args[2]) then
ply:ChatPrint("Please specify an amount.")
return
end
local Reciever
Players = player.GetAll()
for _,v in pairs(Players) do
if(string.find(v:Nick(), args[1])) then
Receiver = v
end
end
if(Reciever && args[1] && args[2]) then
ply:TakeMoney(args[2])
ply:ChatPrint("You gave "..Reciever:Nick().." $"..args[2]..".")
Reciever:GiveMoney(args[2])
Reciever:ChatPrint("You recieved $"..args[2].." from "..ply:Nick()..".")
end
end
[/lua]
thanks ralle, it doesn't give me any errors, but it doesn't say anything in my chat either.
[editline]11:37AM[/editline]
I used an else statement on the if(receiver) and it gave me the else statement. By the way, I'm using the function on myself (/give sov 100)
[editline]11:40AM[/editline]
I think I found the problem, receiver != reciever
[editline]11:45AM[/editline]
still gives me the else
[lua]function GiveMoney(ply,cmd,args)
if(!args[1]) then
ply:ChatPrint("Please specify a player.")
end
if(!args[2]) then
ply:ChatPrint("Please specify an amount.")
return
end
local Reciever
Players = player.GetAll()
for _,v in pairs(Players) do
if(string.find(v:Nick(), args[1])) then
Reciever = v
end
end
if(Reciever && ply:GetMoney() >= args[2] && args[1] && args[2]) then
ply:TakeMoney(args[2])
ply:ChatPrint("You gave "..Reciever:Nick().." $"..args[2]..".")
Reciever:GiveMoney(args[2])
Reciever:ChatPrint("You recieved $"..args[2].." from "..ply:Nick()..".")
else
ply:ChatPrint("You don't have enough money")
end
end[/lua]
It's case sensitive. Might not be that though.
It said that ply:GetMoney is a string when I commented out the rest of it. I'll try tonumber(ply:GetMoney)
[editline]12:29PM[/editline]
now it gives me this:
[code]
Hook 'ChatCommand.ParseChat' Failed: [gamemodes\sandboxrp\gamemode\init.lua:23] attempt to index local 'Reciever' (a nil value)[/code]
for this:
[lua]function GiveMoney(ply,cmd,args)
if(!args[1]) then
ply:ChatPrint("Please specify a player.")
end
if(!args[2]) then
ply:ChatPrint("Please specify an amount.")
return
end
local Reciever
Players = player.GetAll()
for _,v in pairs(Players) do
if(string.find(v:Nick(), args[1])) then
Reciever = v
end
end
Money = tostring(ply:GetMoney())
if/*(Reciever &&*/ Money >= args[2] /*&& args[1] && args[2])*/ then
ply:TakeMoney(args[2])
ply:ChatPrint("You gave "..Reciever:Nick().." $"..args[2]..".")
Reciever:GiveMoney(args[2])
Reciever:ChatPrint("You recieved $"..args[2].." from "..ply:Nick()..".")
else
ply:ChatPrint("You don't have enough money")
end
end[/lua]
please help me, this is really bugging me and it still isn't fixed.
Sorry, you need to Log In to post a reply to this thread.