• Why won't this work
    33 replies, posted
Don't take this the wrong way, but have you tried solving the problem first before asking for help? Curiosity and having the tenacity to find an answer without others helping you is the only way you can work towards becoming a competent programmer that does not require the help of others to complete a task. The errors you have posted actually tell you what to do if you take a second to understand them, and work the problem out by looking at your code side by side. [code] Lua Error: [ERROR] addons/pointshop-master/lua/items/perks/upgrader.lua:62: attempt to index global 'UpgradeTable' (a nil value) 1. fn - addons/pointshop-master/lua/items/perks/upgrader.lua:62 2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 3. SelectWeapon - [C]:-1 4. DropNotifiedWeapon - gamemodes/terrortown/gamemode/weaponry.lua:224 5. unknown - gamemodes/terrortown/gamemode/weaponry.lua:248 6. unknown - lua/includes/modules/concommand.lua:69 [/code] Half of the information given to you in the stack call is useless, unless you are doing some insane looping for executing functions (just a theoretical explanation of why someone would need to use stack information greater than 2 levels deep). [code] Lua Error: [ERROR] addons/pointshop-master/lua/items/perks/upgrader.lua:62: attempt to index global 'UpgradeTable' (a nil value) [/code] Now this error tell you then, on line 62, you attempted to access a table, that at the time the code was executed, did not exist (hence the 'nil value'). On line 62, you have this segment of code: [code] if ( UpgradeTable[ _wToUpgrade ] ) then [/code] From the code you have posted, this should not cause a problem, but seen as there is, we might as well try something. Copy and paste the UpgradeTable to the begining of the file, and remove the old table. Seen as you will be accessing the table multiple times, it makes sense to not remake it and delete it every time you call the hook.
Current code, that was returning the earlier error [CODE]// // Recoded from the ground up to serve as a tutorial - NONFUNCTIONAL- Josh 'Acecool' Moser //Edited and fiddled with by Galactic ITEM.Name = 'Upgrader' ITEM.Price = 50000 ITEM.Model = 'models/props_c17/SuitCase_Passenger_Physics.mdl' ITEM.Bone = 'ValveBiped.Bip01_Spine2' Upgradetable ={ // Weapon to be upgraded = Upgraded weapon weapon_ttt_headcrab = "mirv"; weapon_radiation = "bio_gun"; weapon_ttt_c4 = "w_upc4"; goat_launcher = "up_goat_launcher"; weapon_ttt_adv_disguiser = "doppelbanger"; weapon_ttt_biggun = "up_biggun"; weapon_ttt_manhacknade = "weapon_ttt_goathacknade"; // Follow the pattern to add new upgrades. } function ITEM:OnEquip( ply, modifications ) ply:PS_AddClientsideModel( self.ID ); ply.Upgrader = true; // Follow the pattern to add new upgrades. end function ITEM:OnHolster( ply ) ply.CanChange = false; ply.Upgrader = false; ply:PS_RemoveClientsideModel( self.ID ); ply.__UpgradeTable = null end function ITEM:ModifyClientsideModel( ply, model, pos, ang ) model:SetModelScale( 0.9, 0 ); pos = pos + ( ang:Right( ) * 5 ) + ( ang:Up( ) * 6 ) + ( ang:Forward( ) * 2 ); return model, pos, ang; end // // Upgrade weapons when they switch to it. // hook.Add( "PlayerSwitchWeapon", "ItemUpgrader:PlayerSwitchWeapon", function( _p, _oldWeapon, _newWeapon ) -- _p:PrintMessage(HUD_PRINTTALK, "hook") if ( _newWeapon == NULL ) then return false; end -- _p:PrintMessage(HUD_PRINTTALK, "check weapon") if ( _p.CanChange ) and (_p.Upgrader) then -- _p:PrintMessage(HUD_PRINTTALK, "Can Change") local _wToUpgrade = string.lower( _newWeapon:GetClass( ) ); -- if ( ITEM.__UpgradeTable[ _wToUpgrade ] ) then if ( UpgradeTable[ _wToUpgrade ] ) then _p:PrintMessage(HUD_PRINTTALK, "Upgradable") if ( SERVER ) then _p:PrintMessage(HUD_PRINTTALK, "Serverside") // Server calls: Strip it, ensure it's removed, give them the upgrade _p:StripWeapon( _wToUpgrade ); SafeRemoveEntity( _newWeapon ); _p:Give( UpgradeTable[ _wToUpgrade ] ); end // Tell them about the upgrade, wait 1 frame Then select the new weapon. _p:PrintMessage( HUD_PRINTTALK, "Your old weapon has been upgraded into something good!" ); timer.Simple( 0, function( ) _p:SelectWeapon( UpgradeTable[ _wToUpgrade ] ); end ); // Only allow one upgrade? Comment out if you want to allow unlimited upgrades. -- _p.CanChange = false; // Prevent the switch to the new weapon we removed. return true; end end end ); // // Allow upgrades to occur only during an active round. // hook.Add( "TTTBeginRound", "Perks:TTTBeginRound", function( ) for k, _p in ipairs( player.GetAll( ) ) do _p.CanChange = true; end end ); // // Allow upgrades to occur only during an active round. // hook.Add( "TTTEndRound", "Perks:TTTEndRound", function( ) for k, _p in ipairs( player.GetAll( ) ) do _p.CanChange = false; end end );[/CODE]
I'll drop this here, and let you make the link: [code] Upgradetable ={ // Weapon to be upgraded = Upgraded weapon weapon_ttt_headcrab = "mirv"; weapon_radiation = "bio_gun"; weapon_ttt_c4 = "w_upc4"; goat_launcher = "up_goat_launcher"; weapon_ttt_adv_disguiser = "doppelbanger"; weapon_ttt_biggun = "up_biggun"; weapon_ttt_manhacknade = "weapon_ttt_goathacknade"; // Follow the pattern to add new upgrades. } [/code] [code] if ( UpgradeTable[ _wToUpgrade ] ) then [/code] Also nice to see how you took my advice into consideration, and tried solving problems for yourself. [/sarcasm]
[QUOTE=dingusnin;44271380]I'll drop this here, and let you make the link: [code] Upgradetable ={ // Weapon to be upgraded = Upgraded weapon weapon_ttt_headcrab = "mirv"; weapon_radiation = "bio_gun"; weapon_ttt_c4 = "w_upc4"; goat_launcher = "up_goat_launcher"; weapon_ttt_adv_disguiser = "doppelbanger"; weapon_ttt_biggun = "up_biggun"; weapon_ttt_manhacknade = "weapon_ttt_goathacknade"; // Follow the pattern to add new upgrades. } [/code] [code] if ( UpgradeTable[ _wToUpgrade ] ) then [/code] Also nice to see how you took my advice into consideration, and tried solving problems for yourself. [/sarcasm][/QUOTE] Ah, crap. [editline]17th March 2014[/editline] fixed it, new error is. [QUOTE]Lua Error: [ERROR] addons/pointshop-master/lua/sv_player_extension.lua:419: Tried to use a NULL entity! 1. SendLua - [C]:-1 2. PS_Notify - addons/pointshop-master/lua/sv_player_extension.lua:419 3. unknown - addons/pointshop-master/lua/sv_player_extension.lua:50[/QUOTE] [editline]17th March 2014[/editline] Aaaaaannnd now it works perfectly! Thanks so much everyone!!!
Sorry, you need to Log In to post a reply to this thread.