GiftBox Problems
#1

Hello!
I'm have a code:
Код:
dcmd_getgift(playerid, params[])
{
	#pragma unused params
	new Float:gx, Float:gy, Float:gz, string[256], string1[256], string2[256], string4[256], string5[256], name[60];
	new randompp = random(35);
	GetPlayerName(playerid, name, 60);
	new randommoney = random(750000);
	new randomxp = random(20);
	GetObjectPos(19056, gx, gy, gz);
	new ghours = GetPlayerGiftHours(playerid);
	new nhours = 3 - ghours;
	if(AccountInfo[playerid][Hours] <= 2) return SCM(playerid, ERROR, "Trebuie sa ai cel putin 2 ore jucate pentru a putea participa la GiftBox");
	format(string, sizeof(string), "Vei putea deschide din nou giftbox-ul peste %i ore", nhours);
	if(AccountInfo[playerid][GiftHours] == 2 && AccountInfo[playerid][GiftHours] == 0) return SCM(playerid, COLOR_YELLOW, string);
	else if(AccountInfo[playerid][GiftHours] == 1) return SCM(playerid, COLOR_YELLOW, "Vei putea deschide din nou giftbox-ul peste o ora");
	if(!IsPlayerInRangeOfPoint(playerid, 4, gx, gy, gz))	return SetPlayerCheckpoint(playerid, gx, gy, gz, 2); SCM(playerid, ERROR, "Nu esti in locatia potrivita,ti-am pus un checkpoint pe radar");
	if(!IsPlayerConnected(playerid)) return SCM(playerid, ERROR, "Trebuie sa fii conectat pentru a putea participa la giftbox!");
	else
	{
	new randgift = random(5);
	switch (randgift)
	{
	case 0:
	{
	format(string1, sizeof(string1), "Felicitari,ai castigat %i PremiumPoints din GiftBox!", randompp);
	SCM(playerid, COLOR_YELLOW, string1);
	AccountInfo[playerid][PremiumPoints] += randompp;
	format(string2, sizeof(string2), "{98AFC7}(( %s a castigat %i PremiumPoints din GiftBox! ))", name, randompp);
	SendClientMessageToAll(COLOR_YELLOW, string);
	AccountInfo[playerid][GiftHours] -= 3;
	}
	case 1:
	{
	format(string1, sizeof(string1), "Felicitari,ai castigat %i Experienta din GiftBox!", randomxp);
	SCM(playerid, COLOR_YELLOW, string1);
	AccountInfo[playerid][Exp] += randomxp;
	format(string2, sizeof(string2), "{98AFC7}(( %s a castigat %i Experienta din GiftBox! ))", name, randomxp);
	SendClientMessageToAll(COLOR_YELLOW, string);
	AccountInfo[playerid][GiftHours] -= 3;
	}
 	case 2: 
 	{
	format(string1, sizeof(string1), "Felicitari,ai castigat LEVELUP din GiftBox!");
	SCM(playerid, COLOR_YELLOW, string1);
	AccountInfo[playerid][Level] ++;
	format(string2, sizeof(string2), "{98AFC7}(( %s a castigat LEVELUP din GiftBox! ))", name);
	SendClientMessageToAll(COLOR_YELLOW, string2);
	AccountInfo[playerid][GiftHours] -= 3;
	}
  	case 3: 
  	{
  	format(string5, sizeof(string5), "Felicitari,ai castigat %i$ din GiftBox!", randommoney);
	SCM(playerid, COLOR_YELLOW, string5);
	format(string4, sizeof(string4), "{98AFC7}(( %s a castigat %i$ din GiftBox! ))", name, randommoney);
	SendClientMessageToAll(COLOR_YELLOW, string4);
	GivePlayerMoney(playerid, randommoney);
	AccountInfo[playerid][GiftHours] -= 3;
	        }
	    }
	}
	return 1;
}
Problems is:
1.When i'm type /getgift,checkpoint is placed in center of the map[Why?]
2.When i'm type /getgift and i'm near i'm not reward nothing.
Reply
#2

Your code is stroke inducing, you might as well rewrite it instead of taking the time to debug. For example, you are doing something wrong if you have 6 strings (string1, string2...) with 256 characters, same goes for the rest of the variables. I only skimmed the code but you can probably just have one string (probably not even needing 256 cells in the first place). You can reuse strings, only reason to create more is if you don't want to rewrite the other one for further usage.

Secondly, you initialize ghour and nhour variables, both unneeded really as they're used literally once. Just do it in-line, so instead of doing:
pawn Код:
format(string, sizeof(string), "Vei putea deschide din nou giftbox-ul peste %i ore", nhours);
You can simply:
pawn Код:
format(string, sizeof(string), "Vei putea deschide din nou giftbox-ul peste %i ore", 3 - GetPlayerGiftHours(playerid));
You also initialize this at the top, despite them each being used in one case:
pawn Код:
new randommoney = random(750000);
    new randomxp = random(20);
These can go under the respective case blocks. The same thing goes for randgift, simply use switch(5), no need for the variable.

Another problem is you're checking if the player is connected. Ofcourse they are, who else typed the command? (unless you called the function manually, but still, validity checks could go elsewhere).

DCMD also isn't the best command processor, but that's for another day.

As for the actual issue, 19056 is not the object ID, but the model ID. You need the ID returned from CreateObject.
Reply
#3

Код:
dcmd_getgift(playerid, params[])
{
	#pragma unused params
As stated above, you shouldn't use this...

Код:
dcmd_getgift(playerid) // If it doesn't need params, then why assign them...
{ //No more ugly Pragma bullshit
Reply
#4

Quote:
Originally Posted by Longover
Посмотреть сообщение
Hello!
I'm have a code:
Код:
GetObjectPos(19056, gx, gy, gz);
1.When i'm type /getgift,checkpoint is placed in center of the map[Why?]
Because you are using GetObjectPos with an object model, not the object id given by CreateObject

Quote:
Originally Posted by Longover
Посмотреть сообщение
Hello!
I'm have a code:
Код:
GetObjectPos(19056, gx, gy, gz);
Please store the object id like this:
Код:
new giftbox = CreateObject(19056, ...);
// ...
GetObjectPos(giftbox, gx, gy, gz);
https://sampwiki.blast.hk/wiki/GetObjectPos

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Код:
dcmd_getgift(playerid, params[])
{
	#pragma unused params
As stated above, you shouldn't use this...

Код:
dcmd_getgift(playerid) // If it doesn't need params, then why assign them...
{ //No more ugly Pragma bullshit
Because that will complain the macro?
Quote:

warning 202: number of arguments does not match definition

Reply
#5

Quote:
Originally Posted by RoboN1X
Посмотреть сообщение
Because that will complain the macro?
My mistake, I thought it was zcmd... OP... Convert to ZCMD, as it's better.


As for the error though, there'll be a better method to remove the params error, rather than using pragma.
Reply
#6

Код:
THANKS ALL FOR HELP!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)