How to detect weapon?
#1

I have a /weapon command for people who donated on my server. But the problem is, they can have as many weapons as they want when they type /weapon


How can i make it so they can only choose 3 weapons and are unable to choose anymore until they die and respawn?


Here's my /weapon command:


pawn Код:
if (strcmp("/weapon", cmdtext, true, 10) == 0) // Shows Admin Command List
{
if(donator[playerid] == 1)
{
ShowPlayerDialog(playerid,DONATOR_DIALOG,2,"Choose a Weapon","Uzi\nAk47\nSawn-Off Shotgun\nTec9\nSMG\nCombat Shotgun","Buy","Cancel");
}
else
SendClientMessage(playerid,0xFF0000AA,"This Command is for Donators only, Donate to unlock it!");
return 1;
}
Reply
#2

Код:
new Dweapons;
When you give a weapon

Код:
Dweapons ++;
and

Код:
if(Dweapons > 3) SendClientMessage(0xFF0000AA, "You can only get items 3 times a spawn");
and

OnPlayerSpawn

Код:
Dweapons = 0
Reply
#3

This is what I have and i'm getting errors


Top of script:

pawn Код:
new Dweapons;
Onplayerspawn:

pawn Код:
Dweapons = 0;
Onplayerdeath:

pawn Код:
Dweapons = 0;
My Ondialogresponse:

pawn Код:
if(dialogid==DONATOR_DIALOG)
{
if(response)
{
if(listitem==0)
{
GivePlayerWeapon(playerid, 28, 150);
Dweapons ++;
return 1;
}
if(listitem==1)
{
GivePlayerWeapon(playerid, 30, 150);
Dweapons ++;
return 1;
}
if(listitem==2)
{
GivePlayerWeapon(playerid, 26, 150);
Dweapons ++;
return 1;
}
if(listitem==3)
{
GivePlayerWeapon(playerid, 32, 150);
Dweapons ++;
return 1;
}
if(listitem==4)
{
GivePlayerWeapon(playerid, 29, 150);
Dweapons ++;
return 1;
}
if(listitem==5)
{
GivePlayerWeapon(playerid, 27, 150);
Dweapons ++;
return 1;
}
if(listitem==6)
{
GivePlayerWeapon(playerid,35,15);
Dweapons ++;
return 1;
}
else
if(Dweapons > 3) SendClientMessage(0xFF0000AA, "You can only get items 3 times a spawn");
return 1;
}
}

ERRORS:

Код:
(13259) : error 035: argument type mismatch (argument 2)
ON:

pawn Код:
if(Dweapons > 3) SendClientMessage(0xFF0000AA, "You can only get items 3 times a spawn");
Reply
#4

Agreed with [ĦŁ₣]ЉǾǖŦĦЗŁΛẄ .

Or you have to do SendClientMessageToAll but since this is meant for 1 player only, add playerid

Код:
if(Dweapons > 3) SendClientMessage(playerid, 0xFF0000AA, "You can only get items 3 times a spawn");
Reply
#5

TOP
pawn Код:
new Dweapons[MAX_PLAYERS];
DEATH
pawn Код:
Dweapons[playerid] = 0;
DIALOG
pawn Код:
if(dialogid==DONATOR_DIALOG)
{
  if(response)
  {
   if(Dweapons >= 3) SendClientMessage(0xFF0000AA, "You can only get items 3 times a spawn");
   if(listitem==0)
   {
     GivePlayerWeapon(playerid, 28, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==1)
   {
     GivePlayerWeapon(playerid, 30, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==2)
   {
     GivePlayerWeapon(playerid, 26, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==3)
   {
     GivePlayerWeapon(playerid, 32, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==4)
   {
     GivePlayerWeapon(playerid, 29, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==5)
   {
     GivePlayerWeapon(playerid, 27, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==6)
   {
     GivePlayerWeapon(playerid,35,15);
     Dweapons[playerid] ++;
     return 1;
  }
}
I Edited it
Reply
#6

Quote:
Originally Posted by CAR
TOP
pawn Код:
new Dweapons[MAX_PLAYERS];
DEATH
pawn Код:
Dweapons[playerid] = 0;
DIALOG
pawn Код:
if(dialogid==DONATOR_DIALOG)
{
  if(response)
  {
   if(Dweapons >= 3) SendClientMessage(0xFF0000AA, "You can only get items 3 times a spawn");
   if(listitem==0)
   {
     GivePlayerWeapon(playerid, 28, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==1)
   {
     GivePlayerWeapon(playerid, 30, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==2)
   {
     GivePlayerWeapon(playerid, 26, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==3)
   {
     GivePlayerWeapon(playerid, 32, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==4)
   {
     GivePlayerWeapon(playerid, 29, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==5)
   {
     GivePlayerWeapon(playerid, 27, 150);
     Dweapons[playerid] ++;
     return 1;
   }
   if(listitem==6)
   {
     GivePlayerWeapon(playerid,35,15);
     Dweapons[playerid] ++;
     return 1;
  }
}
I Edited it
I get the following 2 errors now,
Код:
error 033: array must be indexed (variable "Dweapons")
error 035: argument type mismatch (argument 2)
On this line:

pawn Код:
if(Dweapons >= 3) SendClientMessage(0xFF0000AA, "You can only get items 3 times a spawn");
Reply
#7

Quote:
Originally Posted by [ĦŁ₣
ЉǾǖŦĦЗŁΛẄ ]
You still haven't added what I said to add, scroll up and look at my last post.

The 'Array must be indexed' means you haven't told it what part of the array 'Dweapons' you are checking to be above 3

This is how arrays work: they are like variables bit split into loads of parts so:

new Array[20];

this array has 20 parts and you can assign each part different values etc:

Array[3] = 4

this makes the 2nd part of it worth 4 [it is the 2nd part because they always start on zero '0' so count form zero to 2 and it is 3: 0,1,2]

You are creating the array with MAX_PLAYERS as the size so this makes the array into 500 parts and when you use 'playerid' as the 'index' [the 'part' number] it assigns the value to that players number so if it's playerid 2 then Array[playerid] will assign the 3rd part the value [remember they start on 0]

Understand arrays now?

Your problem is that you haven't told the compiler what 'part' of the array you want to check that it's above 3:

if(Dweapons >= 3)

You need to tell it that you want to see if the playerid who responded on the dialog has selected weapons 3 times

To fix this just add a playerid array definition after the array:

if(Dweapons[playerid] >= 3)

Now the code should work fine.

Hope that helps
WOW dude thanks for taking the time to type all that up. I actually understand what it means now.!


But theres still a problem. It checks if i have picked a weapon 3 times, but it does not prevent the player from picking it. It displays the message, but i can still pick weapons
Reply
#8

Quote:
Originally Posted by [ĦŁ₣
ЉǾǖŦĦЗŁΛẄ ]
That's no problem, I like to help wherever I can :P

I messed up the text a bit by not ending the [ sup ] tag on '3rd' :P all fixed now

Glad it helped
Can you help me with the other problem though

It checks if i have picked a weapon 3 times, but it does not prevent the player from picking it. It displays the message, but i can still pick weapons
Reply
#9

PERFECT



Thank you very much.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)