Home   Help Search Login Register  

Author Topic: Problem with money script. HELP!  (Read 8032 times)

0 Members and 1 Guest are viewing this topic.

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #30 on: 08 Sep 2006, 16:34:28 »
still the same error: ... : Error Zero divisor

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #31 on: 08 Sep 2006, 17:07:28 »
OK, then i need to have a look into it when i'm back home.

Meanwhile you could try to debug;

make that radio-alpha trigger, which i suggested a few posts
ago and show me, what is displayed:

Code: [Select]
Trigger:
activation: radio alpha / repeated
condition: this
onActivation: hint format ["%1\n\n%2\n\n%3\n\n%4",cash_array,temp_cash,temp_count,temp_array]

Maybe you can arrange posting a screenshot or attach one to your post.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #32 on: 08 Sep 2006, 17:57:08 »
 So, here are the screen shots...  The resolution of the pic is a bit bad, but you can still see it
« Last Edit: 19 Aug 2009, 21:56:20 by Mandoble »

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #33 on: 08 Sep 2006, 18:41:08 »
OK, from what i can see in the screens, the subarrays of cash_array consist of 4 elements instead of
3 (how it's supposed to be). I need to make further investigations in that when back home (5 to 6 hours).

There is probably some detail i've overseen or you have mixed up something - i will find out tonight.  ;)

If it's not a problem, could you upload the scripts: cash_update and init.sqs, so that i can try it with
your stuff instead of writing or copy/pasting it myself?
That way we can ensure that their aren't differences what we are talking about and i have one more
error source available for debugging.  :)

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #34 on: 08 Sep 2006, 18:50:18 »
Here thay come: init.sqs and cash_update.sqs
I have about 70 scripts on the mission directory so tell me if send the wrong scripts
(mostly buy weapons scripts)

theres 4 players on west and 4 on east  (w1 w2 w3 w4  e1 e2 e3 e4)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #35 on: 08 Sep 2006, 19:30:19 »
Yep, it seems i found the error;

The array SET command i've been using wrong -  :whistle:

In init.sqs replace the line:

Code: [Select]
(cash_array select _i) set [3,_i]
with:

Code: [Select]
(cash_array select _i) set [2,_i]
And in the trigger:

replace the line in onActivation field:

Code: [Select]
cash_array select temp_count set [2,temp_cash]; cash_update = false

with that line:

Code: [Select]
cash_array select temp_count set [1,temp_cash]; cash_update = false

I hope it works now.

btw - i've seen in your init.sqs another mistake:

you publicVariable something and in next line you say it is 0
It should be the other way around - first assign value to variable and second broadcast
it to network.
But you don't need to publicVariable anything in init.sqs since the script is being
executed global.
Only in case you want to create random numbers (server side only) and then broadcast
them to clients.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #36 on: 09 Sep 2006, 08:45:49 »
 If you mean the 2 lines in the init.sqs :

publicvariable "playerse"
playerse = 0

publicvariable "playersw"
playersw = 0


they are supposed to be 0
its a counter how many units have been killed

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #37 on: 09 Sep 2006, 08:51:50 »
I insert the codes and now it works well before respawn... after I die and then respawn it dosen't work

 the good thing is no: error messeges
then, I'm not sure does it added the cash to the palyers account. If  w2 killes e3 it should add the cash to w2cash

w1cash
w2cash
w3cash
w4cash                                          :confused:

e1cash
e2cash
e3cash
e4cash

are the names of the accounts. own account for every player   :2c:
 


Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #38 on: 09 Sep 2006, 11:00:06 »
I've been sitting more than 4 hours on that but no end in sight.

Like you said, to make it work once without error messages it wasn't
that hard (copying the latest codes from here did the job).

But problem is that the array is loosing relation to the unit.


I added a second trigger like the cash_update but for man_update
and put the victim back into the right position of the array but
it idn't work yet: it always ends up with: c0o noid blablaVojak2

I've tried to implement a respawn script but with not success yet.

Look problem is that you can say:
Code: [Select]
!alive unit as condition and it works
but
Code: [Select]
alive unit will not become true after the unit got killed.
I forgot on that totally and since i yesterday first time tried it ingame (the multiplayer
version) i didn't notice it.

OK, the problem with alive/not alive unit i got solved by using the call format command
in combination with the editor given names (like w1) as strings.
I also added a fourth element to the subarrays - each unit has now [unitname,cash,counter,"editorname"]
but to that later, when i solved the last part.

