PDA

View Full Version : help regarding a system


TroubleFingers
27/03/2017, 12:40 PM
https://pastebin.com/SZREAUv4
Only the first crate works. The others don't return any messages. I've tried basically everything. Please help.

Unte99
27/03/2017, 12:49 PM
http://wiki.sa-mp.com/wiki/Update3DTextLabelText

Read the important note.

TroubleFingers
27/03/2017, 12:53 PM
http://wiki.sa-mp.com/wiki/Update3DTextLabelText

Read the important note.

Okay, it doesn't fix my script though.

Unte99
27/03/2017, 03:35 PM
1)


#define MAX_DROPPED_GPARTS 10
static GunParts[MAX_DROPPED_GPARTS][GunPart];


which is basically

static GunParts[10][GunPart];


now in the command:

for(new i = 0; i < sizeof(crateLocations); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 7.0, crateLocations[i][gPosx], crateLocations[i][gPosy], crateLocations[i][gPosz]))
{


you made a loop with sizeof(crateLocations), which is


static crateLocations[][GunPartsCoords] = {
{2834.8857, -2386.6113, 17.5051}, // 0
{2842.3608, -2500.4163, 17.5051}, // 1
{2823.5750, -2474.1826, 12.0983}, // 2
{2837.7878, -2449.3562, 19.9220}, // 3
{2846.3259, -2447.9080, 19.9220}, // 4
{2842.2053, -2500.4648, 17.5051} // 5
};


6, because crateLocations has 6 rows of coordinates you made for picking up parts.

So the loop will be repeated only 6 times, not 10 times as the GunParts[10] first dimension index is.

Fix this code so the loop checks all available coordinates for picking up the parts and also checks all available indexes of GunParts:


CMD:takegunpart(playerid, params[])
{
/*if(pInfo[playerid][pFamily] > 0)
{
if(pInfo[playerid][pRank] >= 5)
{*/
new pickedmsg[30];
for(new i = 0; i < sizeof(crateLocations); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 7.0, crateLocations[i][gPosx], crateLocations[i][gPosy], crateLocations[i][gPosz]))
{
if(if(GunParts[i][gDropped]==0)
{
format(pickedmsg, sizeof(pickedmsg), "Skipped because GunParts[%i][gDropped]==0",i); // I added this message for debugging purposes
SendClientMessage(playerid, -1, pickedmsg);
}
if(GunParts[i][gDropped] == 0) continue;
new gunpartamount = random (6);
//PlayerInfo[playerid][Gunparts] += gunpartamount;
format(pickedmsg, sizeof(pickedmsg), "You've picked %i gun parts.", gunpartamount);
SendClientMessage(playerid, -1, pickedmsg);
GunParts[i][gDropped] = 0;
return 1;
}

}
/*}
}*/
return 1;
}


2) Don't create variables in loops.

TroubleFingers
28/03/2017, 11:52 AM
1)


#define MAX_DROPPED_GPARTS 10
static GunParts[MAX_DROPPED_GPARTS][GunPart];


which is basically

static GunParts[10][GunPart];


now in the command:

for(new i = 0; i < sizeof(crateLocations); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 7.0, crateLocations[i][gPosx], crateLocations[i][gPosy], crateLocations[i][gPosz]))
{


you made a loop with sizeof(crateLocations), which is


static crateLocations[][GunPartsCoords] = {
{2834.8857, -2386.6113, 17.5051}, // 0
{2842.3608, -2500.4163, 17.5051}, // 1
{2823.5750, -2474.1826, 12.0983}, // 2
{2837.7878, -2449.3562, 19.9220}, // 3
{2846.3259, -2447.9080, 19.9220}, // 4
{2842.2053, -2500.4648, 17.5051} // 5
};


6, because crateLocations has 6 rows of coordinates you made for picking up parts.

So the loop will be repeated only 6 times, not 10 times as the GunParts[10] first dimension index is.

Fix this code so the loop checks all available coordinates for picking up the parts and also checks all available indexes of GunParts:


CMD:takegunpart(playerid, params[])
{
/*if(pInfo[playerid][pFamily] > 0)
{
if(pInfo[playerid][pRank] >= 5)
{*/
new pickedmsg[30];
for(new i = 0; i < sizeof(crateLocations); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 7.0, crateLocations[i][gPosx], crateLocations[i][gPosy], crateLocations[i][gPosz]))
{
if(if(GunParts[i][gDropped]==0)
{
format(pickedmsg, sizeof(pickedmsg), "Skipped because GunParts[%i][gDropped]==0",i); // I added this message for debugging purposes
SendClientMessage(playerid, -1, pickedmsg);
}
if(GunParts[i][gDropped] == 0) continue;
new gunpartamount = random (6);
//PlayerInfo[playerid][Gunparts] += gunpartamount;
format(pickedmsg, sizeof(pickedmsg), "You've picked %i gun parts.", gunpartamount);
SendClientMessage(playerid, -1, pickedmsg);
GunParts[i][gDropped] = 0;
return 1;
}

}
/*}
}*/
return 1;
}


