Home   Help Search Login Register  

Author Topic: getting a variable assigned to a player in a script  (Read 2692 times)

0 Members and 1 Guest are viewing this topic.

Mr.Pibb

  • Guest
getting a variable assigned to a player in a script
« on: 09 Dec 2004, 22:57:34 »
 Hello, could really use a lil help with this :)

 Got this great script working in my mp mission from Triggerhappy that executes a script on each players computers, in which it runs on a loop. The script checks if a player has lost rating in a town, thus the town hates him if he has.
 Problem is a player could sit outside a town radius 'rating check area' and kill other players within that area, and the other player couldnt fire back without rating loss(all players are west), another words it a terrible opening for cheating.
 So, I have added a simple trigger that uses "hit" eventhandler for any player, and of course a script. Only problems here are that I dont know the exact wording for finding if a player equals the _shooter, and also I dont know exactly what sort of a variable can be assigned to a player that I could reference in another script.

The first script is the temp script that I used to test if the essentials were working, second is the rough copy that prolly dont work, but it shows whats desired.

Code: [Select]
;A trigger event handler runs this script if any player "hit" within a proximity

;East side shooter is just temp test, shooter will be west

_shooter = _this select 1
_shot = _this select 0
?(_shooter == _shot): exit
?(Side _shooter == East):hint format ["Side _shooter == East"]

Exit

;Need to actually get if shooter equals a player. Then need to assign a variable(shooterplayer) to that player that can be referenced in another script that runs on each players computers that is looping. Below is desired script, but prolly written incorrectly.

_shooter = _this select 1
_shot = _this select 0
shooterplayer = objNull
?(_shooter == player):player = shooterplayer

Exit

Any help on the _shooter == player and the variable assigning to him would be great. Like I said, I need to reference that variable in another script which is running on each players computers. And the objNull part is there to remove any previous reference for shooterplayer so its only referencing one player at a time.

One last thing, I am using a Trigger to execute this with "hit", but I want to actually check the entire island for this occurrance, so the prox zone will be huge,-west present-, but only west in game will be players, would a zone that big cause lag?

TIA

Christian
« Last Edit: 09 Dec 2004, 23:03:01 by Mr.Pibb »

Offline CrashDome

  • Members
  • *
Re:getting a variable assigned to a player in a script
« Reply #1 on: 09 Dec 2004, 23:14:10 »
publicvariable "shooterplayer"

However, I suggest adding and using the Chain of Command's Network Services add-on

Much easier functions to deal with and you can do remote calls on one, all, or specific clients.

Mr.Pibb

  • Guest
Re:getting a variable assigned to a player in a script
« Reply #2 on: 09 Dec 2004, 23:25:43 »
Thanks CrashDome

Let me get this right, so ur saying that all of the below script would respond correctly except just change player = shooterplayer  to  player = publicvariable "shooterplayer"? Now let me ask, would I then need to type - publicvariable "shooterplayer" anytime I wanted to refer to it? Examples like:
publicvariable "shooterplayer" = objNull , ?(publicvariable "shooterplayer" = player):goto dunno      

Code: [Select]
_shooter = _this select 1
_shot = _this select 0
shooterplayer = objNull
?(_shooter == player):player = shooterplayer

Exit

And honestly I am learning as I go here on ofp scripting, so I fear the addon u suggested may confuse me more than help right now in my current knowledge of scripting.

Thanks :)

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:getting a variable assigned to a player in a script
« Reply #3 on: 09 Dec 2004, 23:40:34 »
Code: [Select]
publicvariable "shooterplayer"

This just declares the variable shooterplayer as a public variable.

I don't think you need to declare this more than once.


Planck
I know a little about a lot, and a lot about a little.

Mr.Pibb

  • Guest
Re:getting a variable assigned to a player in a script
« Reply #4 on: 09 Dec 2004, 23:45:19 »
 Gotcha Planck

ok, I will go ahead and test that, see if it pans out.

 thanks

@CrashDome

Is that addon within Chain Of Command program itself?


Mr.Pibb

  • Guest
Re:getting a variable assigned to a player in a script
« Reply #5 on: 10 Dec 2004, 02:20:38 »
If any of u guys could just take a look at this and maybe find the mistake here I would really appreciate it.
Im still having some problems here, either the player is not being referenced by the public variable or Im not getting the reference in the second script, let me just simply throw down what I have goin, its pretty simple:

A trigger with eventhandler"hit" for an ai west guy (joe)  (for testing) exec townareakill.sqs

townareakill.sqs
Code: [Select]
_shooter = _this select 1
_shot = _this select 0
shooterplayer = objNull
?(_shooter == player):player = publicvariable "shooterplayer"; hint format ["shooterplayer public variable"]

Exit

Then there is the other script that runs on each players computer on a loop, and within in it I put a new script with the public variable "shooterplayer"

