scottmmmm Posted October 8, 2014 Share Posted October 8, 2014 Hi folksI'm trying to build my first mod for the game. My simple idea is to create an unreliable gun that randomly blows up and kills the player when fired. Not very compelling, I know, but good to learn the basics.The two problems I've come up against are :-1) how to randomly generate numbers in the scripts. Lua supports math.random() (according to what I've seen on google), but calling this function doesn't work in my script. Another route I tried was Rand.Next(), which I saw in the Javadoc. No luck there unfortunately.2) how to kill the player. I tried calling player:setBodyDamage(-1.0), but this didn't do anything.Any ideas?Thanks Link to comment Share on other sites More sharing options...
Brybry Posted October 8, 2014 Share Posted October 8, 2014 for 1) try ZombRand I think it's 0 to max with max being exclusive (so for example 9 would return 0 to 8, or maybe 8.9999...I don't remember)not sure for the other thoughEdit:maybe try player:inflictWound(BodyLocation.Hand,1.0,false,10.0) or player:getBodyDamage():AddDamage(BodyDamage:ToIndex(BodyPartType.Hand_R), damage)or maybe something like player:getBodyDamage():DamageFromWeapon(InventoryItemFactory.createItem("Base.Shotgun")) if you flat out want to kill them then I think you'd want setOverallBodyHealth and/or setHealth Pudge 1 Link to comment Share on other sites More sharing options...
Jatta Pake Posted October 8, 2014 Share Posted October 8, 2014 1. To generate a random number you can use ZombRand() +1. So to generate a random number between 1 and 10 would be ZombRand(10) +1. You need the +1 in there because the counting starts at zero. ZombRand(10) would generate a number between 0 and 9. To see it in action, check out the solution to the mod I made to randomly generate an item when another item is used. http://theindiestone.com/forums/index.php/topic/10320-recipe-that-spawns-a-random-item/ Link to comment Share on other sites More sharing options...
Realmkeeper Posted October 8, 2014 Share Posted October 8, 2014 1. To generate a random number you can use ZombRand() +1. So to generate a random number between 1 and 10 would be ZombRand(10) +1. You need the +1 in there because the counting starts at zero. ZombRand(10) would generate a number between 0 and 9. To see it in action, check out the solution to the mod I made to randomly generate an item when another item is used. http://theindiestone.com/forums/index.php/topic/10320-recipe-that-spawns-a-random-item/But, by adding one, you can then never get a value of 0!You would be shifting the possible values of ZombRand(10) into the range of [1.00-10.99] Link to comment Share on other sites More sharing options...
scottmmmm Posted October 8, 2014 Author Share Posted October 8, 2014 Great, thanks for that guys. ZombRand works perfectly. Does anyone know the answer to my other question? Is there any way to kill the player? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now