Home   Help Search Login Register  

Author Topic: my script needs some checking  (Read 1624 times)

0 Members and 1 Guest are viewing this topic.

charunks

  • Guest
my script needs some checking
« on: 31 Dec 2003, 11:10:03 »
I' ve created a build soldier ability in the barracks building, so you can build soldiers in there.
an 'actionbutton' (addaction) calls in a script like this

; building a lawsoldier in your group

#check
if (WestRecource < 149) then {goto "endmon"}
if (soldierlimit - 1 < 0) then {goto "endsol"}

_group = group player
_pos = getpos player

_soldier= "SoldierWLAW" createunit [_pos,_group]
WestRecource=WestRecource-150;publicvariable "WestRecource"
soldierlimit=soldierlimit-1

#live
~2
_dammage = getdammage _soldier
if (_dammage < 1) then {goto "live"} else {goto "dead"}

#dead
hint "a Law Soldier died"
deletevehicle _soldier
soldierlimit=soldierlimit+1
~0.5
goto "end"


#endmon
hint "not enough money"
exit

#endsol
hint "you can only support 11 men"
exit

#end
exit

basically the script works perfect, a soldier gets created, it is under your command and it is as dumb as every ai soldier in opfl.

the only thing that isn' t right is, that after I created it it sends a message
"a law soldier died" after two seconds (goto "dead").
The soldier still excists, does what you want it to blablabla
I' m afraid that the function the variable soldierlimit has is worthless,
so you can build more then 12 soldiers (which is not supported in a group.. it' s just a savetymeasure)

on the other hand, the soldier should have been deleted before that command.. and it isn' t .... so I don' t get it

I' ve tried the alive command and I tried the getdammage approach and in both cases the script thinks the soldier has passed away after two seconds.

what did I do wrong, or what' s going wrong?

thnx

« Last Edit: 31 Dec 2003, 11:13:25 by charunks »

deaddog

  • Guest
Re:my script needs some checking
« Reply #1 on: 31 Dec 2003, 14:53:01 »
Replace:
Code: [Select]
#live
~2
_dammage = getdammage _soldier
if (_dammage < 1) then {goto "live"} else {goto "dead"}

With this:
Code: [Select]
#live
~2
?alive _soldier:goto "live"
goto "dead"



charunks

  • Guest
Re:my script needs some checking
« Reply #2 on: 01 Jan 2004, 14:25:54 »
I allready tried the alive command for it.
it does exactly the same.

deaddog

  • Guest
Re:my script needs some checking
« Reply #3 on: 01 Jan 2004, 18:07:46 »
Did you actually try the code?

Did you stop to think that maybe your problem lies in the IF statement?

If someone offers to help you then you should be willing to at least try what is suggested.  Maybe my suggestion doesn't fix your problem but you won't know if you don't try.

Also, try running this script from the sever only.  Some commands don't always work as expected if runnng on a remote machine.
« Last Edit: 01 Jan 2004, 18:18:52 by deaddog »

charunks

  • Guest
Re:my script needs some checking
« Reply #4 on: 02 Jan 2004, 13:03:18 »
I' m sorry if I gave you that Idea, and I' m glad you are helping me out.
I really tried it. I want it to work and I would be crazy not to try it out!

I also play this mission on my machine first, before trying it on LAN, so it' s the server machine.
here are the three way' s I tried and none seem to work in this mission


Quote
; building a lawsoldier in your group

#check
if (WestRecource < 149) then {goto "endmon"}
if (soldierlimit - 1 < 0) then {goto "endsol"}

_group = group player
_pos = getpos player

_soldier= "SoldierWLAW" createunit [_pos,_group]
WestRecource=WestRecource-150;publicvariable "WestRecource"
soldierlimit=soldierlimit-1

#live
~2
?alive _soldier:goto "live"
goto "dead"

#dead
hint "a Law Soldier died"
deletevehicle _soldier
soldierlimit=soldierlimit+1
~0.5
goto "end"


#endmon
hint "not enough money"
exit

#endsol
hint "you can only support 11 men"
exit

#end
exit

(this is the way you advised me too do.. )

Quote
; building a aawsoldier in your group

#check
if (WestRecource < 124) then {goto "endmon"}
if (soldierlimit - 1 < 0) then {goto "endsol"}

_group = group player
_pos = getpos player

_soldier= "SoldierWAA" createunit [_pos,_group]
WestRecource=WestRecource-125;publicvariable "WestRecource"
soldierlimit=soldierlimit-1

#live
~2
if (alive _soldier) then {goto "live"} else {goto "dead"}

#dead
hint "an AA Soldier died"
deletevehicle _soldier
soldierlimit=soldierlimit+1
goto "end"


#endmon
hint "not enough money"
exit

#endsol
hint " you can only support 11 men"
exit

#end
exit
this was my first attempt

Quote
; building a lawsoldier in your group

#check
if (WestRecource < 149) then {goto "endmon"}
if (soldierlimit - 1 < 0) then {goto "endsol"}

_group = group player
_pos = getpos player

_soldier= "SoldierWLAW" createunit [_pos,_group]
WestRecource=WestRecource-150;publicvariable "WestRecource"
soldierlimit=soldierlimit-1

#live
~2
_dammage = getdammage _soldier
if (_dammage < 1) then {goto "live"} else {goto "dead"}

#dead
hint "a Law Soldier died"
deletevehicle _soldier
soldierlimit=soldierlimit+1
~0.5
goto "end"


#endmon
hint "not enough money"
exit

#endsol
hint "you can only support 11 men"
exit

#end
exit
this was my second and I posted this one on the forum.

I am convinced that all these codes should work.. they all say the same in a different way!

I discovered that after the soldier really dies, it gets deleted. I also have respawn in this mission and the script prevents them from respawning, just as it was meant to.
The soldierlimit doesn' t seem to function right (soldierlimit + 1)

one extra question, what' s the biggest difference in your code and mine
(I know it' s writtin in a different way:?this:then and I IF (this) then
but it comes down to the same. )What' s the difference flashpoint sees in it?
« Last Edit: 02 Jan 2004, 13:13:10 by charunks »

deaddog

  • Guest
Re:my script needs some checking
« Reply #5 on: 02 Jan 2004, 18:18:20 »
Sorry about that, I thought that you didn't give my code a chance.

Anyway, I made a little test mission and here is your problem :)