Code: [Select]
?(player == shooterplayer): hint format ["shooterplayer has been referenced in Townsqs"]
That script would execute this line when the players rating drops, which in this case would be due to killing Joe(which should have set "shooterplayer" to player), but the hint format never showed so something is wrong.

The hint format in the first script, townareakill, does come up every time tho.

 I just think its once again a matter of incorrectly inputing something here for the public variable referencing the player.

 hopefully someone can find my mistake here  :P

 btw, no errors come up either !
« Last Edit: 10 Dec 2004, 02:51:11 by Mr.Pibb »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:getting a variable assigned to a player in a script
« Reply #6 on: 10 Dec 2004, 02:29:10 »
Code: [Select]
publicvariable "shooterplayer"

_shooter = _this select 1
_shot = _this select 0
shooterplayer = objNull
?(_shooter == player):player = shooterplayer

Exit

This may work perhaps
The variable is declared as public at the beginning of the script so it is shared between clients.



Planck
I know a little about a lot, and a lot about a little.

Mr.Pibb

  • Guest
Re:getting a variable assigned to a player in a script
« Reply #7 on: 10 Dec 2004, 02:46:04 »
got the public variable as u have it, still doesent seem to register when referencing player to that publicvariable in the second script, no clue right now
 Going to just keep testing and trying to eliminate possibilites

 I did temporarily remove the objNull in case it was nullifying the public variable as it is at the beginning, no difference, second script just skips by ?(player == shooterplayer) as if its false. Weird.

 Thanks
« Last Edit: 10 Dec 2004, 02:54:23 by Mr.Pibb »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:getting a variable assigned to a player in a script
« Reply #8 on: 10 Dec 2004, 03:08:31 »
Making the variable public only serves to make the state of the variable available to all clients in a MP game.

Your other line might be better thus:

?(player == shooterplayer): hint format ["%1  has been referenced in Townsqs", shooterplayer]

Try that anyway


Planck
I know a little about a lot, and a lot about a little.

Mr.Pibb

  • Guest
Re:getting a variable assigned to a player in a script
« Reply #9 on: 10 Dec 2004, 03:18:15 »
No response still Planck

I do wonder, the script that has the final shooterplayer reference there, its a script executed initially by a gamelogic that indeed runs on each players computer, and it consantly runs in loops - any of that possibly causing it to not recognize the new public variable? I dunno, would a global variable be better? (even tho I dont know what a global variable is lol)
 Anyhow, if nothin comes of all this I can try CrashDomes suggestion of using that addon for Chain Of Command.
« Last Edit: 10 Dec 2004, 03:19:58 by Mr.Pibb »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:getting a variable assigned to a player in a script
« Reply #10 on: 10 Dec 2004, 03:27:03 »
Try this:

publicvariable "shooterplayer"

_shooter = _this select 1
_shot = _this select 0
shooterplayer = objNull
?(_shooter == player):shooterplayer = player

Exit

I should have noticed that mistake before.


Planck
I know a little about a lot, and a lot about a little.

Mr.Pibb

  • Guest
Re:getting a variable assigned to a player in a script
« Reply #11 on: 10 Dec 2004, 03:45:19 »
 just the reversed of player = shooterplayer eh? Does that make a difference? If it does I just learned something new lol. Will try it.

Mr.Pibb

  • Guest
Re:getting a variable assigned to a player in a script
« Reply #12 on: 10 Dec 2004, 03:52:09 »
 ahh the sweet smell of victory :)
It works now.

So now, to understand this, is it because the variable must always come before the unit or vehicle or whatever it is being equalled to?

thanks Planck   ;)

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:getting a variable assigned to a player in a script
« Reply #13 on: 10 Dec 2004, 03:59:13 »
Well.......as it was .......

shooterplayer was equal to ObjNull

and then you were trying to make the player ObjNull

player is a game variable and always equals the player.

What was needed was to make your variable equal to the player if the condition was met.


Planck
I know a little about a lot, and a lot about a little.

Mr.Pibb

  • Guest
Re:getting a variable assigned to a player in a script
« Reply #14 on: 10 Dec 2004, 04:11:29 »
lol, I do see what u mean now.

Thanks again for the help there, my greatest enemy at times can just be putting the right stuff in the wrong way  ::)

Christian

Mr.Pibb

  • Guest
Re:getting a variable assigned to a player in a script
« Reply #15 on: 12 Dec 2004, 17:51:11 »
I quickly unsolved, put this in, and re-solved this topic due to an error in the final script - CrashDome and Planck both corrected me on this, so here is the proper form, only the publicvariable "shooterplayer" has been moved



_shooter = _this select 1
_shot = _this select 0
shooterplayer = objNull

?(_shooter == player):shooterplayer = player
publicvariable "shooterplayer"

Exit