Help with an array. [message #390692] |
Mon, 15 June 2009 09:32 |
|
Xpert
Messages: 1588 Registered: December 2005 Location: New York City
Karma: 0
|
General (1 Star) |
|
|
Okay, so basically, I'm trying to get an array going to count the players that damage a certain vehicle(s). I was getting help from someone with this and so far no luck. Maybe someone can find what we're doing wrong?
int damageObject[127];
void reb_vehicle::Created(GameObject *obj) {
vehstartmaxhealth = Commands->Get_Max_Health(obj);
vehstartmaxarmor = Commands->Get_Max_Shield_Strength(obj);
Commands->Start_Timer(obj, this, 1.5f, 1);
this->isUpgraded = false;
for (int i=0; i < 128; i++)
{
damageObject[i] = 0;
}
}
void reb_vehicle::Damaged(GameObject *obj, GameObject *damager, float damage) {
if (damage < 0) {
if (Commands->Is_A_Star(damager) && Commands->Get_Player_Type(damager) == Commands->Get_Player_Type(obj)) {
RepUpdate(Get_Player_ID(damager), (int)((damage - damage) - damage)/2);
}
}
int objId = Get_Player_ID(damager);
damageObject[objId] = objId;
}
void reb_vehicle::Killed(GameObject *obj, GameObject *shooter) {
if (Commands->Is_A_Star(shooter) && Commands->Get_Player_Type(shooter) != Commands->Get_Player_Type(obj)) {
for (int i=0; i < 1;i++)
{
GameObject *mainobj = Get_GameObj(damageObject[i]);
VetUpdate(damageObject[i], (int)GetPoints(Commands->Get_Preset_Name(obj)), (int)Commands->Get_Points(mainobj));
Display_Int_Player(mainobj,GetPoints(Commands->Get_Preset_Name(obj)),"Veteran points gained: %d "),GetPoints(Commands->Get_Preset_Name(obj));
}
}
}
It crashes when the damaged vehicle gets killed/destroyed.
And the structure for VetUpdate is
VetUpdate(int ID, int number, int score)
Creator of NetGuard, an IRC network regulator.
Developer of the CloudyServ 0.982-X project.
Developer of the CloudyServ Ren-X bot.
Part time streamer - https://twitch.tv/gg_wonder
|
|
|
|
Re: Help with an array. [message #390697 is a reply to message #390692] |
Mon, 15 June 2009 10:03 |
|
jnz
Messages: 3396 Registered: July 2006 Location: 30th century
Karma: 0
|
General (3 Stars) |
|
|
2 things I can see here:
First, you need to declare 'damageObject' inside of the script if you want the object that the script is attached to to track player attacking it.
Also:
GameObject *mainobj = Get_GameObj(damageObject[i]);
VetUpdate(damageObject[i], (int)GetPoints(Commands->Get_Preset_Name(obj)), (int)Commands->Get_Points(mainobj));
You need to check mainobj before you use it. If Get_GameObj returns 0, it will crash.
EDIT: third, VetUpdate parameter 1 isn't a GameObj *, it is an int. Probably player ID. Use VetUpdate(Get_PlayerID(damageObject[i]), ...
[Updated on: Mon, 15 June 2009 10:05] Report message to a moderator
|
|
|
Re: Help with an array. [message #390703 is a reply to message #390692] |
Mon, 15 June 2009 10:44 |
|
reborn
Messages: 3231 Registered: September 2004 Location: uk - london
Karma: 0
|
General (3 Stars) |
|
|
Who was helping you with this? Also, grab me on MSN if you have not got this sorted, I think i can help.
|
|
|
Re: Help with an array. [message #390710 is a reply to message #390692] |
Mon, 15 June 2009 13:06 |
raven
Messages: 595 Registered: January 2007 Location: Toronto, Ontario
Karma: 0
|
Colonel |
|
|
After yelling at Xpert a lot, I managed to help him fix it properly Thanks jnz.. that helped
-Jelly Administrator
-Exodus Administrator
|
|
|
|