Angelwolf Posted October 4, 2017 Share Posted October 4, 2017 I'm trying to make a simple script whereby the player can collect ammo for his weapon. function Script:Use(player) if player.weapons[1].ammo<player.weapons[1].maxammo then player.weapons[1].ammo= player.weapons[1].ammo + self.ammoamount end end This works but the player must look at the item and 'use' it for it to activate. When I try to turn this into a collision script, it doesn't work. Can anyone help me adjust this so that it will give the player ammo on collision? This was hacked up, edited and simplified from Haydenmango's old script from 2014. My weapon script has a variable of maxammo. It works on 'use' but for the life of me, I cannot translate it to collision. Quote My Games: Nightmare Prism:::WolfTale:::Dungeon Creeper:::Despair of Ordinary Men:::Piano Simulator 2016:::House (W.I.P) Link to comment Share on other sites More sharing options...
Herobot Posted October 4, 2017 Share Posted October 4, 2017 You'll need a way for the ammo item to tell that the colliding entity is the player, otherwise the item will attempt to add ammo to something that doesn't use ammo and cause a crash. Add this variable to the player: Script.player=true Then put this code on the ammo item: function Script:Collision(entity, position, normal, speed) if entity.script~= nil and entity.script.player ~= nil then --Check if colliding entity is the player if entity.weapons[1].ammo < player.weapons[1].maxammo then entity.weapons[1].ammo = players.weapons[1].ammo + self.ammoamount end end end When an entity collides with the ammo, the script makes sure the entity has a script attached and that the entity has the "player" variable, then adds ammo if it does. Quote Link to comment Share on other sites More sharing options...
Angelwolf Posted October 5, 2017 Author Share Posted October 5, 2017 Thank you for your reply, I was still running into issues using the code you gave me, however you put me on the right path and I now have it working. Thank you so much! Script.ammoamount=6 --int "Ammo Amount" function Script:Collision(entity, position, normal, speed) if entity.script~= nil and entity.script.player ~= nil then --Check if colliding entity is the player if entity.script.weapons[1].ammo< entity.script.weapons[1].maxammo then entity.script.weapons[1].ammo= entity.script.weapons[1].ammo + self.ammoamount self.entity:Release() end end end function Script:Use(player) if player.weapons[1].ammo<player.weapons[1].maxammo then player.weapons[1].ammo= player.weapons[1].ammo + self.ammoamount self.entity:Release() end end 2 Quote My Games: Nightmare Prism:::WolfTale:::Dungeon Creeper:::Despair of Ordinary Men:::Piano Simulator 2016:::House (W.I.P) Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.