Its me Silverton from yoyoforums, I am taking my problem here cause so far, nobody there as been able to help me.
Here is my code:
global.selected=id;
option1=0
option2=0
option3=0
option4=0
if global.lastselected.id.attacks=0 { show_message("No Attacks Left!") }
if global.lastselected!=0
if global.lastselected.id.attacks>0
{
option = show_message_ext("Do you wish to attack this ship?","Attack!","Cancel","");
if (option = 2) exit
if (option = 1)
global.lastselected.id.attacks-=1;
{ if global.shipattacking=1 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 80 { show_message("Attack was successful"); global.selected.id.hp-=30 }}} // 1 = Prometheus Attacking
{ if global.shipattacking=2 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 option2 = show_message_ext("How will you attack?","Earth","Asgard",""); if (option2 = 1) { if irandom_range(0,100) < 80 { show_message("Attack was successful"); global.selected.id.hp-=40 }} if (option2 = 2) { if irandom_range(0,100) < 60 { show_message("Attack was successful"); global.selected.id.hp-=40 }}} // 2 = Daedalus Attacking
{ if global.shipattacking=3 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 option3 = show_message_ext("How will you attack?","Earth","Asgard",""); if (option3 = 1){ if irandom_range(0,100) < 80 { show_message("Attack was successful"); global.selected.id.hp-=50 }} if (option2 = 2) { if irandom_range(0,100) < 70 { show_message("Attack was successful"); global.selected.id.hp-=70 }}} // 3 = Odyssey Attacking
{ if global.shipattacking=4 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 60 { show_message("Attack was successful") global.selected.id.hp-=70 }}} // 4 = Hive Ship Attacking
{ if global.shipattacking=5 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 60 { show_message("Attack was successful") global.selected.id.hp-=80 }}} // 5 = O'Neil Attacking
{ if global.shipattacking=6 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 60 { show_message("Attack was successful") global.selected.id.hp-=60 }}} // 6 = Jackson Attacking
{ if global.shipattacking=7 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 70 { show_message("Attack was successful") global.selected.id.hp-=70 }}} // 7 = Hammond Attacking
{ if global.shipattacking=8 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 50 { show_message("Attack was successful") global.selected.id.hp-=130 }}} // 8 = Ori Attacking
{ if global.shipattacking=9 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 60 { show_message("Attack was successful") global.selected.id.hp-=30 }}} // 9 = Gou'ld Attacking
{ if global.shipattacking=10 if(distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 60 { show_message("Attack was successful") global.selected.id.hp-=70 }}} // 10 = Boss Attacking
{ if global.shipattacking=11 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 if global.lastselected.id.drones>0 { if irandom_range(0,100) < 100 { show_message("Attack was successful") global.selected.id.hp-=200 }}} // 11 = Ancient War Ship Attacking
{ if global.shipattacking=12 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 if global.lastselected.id.drones>0 { if irandom_range(0,100) < 100 { show_message("Attack was successful") global.selected.id.hp-=200 }}} // 12 = Ancient Cruiser Attacking
{ if global.shipattacking=13 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 60 { show_message("Attack was successful") global.selected.id.hp-=70 }}} // 13 = Destiny Attacking
{ if global.shipattacking=14 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 100 { show_message("Attack was successful") global.selected.id.hp-=200 }}} // 14 = Atlantis Attacking
{ if global.shipattacking=15 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 if global.lastselected.id.drones>0 option4 = show_message_ext("How will you attack?","Drill","Drones",""); if (option4 = 1) global.lastselected.id.hp-=global.selected.id.hp global.lastselected.id.hp-=100 if (option4 = 2) { if irandom_range(0,100) < 100 { show_message("Attack was successful"); global.selected.id.hp-=200 }}} // 15 = TowerShip Attacking
{ if global.shipattacking=16 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 60 { show_message("Attack was successful") global.selected.id.hp-=70 }}} // 16 = Wraith Super Hive Attacking
{ if global.shipattacking=17 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 { if irandom_range(0,100) < 80 { show_message("Attack was successful") global.selected.id.hp-=400 }}} // 17 = SAD Attacking
{ if global.shipattacking=18 if (distance_to_object(global.selected.id)<600) if global.lastselected.id.attacks>0 if global.lastselected.id.drones>0 { if irandom_range(0,100) < 100 { show_message("Attack was successful") global.selected.id.hp-=200 }}} // 17 = Homeworld Attacking
}
As you can see, this is a lot!For starters, what this code is SUPPOSED TO DO, is attack a ship. In my game, you select a ship you want to use to attack. global.lastselected= the ship you click on for attacking. In this turn based game, there are lots of the same ship objects, and lots of the same enemy ship objects, and lots of different ships.
In this code, the ship that is being attacked = global.selected.
global.shipattacking is the way I am using for identifying the type of ship that is attacking. As you can see by looking at this code, different ships do different damage.
A couple of ships, have different types of attacks which you can choose from.
CODE PROBLEMS: Ok, when i go into my test room, buy a attack ship and attack the enemy ship that has this code several things happen.
1# The message "Do you wish to attack" Does pop up, I hit yes, but the "attack was hit" message doesn't pop up. I know I have a random chance code here, but no mater how many times I hit it, number 2 happens.
2# The ship attacking loses EXACTLY 100 hp.
Please help! I have been over the code again and again and I can't find anything wrong! Thank you!
-Silverton