createunit does not have a return value.  That means the variable _soldier, is null.  I should have spotted this sooner  :P

One way around this is to have a temporary group:

Place a unit in the editor and put this in its init line:
tempgroup=group this;deletevehicle this

In your build script, put this:

"SoldierWLAW" createunit [_pos,tempgroup]
~1
_soldier=leader tempgroup

[_soldier] join _group


and the complete script:

Code: [Select]
#check
if (WestRecource < 149) then {goto "endmon"}
if (soldierlimit - 1 < 0) then {goto "endsol"}

_group = group player
_pos = getpos player

"SoldierWLAW" createunit [_pos,tempgroup]
~1
_soldier=leader tempgroup

[_soldier] join _group

WestRecource=WestRecource-150;publicvariable "WestRecource"
soldierlimit=soldierlimit-1

#live
~2
if (alive _soldier) then {goto "live"}

#dead
hint "a Law Soldier died"
deletevehicle _soldier
soldierlimit=soldierlimit+1
~0.5
goto "end"


#endmon
hint "not enough money"
exit

#endsol
hint "you can only support 11 men"
exit

#end
exit


I tested it and it works.  The only thing is when the soldier dies, he gets deleted instantly.  That didn't look very good.  You might want to put a small delay in there (10-20 seconds).

deaddog

  • Guest
Re:my script needs some checking
« Reply #6 on: 02 Jan 2004, 20:10:50 »
I just thought of another way of doing this without having to use a temporary group.

replace this part:
Code: [Select]
"SoldierWLAW" createunit [_pos,tempgroup]
~1
_soldier=leader tempgroup

[_soldier] join _group

With this:
Code: [Select]
_before=units _group
"SoldierWLAW" createunit [_pos,_group]
~1
_soldier=((units _group) - _before) select 0

charunks

  • Guest
Re:my script needs some checking
« Reply #7 on: 02 Jan 2004, 21:31:46 »
Yeah, it works! thnx a million..

couldn' t have done that without your help!