Present system
#1

I got the command but when I type /gift crate [then gift type] the present is not created, any idea?

Code:
Код:
CMD:gift(playerid, params[])
{
    new option[32], type[32], string[100];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(PlayerInfo[playerid][pAdmin] <5) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
    if(!aDuty[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You are not on Admin Duty.");
    if(sscanf(params, "s[32]", option))
    {
        SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /gift [option]");
        SendClientMessage(playerid, COLOR_GREY, "OPTIONS: Create, Remove");
        return 1;
    }
    if(!strcmp(option, "create", true))
    {
		new Float:x, Float:y, Float:z;
		GetPlayerPos(playerid, x, y, z);
  		new File:presents=fopen("presents.cfg", io_append);
		format(string, sizeof(string), "%d, %d, %d\r\n", x, y, z);
  		fwrite(presents, string);
  		fclose(presents);
		if(sscanf(params, "s[32]s[32]", option, type))
	    {
	        SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /gift option [type]");
	        SendClientMessage(playerid, COLOR_GREY, "OPTIONS: Gift1, Gift2, Gift3, Gift4, Gift5");
	        return 1;
	    }
		if(!strcmp(type, "gift1", true))
		{
			Gift1 =1;
   			new GiftBox1 = CreateDynamicObject(19054, x, y, z, 0.00000, 0.00000, 0.00000, 0, 0, -1, 200.0);
		    IsValidDynamicObject(GiftBox1);
		    return 1;
		}
		if(!strcmp(type, "gift2", true))
		{
		    Gift2 =1;
		    new GiftBox2 = CreateDynamicObject(19055, x, y, z, 0.00000, 0.00000, 0.00000, 0, 0, -1, 200.0);
		    IsValidDynamicObject(GiftBox2);
		    return 1;
		}
		if(!strcmp(type, "gift3", true))
		{
			Gift3 =1;
   			new GiftBox3 = CreateDynamicObject(19056, x, y, z, 0.00000, 0.00000, 0.00000, 0, 0, -1, 200.0);
		    IsValidDynamicObject(GiftBox3);
		    return 1;
		}
		if(!strcmp(type, "gift4", true))
		{
            Gift4 =1;
  			new GiftBox4 = CreateDynamicObject(19057, x, y, z, 0.00000, 0.00000, 0.00000, 0, 0, -1, 200.0);
		    IsValidDynamicObject(GiftBox4);
		    return 1;
		}
		if(!strcmp(type, "gift5", true))
		{
		    Gift5 =1;
		    new GiftBox5 = CreateDynamicObject(19058, x, y, z, 0.00000, 0.00000, 0.00000, 0, 0, -1, 200.0);
		    IsValidDynamicObject(GiftBox5);
		    return 1;
		}
        return 1;
    }
    else if(!strcmp(option, "remove", true))
    {
		// Code...
        return 1;
    }
    return 1;
}
also is there a way I could add text on the present when it is created? like /open in blue text? like a 3dtext thing
Reply
#2

anyone?
Reply
#3

pawn Код:
if(!strcmp(option, "create", true))
Obviously, "create" is not the same as "create gift" so this statement will fail. This is one of those rare cases where that fourth strcmp parameter comes into play.
Reply
#4

soo... How would I fix this then?
Reply
#5

bump
Reply
#6

I practically gave you the answer on a silver platter, what more do you expect? Put some effort in it, will you?

https://sampwiki.blast.hk/wiki/Strcmp
Took 5 seconds to find.

Quote:

length (optional) When this length is set, the first x chars will be compared - doing "Hello" and "Hell No" with a length of 4 will say it's the same string.

Reply
#7

SSCANF is the issue here, also.

You would have to use an optional parameter, this will work better. Like this:
pawn Код:
if(sscanf(params, "s[32]S(0)[32]",option, type))
    {
        SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /gift [option]");
        SendClientMessage(playerid, COLOR_GREY, "OPTIONS: Create, Remove");
        return 1;
    }
The string compare should then work.

ALSO:

This tutorial cleared this up a hell of a lot for me.

https://sampforum.blast.hk/showthread.php?tid=250454
Reply
#8

Quote:
Originally Posted by Dokins
Посмотреть сообщение
SSCANF is the issue here, also.

You would have to use an optional parameter, this will work better. Like this:
pawn Код:
if(sscanf(params, "s[32]S(0)[32]",option, type))
    {
        SendClientMessage(playerid, COLOR_WHITE, "** [Usage]: /gift [option]");
        SendClientMessage(playerid, COLOR_GREY, "OPTIONS: Create, Remove");
        return 1;
    }
The string compare should then work.

ALSO:

This tutorial cleared this up a hell of a lot for me.

https://sampforum.blast.hk/showthread.php?tid=250454
I'll try this out, thanks for the help too.
Reply
#9

Okay good it worked, now I need help with the /open cmd for the present.... how do i set it so you got to be near the present to type /open?

cmd:
Код:
CMD:open(playerid, params[])
{
	new string[100], GiftBox1, GiftBox2, GiftBox3, GiftBox4, GiftBox5;
    /*new File:presents=fopen("presents.cfg", io_read);
	fclose(presents);
	if(IsPlayerInRangeOfPoint(playerid, 10.0, 23.213,2442.2424,242.214))
	{
		SendClientMessage(playerid, COLOR_GREY, "You're not in range of any Presents at the moment.");
		return 1;
	}*/
	if(Gift1 == 1)
	{
	    format(string, sizeof(string), "Congrats you were givin $10,000 from this package.");
        SendClientMessage(playerid, COLOR_WHITE, string);
		GiveDodMoney(playerid, 10000); // This is just a test, you can change it later.
		DestroyDynamicObject(GiftBox1);
		Gift1 =0;
		return 1;
	}
	if(Gift2 == 1)
	{
 		format(string, sizeof(string), "Congrats you were givin $5,000 from this package.");
        SendClientMessage(playerid, COLOR_WHITE, string);
		GiveDodMoney(playerid, 5000); // This is just a test, you can change it later.
		DestroyDynamicObject(GiftBox2);
		Gift2 =0;
		return 1;
	}
	if(Gift3 == 1)
	{
 		format(string, sizeof(string), "Congrats you were givin $11,000 from this package.");
        SendClientMessage(playerid, COLOR_WHITE, string);
		GiveDodMoney(playerid, 11000); // This is just a test, you can change it later.
		DestroyDynamicObject(GiftBox3);
		Gift3 =0;
		return 1;
	}
	if(Gift4 == 1)
	{
 		format(string, sizeof(string), "Congrats you were givin $12,000 from this package.");
        SendClientMessage(playerid, COLOR_WHITE, string);
		GiveDodMoney(playerid, 12000); // This is just a test, you can change it later.
		DestroyDynamicObject(GiftBox4);
		Gift4 =0;
		return 1;
	}
	if(Gift5 == 1)
	{
 		format(string, sizeof(string), "Congrats you were givin $19,000 from this package.");
        SendClientMessage(playerid, COLOR_WHITE, string);
		GiveDodMoney(playerid, 19000); // This is just a test, you can change it later.
		DestroyDynamicObject(GiftBox5);
		Gift5 =0;
		return 1;
	}
	return 1;
}
Reply
#10

If you are creating a dynamic system where you want to add multiple crates I'd suggest you do it like this:

pawn Код:
#define         MAX_GIFTS          100 //Or whatever amount you want to be maximum..
new Float: GiftX[MAX_GIFTS];
new Float: GiftY[MAX_GIFTS];
new Float: GiftZ[MAX_GIFTS];


//Under the command /gift create

new Float: x, y, z;
GetPlayerPos(playerid, x, y, z);

//loop through all gifts to get the ID

new giftid = i;

GiftX[giftid] = x;
GiftY[giftid] = y;
GiftZ[giftid]= z;

// on /open do this....

for(new giftid = 1; giftid < MAX_GIFTS; giftid ++)
{
    if(IsPlayerInRangeOfPoint(playerid, 3.0, GiftX[giftid], GiftY[giftid], GiftZ[giftid]);

//Give them a gift etc.

}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)