• Script Help
    10 replies, posted
[ERROR] addons/legendscript/lua/autorun/legendscript.lua:28: attempt to call method 'GiveAmmo' (a nil value) 1. unknown - addons/legendscript/lua/autorun/legendscript.lua:28 Timer Failed! [Simple][@addons/legendscript/lua/autorun/legendscript.lua (line 27)] Here is the code giving errors: [CODE]function GivingAmmo() timer.Simple( 10, GivingAmmo ) player.GetByID( 1 ):GiveAmmo( 200, "Pistol", false ) end GivingAmmo()[/CODE]
The GiveAmmo function is probably trying to be ran clientside, which it can't be, enclose it with [B]if ( SERVER ) then end[/B]
That is at the top of the file, is there something that could discontinue that from running on the rest of the file?
Well then it might have failed retrieving the player with the GetByID function, try to print the name via the same way you obtained the player to confirm.
It gives the correct Player ID. *Edit: After finding where the "if (SERVER) then" was ended before this, I moved that end to the end of this statement. However, it seems to no longer run this part of the script...
Not sure about the GiveAmmo, but your timer is invalid because it is inside the function . Either do [code]timer.Simple( 10, function() player.GetByID( 1 ):GiveAmmo( 200, "Pistol", false ) end )[/code] or [code]function GivingAmmo() player.GetByID( 1 ):GiveAmmo( 200, "Pistol", false ) end timer.Simple( 10, GivingAmmo )[/code] See if that fixes the GiveAmmo issue. If not, post the whole code.
Tried that and I'm still not getting anything from the script...It does not show errors anymore but only does adverts. Here is all of the code in the script: [CODE]-- Legend Script if SERVER then AddCSLuaFile() return end local adverts = { -- Edit or add messages below. {Color(255,0,0), "adverttest"}, {Color(0,0,255), "adverttest2"}, {Color(0,255,0), "adverttest3"}, } local index = 0 local function advertise() timer.Simple( 67, advertise ) -- Set the time between each message. chat.AddText( unpack( adverts[ index % #adverts + 1 ] ) ) index = index + 1; end advertise() //Get current weapon Ammo /*function GetAmmo(ply) local wep = ply:GetActiveWeapon currentAmmoCount = ply:GetAmmoCount( wep:GetPrimaryAmmoType() ) end*/ //Ammo Givers: if (SERVER) then function GivingAmmo() player.GetByID( 1 ):GiveAmmo( 200, "Pistol", false ) end timer.Simple( 10, GivingAmmo ) function headcrabRemoval() print("All Headcrabs have been removed by Legend Script.") end function test() print(player.GetByID( 1 )) end test() test() test() test() test() test() end[/CODE]
Just tested this in single-player and it works fine. [code]if (SERVER) then function GivingAmmo() player.GetByID( 1 ):GiveAmmo( 200, "Pistol", false ) print("gave ammo") end timer.Simple( 10, GivingAmmo ) end[/code] I put it in lua/autorun [editline]30th March 2014[/editline] If you're talking about the fact that the timer only calls once, you need to use timer.Create instead of timer.Simple.
That works by itself in a separate script. Thanks for everyone's help! I'll just keep all of these different functions away from each other from now on. Once again, thank you to everyone who replied! Yes I knew it would only run once. Thank you for your time and help!
I was just saying that it worked. You shouldn't really have a function per lua file.
[QUOTE=code_gs;44407278]I was just saying that it worked. You shouldn't really have a function per lua file.[/QUOTE] Indeed. It's just that the upper half of this file is clientside while the portion in question is shared. I'll keep different files for each of the sides. I understand that one per file could be.....overboard :yarr:
Sorry, you need to Log In to post a reply to this thread.