Post Pacific

Post Pacific (https://postpacific.loc-online.com/index.php)
-   Темы без сохранившегося раздела (https://postpacific.loc-online.com/forumdisplay.php?f=10001)
-   -   hp check in ai.obj (https://postpacific.loc-online.com/showthread.php?t=2490)

avatard 09.11.2005 14:11

hp check in ai.obj
 
How do I go about checking if the mobile has more than 95% of hitpoints left in ai.obj?

I've tried this code, but it wouldn't parse the ai.obj :[


push_event // myself
push_const 28
add
fetch_i // sm
push_const 2400
add
fetch_i // hp
push_const 344
add
fetch_d
push_event // myself
push_const 28
add
fetch_i // sm
push_const 2400
add
fetch_i // max_hp
push_const 1000
add
fetch_d
push_const 1xx.xx0000
div
push_const xx.xx0000
mul
greater
shift_sp 1
func_call 175 // func[Despawn]
shift_sp -1

StaticVoid 09.11.2005 17:20

Code:

push_event // myself
push_const 28
add
fetch_i // sm
push_const 2400
add
fetch_i // hp
push_const 344
add
fetch_d
push_event // myself
push_const 28
add
fetch_i // sm
push_const 2400
add
fetch_i // max_hp
push_const 1000
add
fetch_d
push_const 1xx.xx0000
div
push_const xx.xx0000
mul
greater
shift_sp 1
func_call 175 // func[Despawn]
shift_sp -1

I don't see any reason why the above code portion shouldn't parse. When you are saying that it doesn't parse you mean that the reading of ai.obj fails?

From a semantic point although you make the fetches and the correct calculations and you have in the stack the boolean result of hp>90*maxhp/100 you do not use it (at least not in the above code) and the function Despawn is called no matter what. If you want to call despawn only if the hp are less than 95% of the maxhp then you should add a branch_true <label> after the greater statement to jump over the despawn function.

In which handler do you have the above code?

avatard 09.11.2005 21:00

in the handler 17 for 'warrior' class, and the advice of yours was really useful, thanks

avatard 11.11.2005 10:34

alright, I've been trying for quite some time and now it just crashes the server quite often :[
This is what I've got at this very moment:


handler 17 // OUT_OF_TERRITORY
variable_begin
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end

push_event // myself
push_const 28
add
fetch_i // sm
push_const 2400
add
fetch_i // hp
push_const 344
add
fetch_d
push_event // myself
push_const 28
add
fetch_i // sm
push_const 2400
add
fetch_i // max_hp
push_const 1000
add
fetch_d
push_const 1xx.xx0000
div
push_const xx.xx0000
mul
greater
branch_false L75002
L75001
shift_sp 1
push_event // myself
push_const 28
add
fetch_i // start_x
push_const 2428
add
fetch_i
push_event // myself
push_const 28
add
fetch_i // start_y
push_const 2432
add
fetch_i
push_event // myself
push_const 28
add
fetch_i // start_z
push_const 2436
add
fetch_i
func_call 46 // func[InstantTeleport]
shift_sp -4
shift_sp -1
L75002
handler_end


The idea is that the mobs, that get dragged out of spawn area get teleported back if their amount of remaining health points is greater than 95% of total health.

StaticVoid 11.11.2005 16:42

Code:

handler 17 // OUT_OF_TERRITORY
variable_begin
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end

push_event // myself
push_const 28
add
fetch_i // sm
push_const 2400
add
fetch_i // hp
push_const 344
add
fetch_d
push_event // myself
push_const 28
add
fetch_i // sm
push_const 2400
add
fetch_i // max_hp
push_const 1000
add
fetch_d
push_const 1xx.xx0000
div
push_const xx.xx0000
mul
greater
branch_false L75002
L75001
shift_sp 1
push_event // myself
push_const 28
add
fetch_i // start_x
push_const 2428
add
fetch_i
push_event // myself
push_const 28
add
fetch_i // start_y
push_const 2432
add
fetch_i
push_event // myself
push_const 28
add
fetch_i // start_z
push_const 2436
add
fetch_i
func_call 46 // func[InstantTeleport]
shift_sp -4
shift_sp -1
L75002
handler_end

You are calling function instant_teleport with only 3 legit arguments in the stack. If you look at the function references in my ai.obj Tutorial:

func_call 46 // func[InstantTeleport] (rv, event[myself][sm],int(x),int(y),int(z))

the function uses 4 arguments so the stack must be like this before you call it:
Quote:

z coord
y coord
x coord
event[myself][sm]
space kept for return value with shift_sp 1 (it has an arbitrary value)
instead the stack in your code is like thus:
Quote:

z coord
y coord
x coord
space kept for return value with shift_sp 1 (it has an arbitrary value)
with the shift_sp -1 you should get a stack underflow error in that handler (the boolean value is popped out of the stack after the branch check).


alter your code by adding the following after the label L75001:
L75001
shift_sp 1
[highlight=red:5a498c9f6d]push_event // myself
push_const 28
add
fetch_i // sm
push_const 2400
add
fetch_i
[/highlight:5a498c9f6d]
push_event // myself
push_const 28
add
fetch_i // start_x
push_const 2428
add
fetch_i
push_event // myself
push_const 28
add
fetch_i // start_y
push_const 2432
add
fetch_i
push_event // myself
push_const 28
add
fetch_i // start_z
push_const 2436
add
fetch_i
func_call 46 // func[InstantTeleport]
shift_sp -4
shift_sp -1
L75002
handler_end

I hope the above will solve your problem

avatard 12.11.2005 07:37

I do appreciate. thanks!


All times are GMT. The time now is 16:19.