Gun "droping" system problems
#1

Код:
new Shotgundrop[MAX_PLAYERS];
new Float: shotgunx, Float: shotgunz, Float: shotguny;

CMD:dropgun(playerid, params[])
{

GetPlayerPos(playerid, shotgunx, shotguny,shotgunz);
Shotgundrop[playerid] = CreateDynamicObject(2034,shotgunx, shotguny,shotgunz-0.9, 0, 0, 0.00);

return 1;
}

CMD:pick(playerid, params[])
{

if(IsValidDynamicObject(Shotgundrop[playerid]) && IsPlayerInRangeOfPoint(playerid,2.0,shotgunx, shotguny,shotgunz))
{
DestroyDynamicObject(Shotgundrop[playerid]);
}

return 1;
}
this system has 2 problem...
1 st problem : If I use dropgun cmd and then other player use it, my coordinates wouldn't be effective anymore, because, second player changed it... How do I save object coordinates into different variable for each player?

2 st problem : If I try cmd pick on other player object it would check If my object exist, not that player, right? (not tested it yet) If so, how do I fix that?
Reply
#2

pawn Код:
enum GunData
{
    Object,         //Stores the object ID of the weapon
    Float:GunX,     //Stores the X coordinate of the weapon
    Float:GunY,     //Stores the Y coordinate of the weapon
    Float:GunZ      //Stores the Z coordinate of the weapon
};
new Shotgundrop[MAX_PLAYERS][GunData];  //Used to access the 'GunData' array with respect to 'playerid'.

CMD:dropgun(playerid, params[])
{
    if(IsValidDynamicObject(Shotgundrop[playerid][Object])) return SendClientMessage(playerid, -1, "You have already dropped a gun.");  //If they have already used /dropgun
    GetPlayerPos(playerid, Shotgundrop[playerid][GunX], Shotgundrop[playerid][GunY],Shotgundrop[playerid][GunZ]);
    Shotgundrop[playerid][Object] = CreateDynamicObject(2034, Shotgundrop[playerid][GunX], Shotgundrop[playerid][GunY],Shotgundrop[playerid][GunZ] - 0.9, 0, 0, 0.00);
    return 1;
}

CMD:pick(playerid, params[])
{
    for(new i = 0; i < MAX_PLAYERS; i++) //Foreach is a better alternative
    {
        if(!IsPlayerConnected(i)) continue; //Remove if using Foreach.
        if(!IsValidDynamicObject(Shotgundrop[i][Object])) continue;
        if(!IsPlayerInRangeOfPoint(playerid, 2.0, Shotgundrop[i][GunX], Shotgundrop[i][GunY], Shotgundrop[i][GunZ])) continue;
        DestroyDynamicObject(Shotgundrop[i][Object]);
        Shotgundrop[i][Object] = -1;
        return 1;
    }
    SendClientMessage(playerid, -1, "There are no guns nearby."); //If there are no guns within 2.0 units of the player
    return 1;
}
References:
https://sampwiki.blast.hk/wiki/Scripting_Basics#Arrays
https://sampwiki.blast.hk/wiki/Keywords:Statements#for
Reply
#3

Код:
(1817) : warning 213: tag mismatch
(1821) : warning 215: expression has no effect
(1821) : error 001: expected token: ";", but found "["
(1821) : error 029: invalid expression, assumed zero
(1821) : warning 215: expression has no effect
(1821) : error 001: expected token: ";", but found "]"
(1821) : fatal error 107: too many error messages on one line
1821 Line:

Код:
GunLabel[playerid][Object] = CreateDynamic3DTextLabel("Gun", -1 ,GunLabel[playerid][Labx], GunLabel[playerid][Laby],GunLabel[playerid][Labz]-0.9, 2.5);}
Reply
#4

Okay, that wasn't in my code... but change:
pawn Код:
enum GunData
{
    Object,
    //...
to:
pawn Код:
enum GunData
{
    Text3D:Object,
    //...
EDIT: And is that closing brace "}" meant to be at the end of that line?
Reply
#5

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Okay, that wasn't in my code... but change:
pawn Код:
enum GunData
{
    Object,
    //...
to:
pawn Код:
enum GunData
{
    Text3D:Object,
    //...
EDIT: And is that closing brace "}" meant to be at the end of that line?
Yes it wasn't, I tried to add some stuff to system. "}" meant to be there, and it still gives me these errors even after I add "Text3D"

Guess it will be better If I give you full code

Код:
enum GunData{
Gun,
Text3D: Object,
Float:Labx,
Float:Laby,
Float:Labz
};
new GunDrop[MAX_PLAYERS][GunData], GunLabel[MAX_PLAYERS][GunData];

GetPlayerPos(playerid, GunLabel[playerid][Labx], GunLabel[playerid][Laby],GunLabel[playerid][Labz]);
GunDrop[playerid][Gun] = CreateDynamicObject(356, GunLabel[playerid][Labx], GunLabel[playerid][Laby],GunLabel[playerid][Labz]-0.9, 0, 0, 0.00);
GunLabel[playerid][Object] = CreateDynamic3DTextLabel("Gun", -1 ,GunLabel[playerid][Labx], GunLabel[playerid][Laby],GunLabel[playerid][Labz]-0.9, 2.5);
Reply
#6

This works for me:
pawn Код:
enum GunData{
Gun,
Text3D:Object,
Float:Labx,
Float:Laby,
Float:Labz
};
new GunDrop[MAX_PLAYERS][GunData];

GetPlayerPos(playerid, GunDrop[playerid][Labx], GunDrop[playerid][Laby], GunDrop[playerid][Labz]);
GunDrop[playerid][Gun] = CreateDynamicObject(356, GunDrop[playerid][Labx], GunDrop[playerid][Laby], GunDrop[playerid][Labz] - 0.9, 0, 0, 0.00);
GunDrop[playerid][Object] = CreateDynamic3DTextLabel("Gun", -1, GunDrop[playerid][Labx], GunDrop[playerid][Laby], GunDrop[playerid][Labz] - 0.9, 2.5);
Reply
#7

Ok, I fixed it all. Thank you for the help mate.
Reply
#8

Bruh your system doesnt work too. Player still can't take other player "droped" gun
Reply
#9

Bump
Reply
#10

Well, there's nothing wrong with my code. You must have changed something.

EDIT:
pawn Код:
CMD:pick(playerid, params[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(IsValidDynamicObject(Gundrop[i][GunObject]))
        {
            if(IsPlayerInRangeOfPoint(i, 2.0, Gundrop[i][Gunx], Gundrop[i][Guny], Gundrop[i][Gunz]))
            {
                DestroyDynamicObject(Gundrop[i][GunObject]);
                DestroyDynamic3DTextLabel(Gundroplabel[i][GunLabel]);
            }
        }
        else if(IsValidDynamicObject(Gundrop2[i][GunObject1]))
        {
            if(IsPlayerInRangeOfPoint(i, 2.0, Gundrop2[i][Gun1x], Gundrop2[i][Gun1y], Gundrop2[i][Gun1z]))
            {
                DestroyDynamicObject(Gundrop2[i][GunObject1]);
                DestroyDynamic3DTextLabel(Gundroplabel2[i][GunLabel1]);
            }
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)