Redyz Posted January 11, 2010 Author Share Posted January 11, 2010 Hello, this is my first post around here, but I've been lurking for almost a year already, so I'd like to say Hi to everyone. (Well, at least everyone that browses this section)Anyways, enough of this already, on to the main question.I want to change the OnAttack, but instead of just adding +5 or -5 like someone [mentioned](http://www.touchofdeathforums.com/smf/index.php?topic=55259.0), I would like it to add +/- 5%.So I did this algorithm: Damage = Rand(Int((GetPlayerSTR(Index)) - (Int((GetPlayerSTR(Index)) * 0.05))), Int((GetPlayerSTR(Index)) + ((GetPlayerSTR(Index)) * 0.05)))(The code might be messy, I'm kinda tired of looking at all the parantheses)Obviously sometimes the value returned is something like 2.3 or so, and so It doesnt show (E.G Doesn't affect the NPC)So, for it to show, It needs to be rounded, and that is my question.Short version: Need to round the value of a variable, what doThank you. Link to comment Share on other sites More sharing options...
Ruins of Hell Posted January 11, 2010 Share Posted January 11, 2010 Well, you would need to first split the variable, then use Left on the second array, watch.``` ADamage = Split(Rand(Int((GetPlayerSTR(Index)) - (Int((GetPlayerSTR(Index)) * 0.05))), Int((GetPlayerSTR(Index)) + ((GetPlayerSTR(Index)) * 0.05))), ".") Round = Left(Damage(1), 1) If CInt(Round) > 4 Then Round = 1 ElseIf CInt(Round) < 5 Then Round = 0 End If Damage = ADamage(0) + Round``` Link to comment Share on other sites More sharing options...
Admiral Refuge Posted January 11, 2010 Share Posted January 11, 2010 Doesn't Cint() automatically round to the nearest whole number (I know int() doesn't, but I thought Cint() did)? Link to comment Share on other sites More sharing options...
Ruins of Hell Posted January 11, 2010 Share Posted January 11, 2010 @Admiral:> Doesn't Cint() automatically round to the nearest whole number (I know int() doesn't, but I thought Cint() did)?Actually your right…I feel stupid now D:. Link to comment Share on other sites More sharing options...
Redyz Posted January 11, 2010 Author Share Posted January 11, 2010 I'm not familiar with arrays, but anyways, I tried understanding your code, basicly what it does is it checks for the value after the ".", and if it's over 5 or under 4.. Etc (Rounding, I believe?)I tried implementing it in my OnAttack.ess File (I forgot to mention I was using ES, Might be different?) but now it just doesn't affect the NPC in any way, It just never seems to do any damage.Here's my Sub OnAttack, I might be doing something wrong.```Sub OnAttack(Index, Damage)ADamage = Split(Rand(Int((GetPlayerSTR(Index)) - (Int((GetPlayerSTR(Index)) * 0.05))), Int((GetPlayerSTR(Index)) + ((GetPlayerSTR(Index)) * 0.05))), ".") Round = Left(Damage(1), 1) If CInt(Round) > 4 Then Round = 1 ElseIf CInt(Round) < 5 Then Round = 0 End If Damage = ADamage + RoundIf Damage < 1 Then Exit Sub End If If GetPlayerTarget(Index) > 0 Then Call DamageNPC(Index, GetPlayerTargetNPC(Index), Damage) Exit Sub End IfEnd Sub``` Link to comment Share on other sites More sharing options...
Admiral Refuge Posted January 11, 2010 Share Posted January 11, 2010 Just do this:```Damage = Cint(Rand(Int((GetPlayerSTR(Index)) - (Int((GetPlayerSTR(Index)) * 0.05))), Int((GetPlayerSTR(Index)) + ((GetPlayerSTR(Index)) * 0.05))))```Assuming you have your parentheses correct. Link to comment Share on other sites More sharing options...
Redyz Posted January 11, 2010 Author Share Posted January 11, 2010 And after a lot of trial and error, I've finally managed to fix this, thanks a ton guys.I believe a random attacking script that uses percentage would be a good addition to SE.Anyways, you guys can manually replace your Sub OnAttack by this```Sub OnAttack(Index, Damage)Damage = Cint(Rand(Int(GetPlayerSTR(Index) - GetPlayerSTR(Index) * 0.20), Int(GetPlayerSTR(Index) + GetPlayerSTR(Index) * 0.20)))If Damage < 1 Then Exit Sub End If If GetPlayerTarget(Index) > 0 Then Call DamagePlayer(Index, GetPlayerTarget(Index), Damage) Exit Sub End If If GetPlayerTargetNPC(Index) > 0 Then Call DamageNPC(Index, GetPlayerTargetNPC(Index), Damage) Exit Sub End IfEnd Sub```0.20 = 20% So this means +/- 20%Thanks Soul and Admiral Refuge, and Lol, Sorry If it sounds like Im giving this script, It's just that I had trouble finding a random attack script using the search bar, So I figured that posting this one might be helpful to some.~Redyz 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