2) Don't create variables in loops.

Still.

Unte99
28/03/2017, 11:57 AM
Show your current code and tell what you changed.

TroubleFingers
28/03/2017, 12:25 PM
#include <a_samp>
#include <zcmd>
#include <sscanf2>
// 0x00FF00FF - GREEN
//

main() {}

#define MAX_DROPPED_GPARTS 6
static Text3D: takegunpart3d1;
static Text3D: takegunpart3d2;
static Text3D: takegunpart3d3;
static Text3D: takegunpart3d4;
static Text3D: takegunpart3d5;
static Text3D: takegunpart3d6;


enum GunPart {
gID,
gType,
gDropped,
Float:gPos[3]
};

enum GunPartsCoords {
Float:gPosx,
Float:gPosy,
Float:gPosz
};

CMD:here(playerid, params[])
{
SetPlayerPos(playerid, 2834.8857, -2386.6113, 17.5051);
return 1;
}
static GunParts[6][GunPart];
static crateLocations[][GunPartsCoords] = {
{2834.8857, -2386.6113, 17.5051},
{2842.3608, -2500.4163, 17.5051},
{2823.5750, -2474.1826, 12.0983},
{2837.7878, -2449.3562, 19.9220},
{2846.3259, -2447.9080, 19.9220},
{2842.2053, -2500.4648, 17.5051}
};

forward ShipArrivalTimer();
forward ShipDockingTimer();

public OnGameModeInit()
{

takegunpart3d1 = Create3DTextLabel("/takegunpart", 0x00FF00FF, 2834.8857, -2386.6113, 17.5051, 20.0, 0, 1);
takegunpart3d2 = Create3DTextLabel("/takegunpart", 0x00FF00FF, 2842.3608, -2500.4163, 17.5051, 20.0, 0, 1);
takegunpart3d3 = Create3DTextLabel("/takegunpart", 0x00FF00FF, 2823.5750, -2474.1826, 12.0983, 20.0, 0, 1);
takegunpart3d4 = Create3DTextLabel("/takegunpart", 0x00FF00FF, 2837.9119, -2449.5093, 19.9220, 20.0, 0, 1);
takegunpart3d5 = Create3DTextLabel("/takegunpart", 0x00FF00FF, 2845.8704, -2447.4880, 19.9220, 20.0, 0, 1);
takegunpart3d6 = Create3DTextLabel("/takegunpart", 0x00FF00FF, 2834.8857, -2386.6113, 17.5051, 20.0, 0, 1);
Update3DTextLabelText(takegunpart3d1, 0x00FF00FF, "");
Update3DTextLabelText(takegunpart3d2, 0x00FF00FF, "");
Update3DTextLabelText(takegunpart3d3, 0x00FF00FF, "");
Update3DTextLabelText(takegunpart3d4, 0x00FF00FF, "");
Update3DTextLabelText(takegunpart3d5, 0x00FF00FF, "");
Update3DTextLabelText(takegunpart3d6, 0x00FF00FF, "");
SetTimer("ShipArrivalTimer", 10, false);

return 1;
}

public ShipArrivalTimer()
{
SetTimer("ShipDockingTimer", 1200000, false);
for(new i = 0; i < MAX_DROPPED_GPARTS; i++)
{
new shiphasillegal = random(2);
GunParts[i][gDropped] = shiphasillegal;
if(shiphasillegal == 0) return print("No");
if(shiphasillegal == 1) return print("Yes");

}

Update3DTextLabelText(takegunpart3d1, 0x00FF00FF, "/takegunpart");
Update3DTextLabelText(takegunpart3d2, 0x00FF00FF, "/takegunpart");
Update3DTextLabelText(takegunpart3d3, 0x00FF00FF, "/takegunpart");
Update3DTextLabelText(takegunpart3d4, 0x00FF00FF, "/takegunpart");
Update3DTextLabelText(takegunpart3d5, 0x00FF00FF, "/takegunpart");
Update3DTextLabelText(takegunpart3d6, 0x00FF00FF, "/takegunpart");
return 1;
}

public ShipDockingTimer()
{
SetTimer("ShipArrivalTimer", 10800000, false);
Update3DTextLabelText(takegunpart3d1, 0x00FF00FF, "");
Update3DTextLabelText(takegunpart3d2, 0x00FF00FF, "");
Update3DTextLabelText(takegunpart3d3, 0x00FF00FF, "");
Update3DTextLabelText(takegunpart3d4, 0x00FF00FF, "");
Update3DTextLabelText(takegunpart3d5, 0x00FF00FF, "");
Update3DTextLabelText(takegunpart3d6, 0x00FF00FF, "");
return 1;
}

