Array Question -
Kindred - 31.12.2011
((Notice: I am a beginning-scripter, i am not the slightest bit intelligent with array's and such))
Greetings.
I have a question about array's.
So, this is something i'm currently scripting.
pawn Код:
//Top of the script
new RADIO[2]
//Somewhere down below
CMD:createradio(playerid, params[])
{
if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdminLevel] >= 5)
{
new Float:X, Float:Y, Float:Z, Float:angle;
GetPlayerFacingAngle(playerid, angle);
GetPlayerPos(playerid, X,Y,Z);
RADIO[1] = CreateObject(2102, X, Y, Z, 0, 0, angle, 200);
}
return 1;
}
CMD:deleteradio(playerid, params[])
{
if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdminLevel] >= 5)
{
new Float:X, Float:Y, Float:Z;
GetObjectPos(RADIO[1], X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, 20.0, X, Y, Z))
{
DestroyObject(RADIO[1]);
}
}
return 1;
}
This script creates a radio at my position when i type /createradio, and deletes it when i type /deleteradio. Lets say, i had the array as RADIO[32]. ((Just to say, i can't explain very well)).
I want it so when i /createradio, it will spawn the radio at my position, and make it number 0 ((if it was the first time i did it)). Now, i want it so if i type it again, it will add it up once more, so if i did it once previously, it would make the RADIO array = 1, and so forth. Because i don't want to make several "If(IsPlayerInRangeOfPoint)" 's, and i would like to save line space. I also want it so when i type /deleteradio, it will check if i'm near one of the radio's i made, and delete that one only.
Sorry if ^^ that was to much to ask, i'm having trouble and i'm not the slightest bit very intelligent in scripting right now.
Thanks in advance, /KurtBag\
Re: Array Question -
-Prodigy- - 31.12.2011
Something like this:
pawn Код:
#define MAX_RADIOS 20
// Global
new
gRadio[MAX_RADIOS],
gTotalRadios;
CMD:createradio(playerid, params[])
{
if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdminLevel] >= 5)
{
if(gTotalRadios > MAX_RADIOS)
return SendClientMessage(playerid, -1, "Increase the # of radios. Current: "#MAX_RADIOS""); // We reached the max # of radios we can create
new
Float: iPos[4]; // To store the positions
GetPlayerPos(playerid, iPos[0], iPos[1], iPos[2]);
GetPlayerFacingAngle(playerid, iPos[3]);
gRadio[gTotalRadios] = CreateObject(2102, iPos[0], iPos[1], iPos[2], 0, 0, iPos[3], 200);
gTotalRadios ++; // Increase the # of radios, that way they don't "overwrite"
}
return 1;
}
CMD:deleteradio(playerid, params[])
{
if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdminLevel] >= 5)
{
for(new i = 0; i < sizeof(gTotalRadios); i++) // Make a loop through all radios created
{
new
Float: iPos[3]; // Store all radio's position
GetObjectPos(i, iPos[0], iPos[1], iPos[2]); // Get all radio's position
if(IsPlayerInRangeOfPoint(playerid, 20.0, iPos[0], iPos[1], iPos[2]))
{
DestroyObject(gRadio[i]); // Destroy nearby radios
gTotalRadios --; // Decrease # of radios
}
}
}
return 1;
}
?
Re: Array Question -
Kindred - 31.12.2011
The creating works perfectly, but the deleting doesn't.
I'd like to say: Thanks for the fast response.
Also, i understand what your doing here
EDIT: Plus, after you reach the maximum Radio's, it just says "Unknown Command" instead of returning any sendclientmessage
EDIT2: If you are in range of the radio, it still does not recognize you being inside the range (I added a else { sendclientmessage so i can see if it succeeds through the other one or not)
Re: Array Question -
-Prodigy- - 31.12.2011
Ah, forgot something
Try this:
pawn Код:
#define MAX_RADIOS 20
// Global
new
gRadio[MAX_RADIOS],
gTotalRadios;
CMD:createradio(playerid, params[])
{
if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdminLevel] >= 5)
{
if(gTotalRadios >= MAX_RADIOS)
return SendClientMessage(playerid, -1, "Increase the # of radios. Current: "#MAX_RADIOS""); // We reached the max # of radios we can create
new
Float: iPos[4]; // To store the positions
GetPlayerPos(playerid, iPos[0], iPos[1], iPos[2]);
GetPlayerFacingAngle(playerid, iPos[3]);
gRadio[gTotalRadios] = CreateObject(2102, iPos[0], iPos[1], iPos[2], 0, 0, iPos[3], 200);
gTotalRadios ++; // Increase the # of radios, that way they don't "overwrite"
}
return 1;
}
CMD:deleteradio(playerid, params[])
{
if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdminLevel] >= 5)
{
for(new i = 0; i < sizeof(gTotalRadios); i++) // Make a loop through all radios created
{
new
Float: iPos[3]; // Store all radio's position
GetObjectPos(gRadio[i], iPos[0], iPos[1], iPos[2]); // Get all radio's position
if(IsPlayerInRangeOfPoint(playerid, 20.0, iPos[0], iPos[1], iPos[2]))
{
DestroyObject(gRadio[i]); // Destroy nearby radios
gTotalRadios --; // Decrease # of radios
}
}
}
return 1;
}
Re: Array Question -
Kindred - 31.12.2011
I appreciate the effort, but now theres still something wrong. Not sure if its just me.
When i type /createobject, it works, i do it a few more times, then, when i walk up to the last one i made, or any of the previous ones, it doesn't work, unless it was the first one? When i delete the first one, and try to delete the others, it still won't work.
Thanks in advance,
KurtBag.
Re: Array Question -
Kindred - 01.01.2012
Still looking for help, if possible, Thank you
Re: Array Question -
Kindred - 04.01.2012
Still looking for any help possible