The array still remains with the: blabla#noid Vojak2 instead of the unit - but i'm on it.  ;)


about the scores: forget about w1cash etc.
You got an array, which consists for a subarray for each unit. This subarray features the unit, the cash,
and the position in the array (counter).

You could now add a custom action to each unit to check score and use the same way like
in cash_update.sqs to determine the cash of the unit which is executing the script.
An addAction script is running locally on the pc where you execute it btw.

Or you can for example globally display the score of everybody - the cash is in every case in
subarray select 2.

~S~ CD
« Last Edit: 09 Sep 2006, 12:22:03 by Chris Death »
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #39 on: 09 Sep 2006, 13:28:40 »
Well, what shall i say?  :scratch:

I've got it.  :)

OK, due to some circumstances (ofp engine - lol) i had to make some
changes but i will post you everything again including an explanation
what you're doing where.

Step 1:

Into each unit's init field put this:

Code: [Select]
"w1" exec "killed_alive.sqs"; this addEventHandler ["killed",{_this exec {cash_update.sqs}}]
this is the init field of the unit being named: w1
the "w1" you must change accordingly to their unit's editor names



Step 2:

Init.sqs

Code: [Select]
cash_array = []
temp_cash = 0
temp_count = 0
temp_counta = 0
cash_update = false
man_update = false

"if (alive _x) then {cash_array = cash_array + [[_x,0,0]]}" foreach [w1,w2,w3,w4,e1,e2,e3,e4]

_i = 0
_count = count cash_array

#loop

(cash_array select _i) set [2,_i]

_i = _i + 1
?(_i < _count): goto "loop"

cash_start = true


In init.sqs you create cash_array and for each unit which is alive of given units [w1,w2,etc.] a subarray = [unit,0,0]
Then an loop with an increasing number will make the third element of the subarrays into a reference number for
later use of the subarrays.
Also at the begin of init.sqs all necessary variables will be initialized.



Step 3:

Create two triggers:

Trigger 1:

Code: [Select]
size: 0/0 - repeatedly
condition: cash_update
onActivation: cash_array select temp_count set [1,temp_cash]; cash_update = false

Trigger 2:

Code: [Select]
size: 0/0 - repeatedly
condition: man_update
onActivation: cash_array select temp_counta set [0,temp_unit]; man_update = false

Trigger 1 instantly updates the score for the unit which killed another unit.
It's condition cash_update becomes true by the script cash_update.sqs and
once the trigger has done it's work, it sets cash_update back to false.
Trigger 2 works same way as trigger 1 with the difference that this trigger
puts the respawned unit back into it's subarray position in cash_array.



Step 4:

cash_update.sqs

Code: [Select]
@!cash_update

"if (_this select 1 == _x select 0) then {temp_cash = (_x select 1);temp_count = (_x select 2); temp_cash = temp_cash + 40}" forEach cash_array

cash_update = true
"publicVariable _x" forEach ["cash_update","temp_count","cash_update"]
exit

This script is executed by the eventhandler "killed" and it gets automatically passed
parameters: _this select 0 = the victim and _this select 1 = the killer
The script assigns the actual cash of the killer to the variable: temp_cash and then adds
40 to it. Also it assigns the counter to the variable: temp_count.
Then cash_update becomes true and the three variables get broadcast to everybody. -> trigger 1
At the beginning of the script is a condition: @!cash_update - this condition avoids
that two units who died in nearly same time, are mixing up the global variables



Step 5:

killed_alive.sqs

Code: [Select]
_name = _this
_man = call format ["%1",_name]
_temp_counta = 0

@cash_start

"if (_man == _x select 0) then {_temp_counta = _x select 2}" forEach cash_array

#loop


@(call format ["!alive %1",_name])

@(call format ["alive %1",_name])

call format ["%1 addEventHandler [{killed},{_this exec {cash_update.sqs}}]",_name]

@!man_update

temp_counta = _temp_counta
temp_unit = call format ["%1",_name]

man_update = true
"publicVariable _x" forEach ["temp_counta","temp_unit","man_update"]

goto "loop"