CMD:takegunpart(playerid, params[])
{
// if(pInfo[playerid][pFamily] > 0)
//{
//if(pInfo[playerid][pRank] >= 5)
//{
new pickedmsg[30];
for(new i = 0; i < sizeof(crateLocations); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 7.0, crateLocations[i][gPosx], crateLocations[i][gPosy], crateLocations[i][gPosz]))
{
if(GunParts[i][gDropped] == 0) continue;
new gunpartamount = random (6);
//PlayerInfo[playerid][Gunparts] += gunpartamount;
format(pickedmsg, sizeof(pickedmsg), "You've picked %i gun parts.", gunpartamount);
SendClientMessage(playerid, -1, pickedmsg);
GunParts[i][gDropped] = 0;

}
return 1;
}

//}
//}
return 1;
}

Unte99
28/03/2017, 12:46 PM
So what exactly did you change?

TroubleFingers
28/03/2017, 01:00 PM
So what exactly did you change?

Everything you said

Unte99
28/03/2017, 01:07 PM
Everything you said

You didn't even use the command I pasted for you and told you what to do to fix it and you are saying that you changed everything when you didn't do shit. If you are just waiting for someone to paste the working code for you, you are in the wrong section. This is "Scripting Help", not "I paste the code and you fix it for me". Come back to this section when you have the minimum knowledge of sa-mp scripting. When you think you have the knowledge, try x2 times more of the time you spent acquiring the knowledge and then you can come here asking for help. You have no idea what the hell the current code does, what are you even doing here?

TroubleFingers
28/03/2017, 01:21 PM
You didn't even use the command I pasted for you and told you what to do to fix it and you are saying that you changed everything when you didn't do shit. If you are just waiting for someone to paste the working code for you, you are in the wrong section. This is "Scripting Help", not "I paste the code and you fix it for me". Come back to this section when you have the minimum knowledge of sa-mp scripting. When you think you have the knowledge, try x2 times more of the time you spent acquiring the knowledge and then you can come here asking for help. You have no idea what the hell the current code does, what are you even doing here?

Your script does exactly what my script does except for the debug message. It's exactly the same, only the first one works and the others don't. Don't tell me I don't know how to code and instantly rush me like that, I'm weak at the point of arrays as I haven't scripted for long and I don't remember much from that part so I asked for help - if you can't give it and tell me I know shit you can fuck off, honestly.

Unte99
28/03/2017, 01:48 PM
Still.

Your script does exactly what my script does except for the debug message. It's exactly the same, only the first one works and the others don't. Don't tell me I don't know how to code and instantly rush me like that, I'm weak at the point of arrays as I haven't scripted for long and I don't remember much from that part so I asked for help - if you can't give it and tell me I know shit you can fuck off, honestly.

You implied that this post:

http://forum.sa-mp.com/showpost.php?p=3860987&postcount=4

doesn't give any information about your problem and doesn't help with it at all. Even the debug message which supposed to help you understand the current problem and the fact that I said "Don't create variables inside loops" yet you still used the same god damn old code of yours and telling me "Still" (implying that the code will fix itself) and then saying "I changed everything you said" when you didn't even try doing anything. I told you about the GunParts index, that you were looping in the command only through 6 indexes and not 10 and yet you still haven't done anything about it. That's what I call impudent.

You can start here: http://forum.sa-mp.com/showthread.php?t=318212

You think you will get private lessons in "Scripting Help"?

TroubleFingers
28/03/2017, 03:13 PM
You implied that this post:

http://forum.sa-mp.com/showpost.php?p=3860987&postcount=4

doesn't give any information about your problem and doesn't help with it at all. Even the debug message which supposed to help you understand the current problem and the fact that I said "Don't create variables inside loops" yet you still used the same god damn old code of yours and telling me "Still" (implying that the code will fix itself) and then saying "I changed everything you said" when you didn't even try doing anything. I told you about the GunParts index, that you were looping in the command only through 6 indexes and not 10 and yet you still haven't done anything about it. That's what I call impudent.

You can start here: http://forum.sa-mp.com/showthread.php?t=318212

You think you will get private lessons in "Scripting Help"?

I pasted the wrong code, I did not just say I did (I'm sorry for the misunderstanding).
So yes, with your debug thingy it basically indeed detects the id of the part but it its gDropped == 0 although the first one works. So how do we solve this? Basically the loop on the timer when the ship arrive should set every part's gdropped to 1 if the ship has illegal (it's in the code, you can check it). So that means it only sets the first one's gdropped..? why?

TroubleFingers
29/03/2017, 11:55 AM
bump, please help