|
adamandkate Wanderer
Joined: 14 Oct 2009 Posts: 57
|
Posted: Mon Nov 14, 2011 9:42 pm
[Solved] char.vitals.hp inside an @var |
#var health %gmcp.Char.Vitals.hp
#if ((@first) and (@second > 100) and (@health < 1550)) {
do this
}
In this situation the gmcp sets the variable to @health = 1900 but it still fires everytime when it shouldnt.
#var health 1900
#if ((@first) and (@second > 100) and (@health < 1550)) {
do this
}
However, in the above it correctly does not fire. |
|
Last edited by adamandkate on Tue Nov 15, 2011 8:48 pm; edited 1 time in total |
|
|
|
hadar Apprentice
Joined: 30 Aug 2009 Posts: 198 Location: my apt, in california
|
Posted: Tue Nov 15, 2011 2:00 am |
whats the full script? you are showing bits and peices something else could be causing it to misfire
|
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Nov 15, 2011 6:20 am |
The problem looks to be in your usage of the #VARIABLE command. The correct usage in this case would be
Code: |
#var health (%gmcp.Char.Vitals.hp)
#if ((@first) and (@second > 100) and (@health < 1550)) {
do this
} |
The use of parenthesis tells CMud to evaluate the contained portion before assigning it to the variable. Without those CMud has to guess what you want and the best guess that was possible from the string provided was a literal text string. The comparison in your #IF was seeing ("%" < "1") as true. This is a correct behavior. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
adamandkate Wanderer
Joined: 14 Oct 2009 Posts: 57
|
Posted: Tue Nov 15, 2011 11:36 am |
heres the full code. still cant quite get it to work
#var health {%gmcp.Char.Vitals.hp}
#var maxhealth {%gmcp.Char.Vitals.maxhp}
#math percenthealth 100*@health/(@maxhealth)
#if ((@canoverdrive) and (@adrenaline > 100) and (@health < 33101)) {
#var canoverdrive 0
od
}
in this situation canoverdrive =1. adrenaline = 500. health = 100
any ideas. thanks |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Tue Nov 15, 2011 2:21 pm |
You didn't look closely at Vijilante's code. He said to use parentheses, not curly braces. In addition, you don't need #MATH if you are using parentheses. The first part of your code should be:
Code: |
#var health (%gmcp.Char.Vitals.hp)
#var maxhealth (%gmcp.Char.Vitals.maxhp)
#var percenthealth (100*@health/(@maxhealth))
|
|
|
|
|
adamandkate Wanderer
Joined: 14 Oct 2009 Posts: 57
|
Posted: Tue Nov 15, 2011 3:50 pm |
ooooh whoops. thanks!
all working good now. appreciate the help |
|
|
|
adamandkate Wanderer
Joined: 14 Oct 2009 Posts: 57
|
Posted: Tue Nov 15, 2011 4:06 pm |
while were on the topic. is that percent variable correct? it seems to report 100 as the answer regardless of the variables
|
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Tue Nov 15, 2011 4:22 pm |
If both @health and @maxhealth are integers, then CMUD will do integer division (no decimal). For CMUD to do floating point division, you'll need to convert at least one of them into a floating point number, using the %float function.
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: Tue Nov 15, 2011 6:29 pm |
or just use 100.0, there is no need for nested parenthesis on @percenthealth's equation
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Tue Nov 15, 2011 9:28 pm |
Adamandkate--the %gmcp predefined variable only works on muds that implement GMCP, which is essentially mud data encoded into the output stream, similar in concept to MXP. Cmud will automatically grab that data and populate the %gmcp values.
|
|
|
|
danedwards2 Newbie
Joined: 16 Nov 2011 Posts: 1 Location: Chicago, Illinois
|
Posted: Wed Nov 16, 2011 9:22 am |
this thread helped me solve my problem. thanks.
|
|
|
|
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Wed Nov 16, 2011 11:30 am |
another spammer, wtf?
|
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Nov 16, 2011 1:57 pm |
Bleh. Ignore my response above, I was misreading the question.
|
|
|
|
|
|