D.murphy man 0 Posted July 9, 2005 Ok after a rework of my script to pick up objects and move them around (half life 2 style) because of adivse against using nearest object and MP ive encounterd a strang little proplem with it. First of, heres the three scripts: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> PickupCheck.sqs object=_this select 0 man=_this select 1 #check ?man distance object <3:Pickup=man addaction ["pick up object?", "pickup.sqs"];goto "check2" ~1 goto "check" #check2 ?man distance object >3:man removeaction pickup;goto "check" ~1 goto "check2" <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Pickup.sqs Drop=man addaction ["Drop object?","drop.sqs"] man removeaction pickup dropit=0 #loop _x1 = getpos man select 0 _y1 = getpos man select 1 _dir1 = getdir man object setpos [_x1 + (2.50*sin(_dir1)), _y1 + (2.50*cos(_dir1))] object setdir (getdir man) ?dropit==1:exit goto "loop" <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">drop.sqs dropit=1 man removeaction drop pickup=man addaction ["Pick up object?","pickup.sqs"] exit Now this works fine when i put [this,player] exec "pickupcheck.sqs" in ONE barrel (or any other object for that matter) but when i try multiple objects i dont get any options to pick up barrels, intill i get to the last object i placed down in the editor where it seems all the actions stack up and are shown at the same time. (so if i placed down 5 barrels, i wouldnt get any action to pick any of them up intill i get to the last barrel i placed down, where i get 5 actions to pick up barrels) So what seems to be happening is that this script isint running seprately for each barrel,but is taking into ecount every barrel. Or somthing like that. So could any one give me a hand? i been staring at code for last few hours making my mission and i could really do with some one elses fresh prespective on this. Thanks in advance for your help guys and Keep in mind that this is for MP. Share this post Link to post Share on other sites
[aps]gnat 28 Posted July 10, 2005 I have looked too hard but it seems you have GLOBAL variables pickup and drop. Straight away I can tell you this will only work on one object at a time, I suspect to pickup and drop more than 1 object you need a pickup1 pickup2 drop1 drop2 etc etc (or use an Array) Share this post Link to post Share on other sites
crashdome 3 Posted July 10, 2005 You actually don't need to use pickup and drop as global variables. _this select 2 will return the action ID example: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">man removeaction (_this select 2) and even more so you don't need global variable "man" either just use "_this select 1" Â OR change all global variables to local variables by putting an underscore in front of them e.g. _man _object _drop _pickup ... etc... and most certainly you should put a short delay within your loops to prevent excessive cpu usage *EDIT* I meant to also say that your problem is with the "object" variable specifically, but after you fix it by adding an underscore to the front, others will surface until you fix all of em by doing the above suggestions Share this post Link to post Share on other sites
D.murphy man 0 Posted July 10, 2005 Ah i never knew you could get a return vaule of the action ID. Thanks for clearning that up for me, learn somthing new every day i supose Edit: Hmm well every thing in tryings not working i tried puting _object=_this select 1 and _man=_this select 0 in the pickup.sqs but now when i try to pick up the barrel somthing very strang happens and the player seems just to slide across the intire island at silly speeds.. then collapse and die. Share this post Link to post Share on other sites
crashdome 3 Posted July 10, 2005 You gotta save that script. That's funny looking at your code more closely now, I see that the current set up will not work for multiple objects. There is now way of keeping the global variables unique with this setup. I will post something in a moment, gimme a minute to write something. It may help you. Share this post Link to post Share on other sites
crashdome 3 Posted July 10, 2005 This code assumes you have 2 barrels, Each named barrel1 and barrel2 Init.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">PickUp_Objects = [barrel1,barrel2] {_x exec "pickupaction.sqs";} foreach PickUp_Objects GlobalDrop = true pickupaction.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> PRIVATE ["_object"] _object = _this select 0 _object addaction ["Pick me up","pickup.sqs"] pickup.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ? (!GlobalDrop) : exit private ["_object","_man","_ID"] _object = _this select 0 _man = _this select 1 _ID = _this select 2 _object removeaction _ID GlobalDrop = false _object addaction ["Drop Item","drop.sqs"] #loop _object setpos (getpos player) if (GlobalDrop) then {_object exec "pickupaction.sqs";goto "exit";} ~0.1 goto "loop" #exit exit drop.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">GlobalDrop = true _this select 0 removeaction _this select 2 _this select 0 exec "pickupaction.sqs" exit Try this. By adding the action to the object itself we can allow more than a single unit to pick it up AND we can keep the objects unique. The only drawback is that the distance the action will appear on the players menu might be further than 3... I'm not sure. It's a hard coded distance. Also, I did not put any fancy code to position the barrel, I'll leave that up to you! *EDIT* removed some code... didn't like it - changed some stuff around This should be MP compatible also Share this post Link to post Share on other sites
UNN 0 Posted July 10, 2005 Quote[/b] ]Hmm well every thing in tryings not working   i tried puting _object=_this select 1 and _man=_this select 0 in the pickup.sqs but now when i try to pick up the barrel somthing very strang happens and the player seems just to slide across the intire island at silly speeds.. then collapse and die. Your setpos'ing the barrel to close to your body. It creates a form of perpetual motion, by constantly pushing you out of the way. Im using the same thing to try and find a work round, for the walking on moving vehicles problem. Share this post Link to post Share on other sites
D.murphy man 0 Posted July 11, 2005 Cheers crash dome ill get to testing it out once my hangover subsides.. Should be helpful in blockading doors and streets from zombie hordes Edit: Hmm had an error: '_object=_this select 0' error select: type object, expected array Share this post Link to post Share on other sites
crashdome 3 Posted July 11, 2005 Oopss... typo wrap the "_x" in brackets in the init.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{[_x] exec ... Share this post Link to post Share on other sites
gandalf the white 0 Posted July 11, 2005 there's a gravity gun on this page It's pretty fun to use it online and play tennis with hummers, etc . Anyhow, you might want to see how that script works, as it doesn't moves the object to your position, but 10M in front of your weapon muzzle, above that, you dont get multiple messages Share this post Link to post Share on other sites
D.murphy man 0 Posted July 11, 2005 Well i got it all working nice and smoothly now, and got the barrels to 'float' 1 or 2 m infront of the player. But there seems to be the same error as before but only when i try and drop the object. The error shows up '_object=_this select 0' error select: type object, expected array and the barrels dont just have a "drop item" action on them instead of a "pick me up" action again. I tried looking at it my self and im not sure what to do to fix it Share this post Link to post Share on other sites
crashdome 3 Posted July 11, 2005 same problem... different area  Change:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (GlobalDrop) then {_object exec "pickupaction.sqs";goto "exit";} to <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (GlobalDrop) then {[_object] exec "pickupaction.sqs";goto "exit";} As far as no "Drop" item action... that has me baffled a bit. Test by commenting out the setpos commands (so it doesn't actually move) and see if the "Drop Item" command shows up. If it does, there might be an issue with addaction on objects that are 'floating'... *EDIT* test the fix above first - it might be related. I didn't quite grasp the drop action problem you mentioned and after rereading it, it might be because of above error. Share this post Link to post Share on other sites
D.murphy man 0 Posted July 11, 2005 Well i added the fix in you mentioned and it has fixed the proplem...sort of. Now when i 'drop' the object the 'pick me up' action shows (because it didnt before) but i still get an error message and the 'drop item' command dosent dissapear. So now once ive droped the barrel i have a 'drop item' and a 'pick me up' action both showing.And i notice that if i do choose to pick it up again, and drop it again, another 'drop item' action is added. So then when i go near the barrel theres 1 'pick me up' action and 2 'drop iteam' actions. lol hope that makes sense So ill take an educated guess that the line: _this select 0 removeaction _this select 2 in drop.sqs is the proplem. Share this post Link to post Share on other sites
crashdome 3 Posted July 11, 2005 OK.. since I have completely lost track of my typos ... do me a favor... Make sure ALL variables/statements that come before the word "exec" are in brackets. I think the drop.sqs has "_this select 0" not in brackets before the exec command.... Share this post Link to post Share on other sites
D.murphy man 0 Posted July 11, 2005 Heh ill have a quik look over of them now and fill in the brackets. Expect an edit of this post quite soon! Edit: Ok i only found one more typo and that was in the drop .sqs. So i fixed it and just gave it a test and now i get another error. _this select 0 removeaction _this select|#| 2 :Error removeaction Type array, expected number Not sure what thats about i didnt even know you could use _this select # on the arse end of a removeaction command. Edit 2: O0o just noticed iv become an advance memeber! woo 3 stars Share this post Link to post Share on other sites
crashdome 3 Posted July 11, 2005 OK... wrap that in "(...)" Man... have I really gotten that old? Share this post Link to post Share on other sites
D.murphy man 0 Posted July 11, 2005 He he yep, i was justing getting a double up of 'pick me up' actions every time i droped and noticed that you typed [_this bla..] exec "pickupaction.sqs" to activate when globaldrop is true and in the drop.sqs Any way it works like a charm now, thanks! should add my missions hold out against the zombies atmosphere a bit more Share this post Link to post Share on other sites
crashdome 3 Posted July 11, 2005 Glad I could help. Next time, I'll actually test my scripts for typos first Share this post Link to post Share on other sites