• Changing the Crowbar in Deathrun Pointshow
    22 replies, posted
I know there are many threads about this but there none for the Deathrun gamemode. Most of them are for TTT. Here the code I'm working with: [code] ITEM.Name = 'Diamond Sword' // change this to whatever name you want ITEM.Price = 100000 // change this to whatever price you want ITEM.Model = 'models/weapons/w_diamond_mc_sword.mdl' // change this to what shop 'icon' you want ITEM.WeaponClass = 'mc_sword_diamond' //change this to name for item you want to replace the crowbar with ITEM.SingleUse = false // makes it persist every time. This does sometimes bug out, a good suggestion would be to add more weapons before this weapon that work similar, may give a workaround to your issue. function ITEM:OnEquip(ply) if not ply:Alive() then return end ply:StripWeapon('weapon_crowbar') ply:Give(self.WeaponClass) ply:SelectWeapon(self.WeaponClass) end function ITEM:OnHolster(ply) if not ply:Alive() then return end ply:StripWeapon(self.WeaponClass) ply:Give('weapon_crowbar') ply:SelectWeapon('weapon_crowbar') end function ITEM:PlayerSpawn(ply) ply:StripWeapon('weapon_crowbar') ply:Give(self.WeaponClass) ply:SelectWeapon(self.WeaponClass) end [/code] The problem I am having is that it doesn't remove the Crowbar on spawn, it because the round starts in "Preparing" and the Crowbar gets given to the player on the round "Active", and the Diamond sword gets given straight away.
Add/create a hook for when it changes to round active that checks if the item is owned. If so, do the same thing you're doing on PlayerSpawn.
What will the hook look like?
[code]hook.Add( "hook_here", "NewCrowbar", function() --Assuming clientside... if ( LocalPlayer():PS_HasItem( "diamondsword" ) ) then ply:StripWeapon( "diamondsword" ) ply:Give( "diamondsword" ) ply:SelectWeapon( "diamondsword" ) end end)[/code]
[code]function ITEM:OnEquip(ply) if not ply:Alive() then return end ply:StripWeapon('weapon_crowbar') ply:Give(self.WeaponClass) ply:SelectWeapon(self.WeaponClass) hook.Add( "hook_here", "NewCrowbar", function() if ( LocalPlayer():PS_HasItem( "diamondsword" ) ) then ply:StripWeapon( "weapon_crowbar" ) ply:Give( self.WeaponClass ) ply:SelectWeapon( self.WeaponClass ) end end) end [/code] Like this? No clue what to rename hook_here to :S
No. Add the hook code into a new file in lua/autorun/client. Also, change the hook to whatever hook the Deathrun gamemode uses when the round changes from preparing to active.
I named the hook to "OnRoundSet" but it doesn't work still [code] hook.Add( "OnRoundSet", "NewCrowbar", function() if ( LocalPlayer():PS_HasItem( "Diamond Sword" ) ) then ply:StripWeapon( "weapon_crowbar" ) ply:Give( "mc_sword_diamond" ) ply:SelectWeapon( "mc_sword_diamond" ) end end) [/code]
Lucky for you, googling the hook returned the parameters needed. [code]hook.Add( "OnRoundSet", "NewCrowbar", function( round ) if ( LocalPlayer():PS_HasItem( "Diamond Sword" ) and round == ROUND_ACTIVE ) then timer.Simple( 1, function() ply:StripWeapon( "weapon_crowbar" ) ply:Give( "mc_sword_diamond" ) ply:SelectWeapon( "mc_sword_diamond" ) end) end end)[/code]
It still gives me the crowbar and the Diamond sword Are you sure it for the client side?
Give() is a server-side function. Along with StripWeapon(), you'll need to put the file in lua/autorun/server and do a for loop of the players and then do your if statements.
Getting errors soon as I put the file into autorun/server [code][ERROR] lua/autorun/server/hook_pointshop.lua:2: attempt to call global 'LocalPlayer' (a nil value) 1. fn - lua/autorun/server/hook_pointshop.lua:2 2. Call - addons/ulib/lua/ulib/shared/hook.lua:183 3. SetRound - gamemodes/deathrun/gamemode/sv_round.lua:144 4. unknown - gamemodes/deathrun/gamemode/sv_round.lua:180 5. RoundThink - gamemodes/deathrun/gamemode/sv_round.lua:236 6. unknown - gamemodes/deathrun/gamemode/init.lua:616 [/code]
[code]-- Serverside hook.Add( "OnRoundSet", "NewCrowbar", function( round ) for _, ply in pairs( player.GetAll() ) do if ( ply:PS_HasItem( "Diamond Sword" ) and round == ROUND_ACTIVE ) then timer.Simple( 1, function() ply:StripWeapon( "weapon_crowbar" ) ply:Give( "mc_sword_diamond" ) ply:SelectWeapon( "mc_sword_diamond" ) end) end end end)[/code]
[code] [ERROR] lua/autorun/server/hook_pointshop.lua:2: attempt to index global 'ply' (a nil value) 1. fn - lua/autorun/server/hook_pointshop.lua:2 2. Call - addons/ulib/lua/ulib/shared/hook.lua:183 3. SetRound - gamemodes/deathrun/gamemode/sv_round.lua:144 4. unknown - gamemodes/deathrun/gamemode/sv_round.lua:180 5. RoundThink - gamemodes/deathrun/gamemode/sv_round.lua:236 6. unknown - gamemodes/deathrun/gamemode/init.lua:616 [/code] Error :P
Gee thanks for the help. What's line two.
You obviously didn't copy the correct code then, because ply is defined in the for loop...
Got it working, thanks
Sorry, but an bug just appeared, and it has something to do with the crowbar. When you have a Diamond Sword and no Crowbar when on death a crowbar always drops. I do not know why this is happening, any ideas?
The gamemode is probably set to always drop a crowbar instead of the player's actual weapons.
It doesn't allow the Crowbar to be dropped, I think it somewhere in the init.lua
Are you saying it drops when the player dies?
Yes, only when the player doesn't have the crowbar given to them
I think it in the init.lua the drop weapon thing, I don't know
Sorry for the bump but this is a problem
Sorry, you need to Log In to post a reply to this thread.