i really dont understand what's happening -
aircombat - 20.05.2010
k , so i created a /rob , but the problem is the params doesnt work properly like if i did /rob lol , it said u robbed Etch (Me) , if i /rob 1 and he exist , it just send him a msg but i dont get the money so can u take a look at it :
Код:
dcmd_rob(playerid,params[])
{
new giveplayerid; new Float:gX; new Float:gY; new Float:gZ; GetPlayerPos(giveplayerid,gX,gY,gZ);
if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, 0xFF9900AA, "Usage: /rob [Playerid/Partname]");
else if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid,0xFF9900AA,"Player Isn't Online");
else if (giveplayerid == playerid)return SendClientMessage(playerid,0xFF9900AA,"Player Is Not Connected Or Its Yourself!");
else if(AllowedToRob[playerid] == 0) return SendClientMessage(playerid,0xFF9900AA,"You Can Only Rob Each 10 Minutes");
else if(!IsPlayerInRangeOfPoint(playerid, 5.0, gX, gY, gZ)) return SendClientMessage(playerid,0xFF9900AA,"You Have To Be Near The Player To Rob Him");
else
{
GivePlayerMoney(giveplayerid,-GetPlayerMoney(giveplayerid));
GivePlayerMoney(playerid,GetPlayerMoney(giveplayerid));
new string1[128],string2[128],pName1[MAX_PLAYER_NAME],pName2[MAX_PLAYER_NAME]; GetPlayerName(playerid,pName1,MAX_PLAYER_NAME); GetPlayerName(giveplayerid,pName2,MAX_PLAYER_NAME);
format(string1,128,"%s Robbed You!",pName1);
SendClientMessage(giveplayerid,COLOR_YELLOW,string1);
format(string2,128,"You Robbed %s",pName2);
SendClientMessage(playerid,COLOR_YELLOW,string2);
AllowedToRob[playerid] = 0;
SetTimerEx("RobAgain", 600000, 0, "i", playerid);
}
return 1;
}
Re: i really dont understand what's happening -
Naxix - 20.05.2010
I made this command a while ago, it should work and you can just edit as you please (if you want 2)
Код:
dcmd_robplayer(playerid,params[])
{
new pid,money = random(6000);
new Float:x,Float:y,Float:z;
GetPlayerPos(pid,x,y,z);
if(sscanf(params,"u",pid)) return SendClientMessage(playerid,COLOUR_RED,"Usage: /robplayer [id]");
else if(pid == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOUR_RED,"Inactive player id");
else if(pid == playerid) return SendClientMessage(playerid,COLOUR_RED,"You cannot rob yourself!");
else if(GetPlayerMoney(pid) <= 0) return SendClientMessage(playerid,COLOUR_RED,"That player doesn't have enough money to rob from!");
else if(IsPlayerInRangeOfPoint(playerid,6,x,y,z))
{
new stringD[55],stringE[55],name[MAX_PLAYER_NAME],name2[MAX_PLAYER_NAME];
GetPlayerName(pid,name,sizeof(name));
GetPlayerName(playerid,name2,sizeof(name2));
SetPlayerCash(pid,GetPlayerMoney(pid)-money);
SetPlayerCash(playerid,GetPlayerMoney(playerid)+money);
format(stringD,sizeof(stringD),"%s robbed you for $%i!",name2,money);
format(stringE,sizeof(stringE),"You robbed $%i from %s!",money,name);
SendClientMessage(pid,COLOUR_RED,stringD);
SendClientMessage(playerid,COLOUR_RED,stringE);
SetTimerEx("RobChecker",600000,0,"playerid",playerid);
SetPlayerWantedLevel(pid,GetPlayerWantedLevel(playerid)+2);
ROB[playerid] = 1;
return 1;
}
return SendClientMessage(playerid,COLOUR_RED,"Player is too far away");
}
Re: i really dont understand what's happening -
juice.j - 20.05.2010
Can you explain once more what the result is when you perform the command?
The code itself looks like it could work, however a few logic mistakes:
You check the range of giveplayerid before you write the playerid into it (directly after "new giveplayerid;"). This gives back coords of playerid 0.
Create further variables as soon as you need them, not if they possible wouldn't be used (new Float:gX; new Float:gY; new Float:gZ
![Wink](images/smilies/wink.png)
.
string1 and string2 in the way you do it, is a waste of variables - so are pName1 and pName2. You could use one string for each.
Re: i really dont understand what's happening -
aircombat - 20.05.2010
/rob lol :
Etch Robbed You (which is me) Get Sent To Me
/rob 1 (Which is another id online) :
Etch Robbed You Get Sent To Me
Re: i really dont understand what's happening -
juice.j - 20.05.2010
And lol as well as playerid 1 are connected to your server at that time?
Re: i really dont understand what's happening -
aircombat - 20.05.2010
no it just return to me , /rob lol , /rob etch , /rob 10 , /rob 11 , /rob juice , all return on me get robbed
Re: i really dont understand what's happening -
juice.j - 20.05.2010
Suppose its the first else you use, which might result in a logic error...
Try this:
Код:
dcmd_rob(playerid,params[])
{
new giveplayerid;
if(sscanf(params, "u", giveplayerid)){
return SendClientMessage(playerid, 0xFF9900AA, "Usage: /rob [Playerid/Partname]");
} else {
if(!IsPlayerConnected(giveplayerid))
return SendClientMessage(playerid,0xFF9900AA,"Player Isn't Online");
if (giveplayerid == playerid)
return SendClientMessage(playerid,0xFF9900AA,"Player Is Not Connected Or Its Yourself!");
if(AllowedToRob[playerid] == 0)
return SendClientMessage(playerid,0xFF9900AA,"You Can Only Rob Each 10 Minutes");
new Float:gX; new Float:gY; new Float:gZ;
GetPlayerPos(giveplayerid,gX,gY,gZ);
if(!IsPlayerInRangeOfPoint(playerid, 5.0, gX, gY, gZ))
return SendClientMessage(playerid,0xFF9900AA,"You Have To Be Near The Player To Rob Him");
GivePlayerMoney(giveplayerid,-GetPlayerMoney(giveplayerid));
GivePlayerMoney(playerid,GetPlayerMoney(giveplayerid));
new string1[128],string2[128],pName1[MAX_PLAYER_NAME],pName2[MAX_PLAYER_NAME]; GetPlayerName(playerid,pName1,MAX_PLAYER_NAME); GetPlayerName(giveplayerid,pName2,MAX_PLAYER_NAME);
format(string1,128,"%s Robbed You!",pName1);
SendClientMessage(giveplayerid,COLOR_YELLOW,string1);
format(string2,128,"You Robbed %s",pName2);
SendClientMessage(playerid,COLOR_YELLOW,string2);
AllowedToRob[playerid] = 0;
SetTimerEx("RobAgain", 600000, 0, "i", playerid);
}
return 1;
}
(( Entirely untested ))
If my guess should turn out to be true I can explain you the problem.