At the beginning of this script the editor name (e.g: w1) will be copied to _name
and the unit itself to _man (this is used to keep the variables local to the
script). Also a local _temp_counta for the script only is created to make a
reference for the unit's subarray position in cash_array.
Then the script waits for the condition cash_start, which will be made true
in init.sqs after initializing a working cash_array.

In the loop the script checks for the editor-name of the unit, wether it's alive or not.
If the unit is not alive, the script will wait until it has respawned.
Once respawned the unit and the reference counter will be copied into temp_unit
and temp_counta.
Then man_update will be set to true and all three become broadcasted to
network. -> trigger 2


Well that should it be.  :)

I could not test it in multiplayer environment so i cannot tell you that it's 100%
testet, but based on my experience it should work now.
Also there could probably come a problem in case 2 units get really killed almost
in same time because of publicVariable taking longer than the time between the
two kills - this is game engine related.

I've also attached a working example mission.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #40 on: 09 Sep 2006, 15:04:01 »
Still a problem with the accounts
I had killed 2 enemy units so I should have got +80$... but when I tried to buy a beretta 92f for 100$ I got a messege : You don't have enough money
(the start cash is 50$)   :confused:

here are couple of scripts that might help  (the buy scripts and start cash script)






Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #41 on: 09 Sep 2006, 17:25:11 »
I told you that the cash of each unit is inside the according subarray of cash_array.

Look, cash_array looks like this:

[[w1,0,0],[w2,0,1],[w3,0,2],[w4,0,3],[e1,0,4],[e2,0,5],[e3,0,6],[e4,0,7]]

This is now an array consisting of 8 subarrays, each featuring 3 informations:

1) The unit

2) Their unit's cash

3) A number which indicates the position of the subarray in cash_array


At start of the mission the cash of each unit is at 0 here, while you have
another variable (e.g: e1cash) which you set to 50.
If you want the start cash to be 50, then you should not make it to
0 in init.sqs but to 50 btw.

Where do you transfer the head-bounty from the unit's array to it's
proposed variable (e1cash for e1)?

If your other scripts are all setup to cooperate with a variable e.g. e1cash
then we need to implement it (this would just make a few changes in
cash_update.sqs)


Also i noticed that the performance we saved with that array/subarray method,
you've put into the other scripts. I mean the way how you ask in the script
everything seperately for each playername.

For example it doesn't matter wether the player is unit w1 or w2 or e4, you only
need to add the actions to the player and not to it's editorname (this would save
you alot of lines inside your scripts).

-------------------------------------------------

Just one thing i'd expect from you too;
do your homework and try to find out by yourself, what my code
is doing. Start with using radio-triggers to let you display some variables
or arrays so that you figure out what happens when.
I just have to say this because i see how you waiste holy performance in
the other scripts by running the same commands over and over again.

I would feel stupid in just making a mission for somebody (or a part of a
mission), without this guy having understood what i told him.  :)

-------------------------------------------------------------------------------------------


:edit - and another thing i noticed is that you made it for players only
If i know this from beginning, i could have saved alot of work too with
an easier way for the respawn check script.
However, i will not again change everything, maybe later when this is
finished i'll think one more time about it.

~S~ CD
« Last Edit: 09 Sep 2006, 18:08:13 by Chris Death »
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #42 on: 09 Sep 2006, 19:42:41 »
I made little changes to the cash_update.sqs and now it works very well.  :thumbsup:

thanks very much.... I couldn't done this without your help.  :)
now I realy understand what the scripts do...

I have read my homework  :yes:


Well, what shall i say?  :scratch:

I've got it.   :check:

now I know how much time it takes to do and try diffirent things

SO NOW IT WORKS PERFECT

I'll have your name in readme in the part : special thanks to...



Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #43 on: 09 Sep 2006, 20:56:56 »
 :) good to see you got the endspurt on your own

If anything from the code is still not clear, or if you run
into further problems with it, feel free to ask again.

I hope you didn't get me wrong in my last post i did
just want to point out where's the line between the
guy who makes the mission and the guy who helps.

When i was on my weekly shopping tour today i knew
exactly how much money is in cash_array select 0 (on second
position of the sub-array), but don't ask me how much
i got in my pockets (before and after shopping).  :D

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Problem with money script. HELP!
« Reply #44 on: 10 Sep 2006, 09:53:11 »
Tut tut..

Keep the discussion on topic, please.
Those screenshots do not relate directly to the problem and only invite discussion about the mission, a discussion that should be held elsewhere..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.