by Silentdarkness12 » Sun Nov 17, 2019 2:57 pm
I've been working on a minimod for Hideous Destructor to add a sort of gear crate that you can lug around to help carry all the stuff around between levels you could ever need, and even stuff you don't need. However, i'm now running into a problem that is significantly well above and beyond what I can make sense of, and especially baffling since i'm heavily copying the backpack code for this, and yet i'm running into a problem here I don't run into with the HD backpack.
Code: Select all
let wep=(class<hdweapon>)(invclasses[thisitem]);
Somehow, these bits of codes are colliding and making an array access out of bounds, whatever that is. I seriously got nothing here, and I need help figuring this one out. Entire blocks of relevant code included below for the sake of being more reasonable.
HDGearcrate.wad
Code: Select all
extend class HDGearCrate{
void RandomContents(){
if(hd_debug)A_Log("\n* Backpack: *");
for(int i=0;i<5;i++){
int thisitem=random(1,invclasses.size())-1;
let wep=(class<hdweapon>)(invclasses[thisitem]);
let pkup=(class<hdpickup>)(invclasses[thisitem]);
let mag=(class<hdmagammo>)(pkup);
int howmany=0;
if(wep){
let iii=inventory(spawn(wep,pos,ALLOW_REPLACE));
if(hdweapongiver(iii))itemtobackpack(hdweapongiver(iii).actualweapon);
else if(hdpickupgiver(iii))itemtobackpack(hdpickupgiver(iii).actualitem);
else itemtobackpack(iii);
}else if(mag){
howmany=min(
random(1,random(1,20)),
getdefaultbytype(mag).maxamount,
HDCONST_BPMAX/(
max(1.,getdefaultbytype(mag).roundbulk)
*max(1.,getdefaultbytype(mag).magbulk)
*5.
)
);
for(int j=0;j<howmany;j++){
inventory iii=inventory(spawn(mag,pos,ALLOW_REPLACE));
if(iii){
itemtobackpack(iii);
if(iii)iii.destroy();
}
}
}else if(pkup){
let iii=spawn(pkup,pos,ALLOW_REPLACE);
if(iii){
iii.destroy();
howmany=min(
random(1,getdefaultbytype(pkup).bmultipickup?random(1,80):random(1,random(1,20))),
getdefaultbytype(pkup).maxamount,
HDCONST_BPMAX/(max(1.,getdefaultbytype(pkup).bulk)*5.)
);
if(
getdefaultbytype(pkup).refid==""
){
howmany=random(-2,howmany);
}
amounts[thisitem]=""..howmany;
if(amounts[thisitem].toint()<1)amounts[thisitem]="";
}
}
if(hd_debug)A_Log(invclasses[thisitem].." "..howmany);
}
weaponbulk();
updatemessage(index);
}
}
Code: Select all
class WildGearCrate:IdleDummy {
//$Category "Items/Hideous Destructor/Gear"
//$Title "Backpack (Random Spawn)"
//$Sprite "GRCRA0"
override void postbeginplay(){
super.postbeginplay();
let aaa=HDBackpack(spawn("HDGearCrate",pos,ALLOW_REPLACE));
aaa.RandomContents();
destroy();
}
}
Hideous_Destructor_Master
Code: Select all
extend class HDBackpack{
void RandomContents(){
if(hd_debug)A_Log("\n* Backpack: *");
for(int i=0;i<5;i++){
int thisitem=random(1,invclasses.size())-1;
let wep=(class<hdweapon>)(invclasses[thisitem]);
let pkup=(class<hdpickup>)(invclasses[thisitem]);
let mag=(class<hdmagammo>)(pkup);
int howmany=0;
if(wep){
let iii=inventory(spawn(wep,pos,ALLOW_REPLACE));
if(hdweapongiver(iii))itemtobackpack(hdweapongiver(iii).actualweapon);
else if(hdpickupgiver(iii))itemtobackpack(hdpickupgiver(iii).actualitem);
else itemtobackpack(iii);
}else if(mag){
howmany=min(
random(1,random(1,20)),
getdefaultbytype(mag).maxamount,
HDCONST_BPMAX/(
max(1.,getdefaultbytype(mag).roundbulk)
*max(1.,getdefaultbytype(mag).magbulk)
*5.
)
);
for(int j=0;j<howmany;j++){
inventory iii=inventory(spawn(mag,pos,ALLOW_REPLACE));
if(iii){
itemtobackpack(iii);
if(iii)iii.destroy();
}
}
}else if(pkup){
let iii=spawn(pkup,pos,ALLOW_REPLACE);
if(iii){
iii.destroy();
howmany=min(
random(1,getdefaultbytype(pkup).bmultipickup?random(1,80):random(1,random(1,20))),
getdefaultbytype(pkup).maxamount,
HDCONST_BPMAX/(max(1.,getdefaultbytype(pkup).bulk)*5.)
);
if(
getdefaultbytype(pkup).refid==""
){
howmany=random(-2,howmany);
}
amounts[thisitem]=""..howmany;
if(amounts[thisitem].toint()<1)amounts[thisitem]="";
}
}
if(hd_debug)A_Log(invclasses[thisitem].." "..howmany);
}
weaponbulk();
updatemessage(index);
}
I understand it's something to do with arrays, but I have not even the slightest bit of a clue what i'm doing wrong here. Help would be appreciated.
I've been working on a minimod for Hideous Destructor to add a sort of gear crate that you can lug around to help carry all the stuff around between levels you could ever need, and even stuff you don't need. However, i'm now running into a problem that is significantly well above and beyond what I can make sense of, and especially baffling since i'm heavily copying the backpack code for this, and yet i'm running into a problem here I don't run into with the HD backpack.
[imgur]https://imgur.com/shPMOKJ[/imgur]
[code]aaa.RandomContents();[/code]
[code]let wep=(class<hdweapon>)(invclasses[thisitem]);[/code]
Somehow, these bits of codes are colliding and making an array access out of bounds, whatever that is. I seriously got nothing here, and I need help figuring this one out. Entire blocks of relevant code included below for the sake of being more reasonable.
HDGearcrate.wad
[code]extend class HDGearCrate{
void RandomContents(){
if(hd_debug)A_Log("\n* Backpack: *");
for(int i=0;i<5;i++){
int thisitem=random(1,invclasses.size())-1;
let wep=(class<hdweapon>)(invclasses[thisitem]);
let pkup=(class<hdpickup>)(invclasses[thisitem]);
let mag=(class<hdmagammo>)(pkup);
int howmany=0;
if(wep){
let iii=inventory(spawn(wep,pos,ALLOW_REPLACE));
if(hdweapongiver(iii))itemtobackpack(hdweapongiver(iii).actualweapon);
else if(hdpickupgiver(iii))itemtobackpack(hdpickupgiver(iii).actualitem);
else itemtobackpack(iii);
}else if(mag){
howmany=min(
random(1,random(1,20)),
getdefaultbytype(mag).maxamount,
HDCONST_BPMAX/(
max(1.,getdefaultbytype(mag).roundbulk)
*max(1.,getdefaultbytype(mag).magbulk)
*5.
)
);
for(int j=0;j<howmany;j++){
inventory iii=inventory(spawn(mag,pos,ALLOW_REPLACE));
if(iii){
itemtobackpack(iii);
if(iii)iii.destroy();
}
}
}else if(pkup){
let iii=spawn(pkup,pos,ALLOW_REPLACE);
if(iii){
iii.destroy();
howmany=min(
random(1,getdefaultbytype(pkup).bmultipickup?random(1,80):random(1,random(1,20))),
getdefaultbytype(pkup).maxamount,
HDCONST_BPMAX/(max(1.,getdefaultbytype(pkup).bulk)*5.)
);
if(
getdefaultbytype(pkup).refid==""
){
howmany=random(-2,howmany);
}
amounts[thisitem]=""..howmany;
if(amounts[thisitem].toint()<1)amounts[thisitem]="";
}
}
if(hd_debug)A_Log(invclasses[thisitem].." "..howmany);
}
weaponbulk();
updatemessage(index);
}
}[/code]
[code]class WildGearCrate:IdleDummy {
//$Category "Items/Hideous Destructor/Gear"
//$Title "Backpack (Random Spawn)"
//$Sprite "GRCRA0"
override void postbeginplay(){
super.postbeginplay();
let aaa=HDBackpack(spawn("HDGearCrate",pos,ALLOW_REPLACE));
aaa.RandomContents();
destroy();
}
}[/code]
Hideous_Destructor_Master
[code]extend class HDBackpack{
void RandomContents(){
if(hd_debug)A_Log("\n* Backpack: *");
for(int i=0;i<5;i++){
int thisitem=random(1,invclasses.size())-1;
let wep=(class<hdweapon>)(invclasses[thisitem]);
let pkup=(class<hdpickup>)(invclasses[thisitem]);
let mag=(class<hdmagammo>)(pkup);
int howmany=0;
if(wep){
let iii=inventory(spawn(wep,pos,ALLOW_REPLACE));
if(hdweapongiver(iii))itemtobackpack(hdweapongiver(iii).actualweapon);
else if(hdpickupgiver(iii))itemtobackpack(hdpickupgiver(iii).actualitem);
else itemtobackpack(iii);
}else if(mag){
howmany=min(
random(1,random(1,20)),
getdefaultbytype(mag).maxamount,
HDCONST_BPMAX/(
max(1.,getdefaultbytype(mag).roundbulk)
*max(1.,getdefaultbytype(mag).magbulk)
*5.
)
);
for(int j=0;j<howmany;j++){
inventory iii=inventory(spawn(mag,pos,ALLOW_REPLACE));
if(iii){
itemtobackpack(iii);
if(iii)iii.destroy();
}
}
}else if(pkup){
let iii=spawn(pkup,pos,ALLOW_REPLACE);
if(iii){
iii.destroy();
howmany=min(
random(1,getdefaultbytype(pkup).bmultipickup?random(1,80):random(1,random(1,20))),
getdefaultbytype(pkup).maxamount,
HDCONST_BPMAX/(max(1.,getdefaultbytype(pkup).bulk)*5.)
);
if(
getdefaultbytype(pkup).refid==""
){
howmany=random(-2,howmany);
}
amounts[thisitem]=""..howmany;
if(amounts[thisitem].toint()<1)amounts[thisitem]="";
}
}
if(hd_debug)A_Log(invclasses[thisitem].." "..howmany);
}
weaponbulk();
updatemessage(index);
}[/code]
I understand it's something to do with arrays, but I have not even the slightest bit of a clue what i'm doing wrong here. Help would be appreciated.