Server sided money(points) help.
#1

So I've custom money system(called points),

So what I've tried to do is create a weapon shop dialog, the only problem I have is this!


Код:
C:\Users\yan\Desktop\LS DM\gamemodes\DBv1.pwn(1653) : error 017: undefined symbol "GetPlayerPoints"
C:\Users\yan\Desktop\LS DM\gamemodes\DBv1.pwn(1657) : error 017: undefined symbol "GivePlayerPoints"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Код:
stock SellWeapon(playerid, points, weapon, ammo)
{
   new ppoints = GetPlayerPoints(playerid);
   if(ppoints>points)
   {
	  new string[80], weaponname[32];
	  GivePlayerPoints(playerid, -points, pInfo[playerid][Points]);
	  GivePlayerWeapon(playerid, weapon,ammo);
	  GetWeaponName(weapon, weaponname, sizeof(weaponname));
	  format(string, sizeof(string), "{c3c3c3}(SHOP) You have bought %s with %i ammo for %i points", weaponname, ammo, points);
	  return SendClientMessage(playerid, -1, string);
   }
   else return SendClientMessage(playerid, -1,"You don't have enough points");
}
How do I get the player points correctly? (and set it of course)
Reply
#2

You haven't defined GetPlayerPoints, or GivePlayerPoints.

So what it is, is that you haven't got the function, but you are trying to use it.

Код:
forward GetPlayerPoints(playerid);
public GetPlayerPoints(playerid)
{
    return pInfo[playerid][Points];
}
Код:
forward GivePlayerPoints(playerid, amount);
public GivePlayerPoints(playerid,amount)
{
    pInfo[playerid][Points]=pInfo[playerid][Points]+amount;
    return 1;
}
This is just what it should have, but it's in no way tested. You're likely to be missing all of this. Also not that you use in GivePlayerPoints, that you have 3 params, when you only need 2 because the enum is addressed inside the function itself.

Just use this as more a sketch, rather than 'actual' code.

Here's an older tutorial, that still holds good info. More than what I've shown here.

https://sampforum.blast.hk/showthread.php?tid=71136
Reply
#3

No need for it to be a public function. Also use the "+" and "=" operators.

i.e:

PHP код:
stock GetPlayerPointsplayerid )
     return 
pInfoplayerid ][ Points ];
stock GivePlayerPointsplayeridamount ) {
    
pInfoplayerid ][ Points ] += amount
    return 
1;

Reply
#4

As I said, untested and more as a point of what he was missing, than being usable code.

Don't use stock this way as it's not even advised...

Can simply use no prefix, I just used public as it's standard.
Reply
#5

I tried to use this tutorial

https://sampforum.blast.hk/showthread.php?pid=3215317#pid3215317
Reply
#6

Quote:
Originally Posted by ivndosos
Посмотреть сообщение
That's not a tutorial for server sided money at all... This could be where you're starting your problem.
Reply
#7

Okay It's working perfectly the only problem is:

For example I have 11 points and M4 costs 10 points, I can buy it,

If I have exactly 10 points I can't buy it, If I have less that 10 too I also can't buy it

Код:
stock SellWeapon(playerid, points, weapon, ammo)
{
   new ppoints = GetPlayerPoints(playerid);
   if(ppoints>points)
   {
	  new string[80], weaponname[32];
	  GivePlayerPoints(playerid, -points);
	  GetPlayerPoints(playerid);
	  GivePlayerWeapon(playerid, weapon,ammo);
	  GetWeaponName(weapon, weaponname, sizeof(weaponname));
	  format(string, sizeof(string), "{EFB509}(SHOP) You have bought %s with %i ammo for %i points", weaponname, ammo, points);
	  return SendClientMessage(playerid, -1, string);
   }
   else return SendClientMessage(playerid, -1,"{FF0000}(INFO) You don't have enough points");
}
forward GetPlayerPoints(playerid);
public GetPlayerPoints(playerid)
{
    return pInfo[playerid][Points];
}
forward GivePlayerPoints(playerid, amount);
public GivePlayerPoints(playerid,amount)
{
    pInfo[playerid][Points]=pInfo[playerid][Points]+amount;
    return 1;
}
Reply
#8

How you have it, it'll only check if it's less than, it's not checking the equal amount.

Код:
if(ppoints>=points)
This does less than or equal to.
Reply
#9

Thanks
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)