Home   Help Search Login Register  

Author Topic: Add money to civilians  (Read 1563 times)

0 Members and 1 Guest are viewing this topic.

Offline Yasirotta

  • Members
  • *
Add money to civilians
« on: 26 Jan 2009, 20:18:41 »
I would like to add random value of money to civilians.
First, it would be nice if i could set 60% chance they have even something, so its possible that civilian doesnt't have any cash. After this, each civilian could carry random value of cash between 5 to 50 dollars. I have about 25 civilian, so is there easy way to script this or do i have to name every civilian to this script ?
I would like use script so, that you can shoot civilian and take possible cash in action menu.

I use this code in my init.sqs for money:
Code: [Select]
playermoney = 100

Offline Ext3rmin4tor

  • Members
  • *
Re: Add money to civilians
« Reply #1 on: 27 Jan 2009, 14:49:39 »
You can do that adding an event handler for each civilian. To do that in no time you should make an area trigger as big as the mission area, activated by the civilian.

Then in the onActivation field write

Code: [Select]
{_x addEventHandler["killed", {_this exec "money.sqs"}]} forEach thisList

After that, create a script named "money.sqs" containing the following code

Code: [Select]
_moneyTaken = false
_killed = _this select 0
_killer = _this select 1
_killedPos = getPos _killed


;wait unitil the player is close enough to take money
@(_killer distance _killedPos < 4)

;add "take money" action if the killed civilian has money (60% of chance)
_rnd = random(1)
? (_rnd  <= 0.6): goto "hasMoney"
goto "end"

#hasMoney


#takeMoney
;store the money owned by player before taking more from the corpse

_currentMoney = playerMoney

;stop until the player is within the action range
@(_killer distance _killedPos < 4)
_moneyAction = _killer addAction["Take the money", "takeMoney.sqs"]

;the script stops until the player is too far from the target or
;he takes the money
@((_killer distance _killedPos >= 4) or (playerMoney > _currentMoney))

;if the player is too far from the corpse remove the action and restart the loop
? (_killer distance _killedPos >= 4): goto "removeAction"
;else the player has taken the money and exit the loop
goto "endLoop"

#removeAction
_killer removeAction _moneyAction
goto "takeMoney"

#endLoop
_killer removeAction _moneyAction
goto "end"



#end
exit

and create a second script named "takeMoney.sqs" (while the first script name can be wathever you want, you just need to change the event handler parameters in the trigger, the name of this script is important or nothing will work!!!!)

Code: [Select]
_money = 5 + floor(random(46))
playerMoney = playerMoney + _money
(_this select 1) removeAction (_this select 2)
exit

I tested it in Armed Assault since I don't have OFP installed but since it is written in SQS syntax and I used only OFP commands it should work in that game too.

There is only one known problem: if you killed a civilian which drops money, then go far enough from its location to have your action removed and then kill another civilian who also drops money and you take them from this last dead guy, your action will be removed also for the first guy you killed because the script waits until whether you're not too far from the corpse or you've already taken the money and the check is performed on the playerMoney. So if you take the money from the second guy your amount raises but, doing so, also the script for the other guy detects your money has raised and interrupt the script.

Unfortunately OFP doesn't allow to define custom object variable like ArmA, so I can't make a check for example on an object variable for each civilian called for example "civilianMoney". If I could do this I could check if the civilian has still it's money after the player will have taken it. If someone can find a way to do this also in OFP is welcome, otherwise I suggest you immediately take the money from the corpse as soon as you have the chance before approaching another corpse and take its money.
« Last Edit: 27 Jan 2009, 15:02:51 by Ext3rmin4tor »
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Walter_E_Kurtz

  • Guest
Re: Add money to civilians
« Reply #2 on: 28 Jan 2009, 01:31:31 »
Floor is an ArmA command.

For OFP, the TakeMoney.sqs script would start:
Code: [Select]
_roulette = random(46)
_money = 5 + _roulette - (_roulette mod 1)

Offline Ext3rmin4tor

  • Members
  • *
Re: Add money to civilians
« Reply #3 on: 28 Jan 2009, 10:50:35 »
Ah sorry, I didn't remember that. I thought a stupid function like floor was implemented in OFP
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Yasirotta

  • Members
  • *
Re: Add money to civilians
« Reply #4 on: 28 May 2009, 19:14:11 »
Hello, i was trying this all and i got this error message:

Code: [Select]
(_Killer distance _killedPos < |#| 4 ) Error Distance Type array, expected object

And next question, is my TakeMoney script right when its like this ?

Code: [Select]
_roulette = random(46)
_money = 5 + _roulette - (_roulette mod 1)
playerMoney = playerMoney + _money
(_this select 1) removeAction (_this select 2)
exit

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Add money to civilians
« Reply #5 on: 28 May 2009, 20:38:49 »
Code: [Select]
(_Killer distance _killedPos < |#| 4 ) Error Distance Type array, expected object
In OFP the distance command expects two objects, using arrays won't work. So replace all occurences of "_killedPos" with "_killed" and remove the 4th line of the script ("_killedPos = getPos _killed").
try { return true; } finally { return false; }

Offline Yasirotta

  • Members
  • *
Re: Add money to civilians
« Reply #6 on: 28 May 2009, 21:06:08 »
YEA BABY IT WORKS !  :D

Only this was, that there was group of 6 civilian. Then, when i tested this i shooted all of them and there appears to be 3 lines of "Take Money" in action menu. However, i press one of them and rest 2 disappear also. Then, i check money and i got 36 more. Sounds like i have taken just one persons cash, not all of them.

I must test this few times more, it can be also that i got total 36 bucks from 3 civilians, but still wondering why those 2 other line also disappear.

Walter_E_Kurtz

  • Guest
Re: Add money to civilians
« Reply #7 on: 01 Jun 2009, 16:59:28 »
How many civilians are there in the mission altogether?

How close together were the civilians when you shot them? You will have the option to "Take Money" from each corpse within 4 metres.

I suggest you reduce the distance to 1 metre or so. Then the "Take Money" action will only appear when you are crouching over the corpse - realistic, if distasteful.
Code: [Select]
@(_killer distance _killed < 1)Now the problem should only occur when two bodies overlie each other.

Offline Yasirotta

  • Members
  • *
Re: Add money to civilians
« Reply #8 on: 01 Jun 2009, 18:23:45 »
Yup, it works better. Now player cant "fast collect" cash and run.
Thank you very much.