Scripters may find this usefull

Willy

Administrator
Elder
Joined
Jul 27, 2011
Messages
130
This could be VERY helpful at times when scripting for B&W 2.
In this topic I will teach you how to find a certain point around an object.
I am not talking about going into the landscape editor and getting a point at the object.
What I am talking about is being able to find the front of an object AFTER the player places it anywhere at any angle in the game.
(This will take grade 11 math) 
Lets picture a person trying to remake a hurricane script, and in their video they need to bring the camera to view the hurricane from the front of the wonder.

Step 1: Get the X pos and Z pos and the angle of the wonder

Xposhepic= SCRIPT_OBJECT_PROPERTY_TYPE_XPOS of hEpic
Zposhepic= SCRIPT_OBJECT_PROPERTY_TYPE_ZPOS of hEpic
Anglehepic = SCRIPT_OBJECT_PROPERTY_TYPE_ANGLE of hEpic

Step 2: What distance? This is up to you pick whatever distance you want the camera form the wonder

distancehepic = 15/57.294
NOTE: Whenever doing this ALWAYS divide the distance by 57.294, Why? B&W 2's calculation will always be off by 57.294 so to fix that you just divide the distance.

Step 3: What angle do you want? Whatever angle you what just subtract or add to the angle

Anglehepic -= 95
NOTE: You will need to monkey around with this. Keep trying to add or subract different numbers until you get the angle you want

Step 4: Find the point you want. use this formula.

hEpicpoint= marker at {Xposhepic+distancehepic *cos Anglehepic , 0, Zposhepic+distancehepic *sin Anglehepic}
NOTE: For the Y pos you can pick any number you want. it only make the point higher or lower

Step 5: Only use this step when testing your angle. Use a visual effect to find the point you calculated.

visual1 = create visual effect VISUAL_EFFECT_EARTHQUAKE_BEAM at {hEpicpoint} time -1

NOTE!: When using these calculations make sure ALL variables are global variables
____________________________________________________________________________________________________________

This can be used for ANY object. You can also find multiple points around an object.
Here is an example of a script that will find 12 point around a gate AFTER the player builds it:

NOTE: For gates, when you get the X and Z axis you will get a point that is not the real center of the gate you can see the calculations I made to find the real center in blue. I have also included the visual effect I used to test the points

begin script FindGates21
visual1 = 0
start
begin loop
Gates[0] = get SCRIPT_OBJECT_TYPE_ABODE ABODE_NUMBER_GATEHOUSE at {913.38, 698.25} radius 173
if Gates[0] exists
if SCRIPT_OBJECT_PROPERTY_TYPE_BUILT_PERCENTAGE of Gates[0] >= 0.99
Greekgatebuilt = 1
else
Greekgatebuilt = 0
end if
end if
until Greekgatebuilt == 1
end loop
if Greekgatebuilt == 1
GateposX = SCRIPT_OBJECT_PROPERTY_TYPE_XPOS of Gates[0]
GateposZ = SCRIPT_OBJECT_PROPERTY_TYPE_ZPOS of Gates[0]
Gatesangle2 = SCRIPT_OBJECT_PROPERTY_TYPE_ANGLE of Gates[0]
distance1 = 13/57.294
GatesAngle[0] = Gatesangle2 + 0
Gatespot = marker at {GateposX+distance1*cos GatesAngle[0], 0, GateposZ+distance1*sin GatesAngle[0]}

GateposX = SCRIPT_OBJECT_PROPERTY_TYPE_XPOS of Gatespot
GateposZ = SCRIPT_OBJECT_PROPERTY_TYPE_ZPOS of Gatespot
visual1 = create visual effect VISUAL_EFFECT_EARTHQUAKE_BEAM at {Gatespot} time -1
ff = 0
ss = 0
begin loop
ff += 15
GatesAngle[ss] = Gatesangle2 - ff
ss++
until ss == 11
end loop
distance1 = 30/57.294
ss = 0
begin loop
Attspot[ss] = marker at {GateposX+distance1*cos GatesAngle[ss], 0, GateposZ+distance1*sin GatesAngle[ss]}
visual2[ss] = create visual effect VISUAL_EFFECT_EPIC_VOLCANO_BEAM at {Attspot[ss]} time -1
ss++
wait 2 seconds
until ss == 11
end loop
end if
end script FindGates21

NOTE: I was going to put in a picture but I can't because the size of the picture is too large :(
 
Willy said:
NOTE: I was going to put in a picture but I can't because the size of the picture is too large :(

Try saving it as a .gif, that should shave off a few KB.

 
Saving as a .gif file didn't not work so instead I uploaded them here:
http://giveme42.imgur.com/all/
 
Back
Top