Archived copy of war3source.com, the War3Source forum (2009–2020), rebuilt from the Internet Archive by wc3mods.net. This page was captured on 2012-10-24 (original capture). Forum · All archived topics · Wiki · Bug tracker · Blog
Chat

War3:Source
October 24, 2012, 03:27:49 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Download: http://war3source.com/index.php?board=9.0
What is War3Source?: http://war3source.com/index.php?topic=200.0
Sample Stats: http://war3source.com/war3stats
Steam Community Group: http://steamcommunity.com/groups/war3source
War3Source SVN Checkout: http://ownageclan.com/svn/war3source/
War3Source servers: http://www.game-monitor.com/search.php?vars=war3_version=
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Dice method?  (Read 346 times)
Wangwang
Newbie
*
Posts: 20


View Profile Email
« on: March 26, 2011, 02:13:31 AM »

Looking for someone to give me a quick hand with my latest race.

Long story short I'm trying to make my race randomly give either 1-5 gold, 10-50 xp or +10-50 health upon damaging an enemy. However, I'd rather keep it as one skill, instead of splitting it up.

I know this won't work, but basically

Code:
public OnWar3EventPostHurt( victim, attacker, damage )
{
if( W3GetDamageIsBullet() && ValidPlayer( victim, true ) && ValidPlayer( attacker, true ) && GetClientTeam( victim ) != GetClientTeam( attacker ) )
{
if( War3_GetRace( attacker ) == thisRaceID )
{
new skill_dmg = War3_GetSkillLevel( attacker, thisRaceID, SKILL_DMG );
if( !Hexed( attacker, false ) && skill_dmg > 0
Dice[1]=<code for gaining extra xp>
Dice[2]=<code for gaining extra gold>
Dice[3]=<code for gaining health>
}
}
}

Assuming that makes sense, how would I impliment this? I'm sure I've seen it somewhere but now I can't seem the find it T_T
Logged
Wangwang
Newbie
*
Posts: 20


View Profile Email
« Reply #1 on: March 26, 2011, 02:27:03 AM »

FOUND IT!

For anyone looking for the same thing as I was, set out as follows:

Code:
new DICE = (GetRandomInt(Lowest,Highest));
if(DICE == Lowest)
{
<code>
}
if(DICE == X)
{
<code>
}
if(DICE == Highest)
}
<code>
}

Repeating
Code:
if(DICE == X)
for as many values as you need.
Logged
qwerty
Jr. Member
**
Posts: 87


View Profile
« Reply #2 on: March 27, 2011, 11:23:09 PM »

that's basic programming.  infact, that code will work completely as-is in any c++ compiler if you declare the method earlier.  

BUT, the way you have it will essentially roll the dice three times.  each time you damage your opponent, you'll make three calls to dice.

it'd probably be easier to just make it like this: (note, i do not know how to code in war3, so you should just interpret what i write to be the correct format.)

Code:
public OnWar3EventPostHurt( victim, attacker, damage )
{
if( W3GetDamageIsBullet() && ValidPlayer( victim, true ) && ValidPlayer( attacker, true ) && GetClientTeam( victim ) != GetClientTeam( attacker ) )
{
if( War3_GetRace( attacker ) == thisRaceID )
{
new skill_dmg = War3_GetSkillLevel( attacker, thisRaceID, SKILL_DMG );
if( !Hexed( attacker, false ) && skill_dmg > 0
int tempValue (GetRandomInt(lowest,highest))
if(tempValue == 1||2){
<code for extra xp>
}
else if (tempValue == 3||4){
<code for extra gold>
}
else if (tempValue == 5||6){
<code for extra hp>
}
else if (tempValue == 7){
<code for extra xp>
<code for extra gold>
<code for extr hp>
}
}
}
}

note, that that has a 1 in 7 chance of triggering all three.  delete the last else if block if you don't want that, it was just something i thre in for fun
Logged
Wangwang
Newbie
*
Posts: 20


View Profile Email
« Reply #3 on: March 29, 2011, 02:42:59 AM »

that's basic programming.  infact, that code will work completely as-is in any c++ compiler if you declare the method earlier.  

BUT, the way you have it will essentially roll the dice three times.  each time you damage your opponent, you'll make three calls to dice.

it'd probably be easier to just make it like this: (note, i do not know how to code in war3, so you should just interpret what i write to be the correct format.)

Code:
public OnWar3EventPostHurt( victim, attacker, damage )
{
if( W3GetDamageIsBullet() && ValidPlayer( victim, true ) && ValidPlayer( attacker, true ) && GetClientTeam( victim ) != GetClientTeam( attacker ) )
{
if( War3_GetRace( attacker ) == thisRaceID )
{
new skill_dmg = War3_GetSkillLevel( attacker, thisRaceID, SKILL_DMG );
if( !Hexed( attacker, false ) && skill_dmg > 0
int tempValue (GetRandomInt(lowest,highest))
if(tempValue == 1||2){
<code for extra xp>
}
else if (tempValue == 3||4){
<code for extra gold>
}
else if (tempValue == 5||6){
<code for extra hp>
}
else if (tempValue == 7){
<code for extra xp>
<code for extra gold>
<code for extr hp>
}
}
}
}

note, that that has a 1 in 7 chance of triggering all three.  delete the last else if block if you don't want that, it was just something i thre in for fun

I don't quite understand how what you've posted differs from what I posted originally. I already implemented the code I posted in to 2 of my races, and they work fine. "BUT, the way you have it will essentially roll the dice three times" If by this you're suggesting that each time an opponent is damaged, it will output xp 3 times, xp twice gold once etc etc, then I have to say you're wrong, each dice outcome has an equal chance. If I wanted to change it so the outcomes are weighted, I would do so, and it's not that hard to do.
Logged
qwerty
Jr. Member
**
Posts: 87


View Profile
« Reply #4 on: March 29, 2011, 11:47:35 AM »

it just looked like you called that dice method three times for every hit. 

i just eliminated the extra method, and made it only trigger once per hit.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!