Hey guys, just need a little help. I want it so that when you hit a level so like level 16 you unlock a gun but it gives it to you in Pointshop 2. I have tried making it but it doesnt work.
The example on the point shop to site is this:
[CODE]
/*
* Gives a random item from the shop to a player
*/
function GiveRandomItem( ply )
local items = Pointshop2.GetRegisteredItems( )
local itemClass = table.Random( items )
return ply:PS2_EasyAddItem( itemClass.className )
end
GiveRandomItem( player.GetByID( 1 ) )
/*
* Gives a item with the specified name to the player
*/
function GiveItemByPrintName( ply, printName )
local itemClass = Pointshop2.GetItemClassByPrintName( printName )
if not itemClass then
error( "Invalid item " .. tostring( printName ) )
end
return ply:PS2_EasyAddItem( itemClass.className )
end
GiveItemByPrintName( player.GetByID( 1 ), "Gas Mask" )
[/CODE]
So i tried adding it into my leveling system but it does not seem to work. I have just duplicated the glock one on the bottom but added the pointshop 2 code.
[CODE]function LevelsSystem:AnnounceLevelUp(ply,num)
if ply:IsPrestige() and ply:GetLevel() == LevelsSystem.PrestigeMax then return end
local carryover = 0
if num > ply:XPNextLevel() then
carryover = num-ply:XPNextLevel()
end
ply:AddLevel(1)
ply:RemoveXP(ply:GetXP())
if ply:GetLevel()== 16 then
function GiveItemByPrintName( ply, G3SG1 )
local itemClass = Pointshop2.GetItemClassByPrintName( G3Sg1 )
if not itemClass then
error( "Invalid item " .. tostring( G3Sg1 ) )
end
return ply:PS2_EasyAddItem( weapon_tt_g3sg1 )
end
GiveItemByPrintName( player.GetByID( 1 ), "P228" )
ly:ChatPrint("G3SG1 UNLOCKED ")
else
end
if ply:GetLevel() == 3 then
ply:ChatPrint("Glock UNLOCKED ")
table.insert(ply.TotalPurchases, 1)
LevelsSystem:EquipWeapon(ply,"weapon_ttt_glock",1)
else
end[/CODE]
Thanks.
Does the code look right though?
[editline]28th March 2017[/editline]
[ERROR] addons/levelsystem/lua/autorun/server/levels_main.lua:181: attempt to index global 'ly' (a nil value)
1. AnnounceLevelUp - addons/levelsystem/lua/autorun/server/levels_main.lua:181
2. GiveUsersXP - addons/levelsystem/lua/autorun/server/levels_main.lua:151
3. fn - addons/levelsystem/lua/autorun/server/levels_main.lua:17
4. Call - addons/ulib/lua/ulib/shared/hook.lua:109
5. EndRound - gamemodes/terrortown/gamemode/init.lua:768
6. unknown - gamemodes/terrortown/gamemode/init.lua:320
did you read the error message?
Yeah i just realised that i missed a p for ply:ChatPrint
But now im getting this stupid error
[CODE][ERROR] addons/pointshop 2/lua/ps2/shared/sh_0_pointshop2.lua:32: bad argument #1 to 'lower' (string expected, got nil)
1. lower - [C]:-1
2. GetItemClassByPrintName - addons/pointshop 2/lua/ps2/shared/sh_0_pointshop2.lua:32
3. GiveItemByPrintName - addons/levelsystem/lua/autorun/server/levels_main.lua:174
4. AnnounceLevelUp - addons/levelsystem/lua/autorun/server/levels_main.lua:180
5. GiveUsersXP - addons/levelsystem/lua/autorun/server/levels_main.lua:151
6. fn - addons/levelsystem/lua/autorun/server/levels_main.lua:85
7. unknown - addons/ulib/lua/ulib/shared/hook.lua:109
8. FireBullets - [C]:-1
9. ShootBullet - gamemodes/terrortown/entities/weapons/weapon_tttbase.lua:316
10. PrimaryAttack - gamemodes/terrortown/entities/weapons/weapon_tttbase.lua:240
11. unknown - addons/damagelogs/lua/damagelogs/sv_damageinfos.lua:46[/CODE]
that's the same as the first one
Think i got it one sec missed a T on ttt
[editline]28th March 2017[/editline]
Attempted to create unknown entity type nil!
NULL Ent in GiveNamedItem!
[editline]28th March 2017[/editline]
Nvm still screwed
[url]https://en.wikipedia.org/wiki/Debugging[/url]
[quote]Debugging is the process of finding and resolving of defects that prevent correct operation of computer software or a system.[/quote]
Emphasis on [b]finding[/b]. Good luck.
Bro you have a real problem dude, dont be rude man. Show a little respect bro.
I don't see anybody else jumping in to help you with your trivial errors.
Jesus fucking Christ it's literally a capital letter that needs to be made lowercase, you can't have us do everything for you. And "show a little respect" is not something I'd say to the person trying to help you with your - 'a 5 year old could solve this' - problem
Also ninja'd :v:
You can help but making fun of someone is not the way to go who is new at lua. Also the capital letter hasnt fixed. Thanks anyway.
Make an attempt. I wasn't making fun of you, I was saying that you should at least try to solve it yourself before asking for help.
[editline]28th March 2017[/editline]
And learning to read and understand error messages is the most important skill you need to learn. If you get an error and you tried to read it but can't understand what it means, post it, say what you think it might be saying or why you don't understand it, and I will be very happy to help you - so will other people, I guarantee. But when you just post an error message without even reading it beforehand, that's a waste of everyone's time. Including yours.
[QUOTE=Mike Wazowski;52022300]You can help but making fun of someone is not the way to go who is new at lua. Also the capital letter hasnt fixed. Thanks anyway.[/QUOTE]
Can you post your current (after your fixes) code and error?
[CODE]
if ply:GetLevel()== 17 then
function GiveItemByPrintName( ply, G3SG1 )
local itemClass = Pointshop2.GetItemClassByPrintName( G3SG1 )
if not itemClass then
error( "Invalid item " .. tostring( G3SG1 ) )
end
return ply:PS2_EasyAddItem( itemClass.weapon_ttt_g3sg1 )
end
GiveItemByPrintName( player.GetByID( 1 ), "G3SG1" )
else
end
[/CODE]
[QUOTE=Mike Wazowski;52024084][CODE]
if ply:GetLevel()== 17 then
function GiveItemByPrintName( ply, G3SG1 )
local itemClass = Pointshop2.GetItemClassByPrintName( G3SG1 )
if not itemClass then
error( "Invalid item " .. tostring( G3SG1 ) )
end
return ply:PS2_EasyAddItem( itemClass.weapon_ttt_g3sg1 )
end
GiveItemByPrintName( player.GetByID( 1 ), "G3SG1" )
else
end
[/CODE][/QUOTE]
and what's the error?
Why are you creating a function and after defining it you call it, like you don't need to define it
Sorry, you need to Log In to post a reply to this thread.