Little XP System problem -
luckie12 - 10.05.2014
Hi everybody, im playing with the variables, and i decided to make a small XP system for my server, its not alot of code haha but here is it:
Код:
new PlayerXP[MAX_PLAYERS];
public OnPlayerDeath(playerid, killerid, reason)
{
PlayerXP[playerid] = -5;
SendClientMessage(playerid, 0, "You lost 5 xp points!");
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/xp", cmdtext, true, 10) == 0)
{
PlayerXP[playerid] += 50;
return 1;
}
if (strcmp("/getxp", cmdtext, true, 10) == 0)
{
SendClientMessage(playerid, 0, PlayerXP[playerid]);
return 1;
}
return 0;
}
But the problem is, when i have like only 2 XP points and i get killed so thats 2-4 thats not possible, but when i type /getxp (shows me how much XP i have) it says random characters, and if i do /xp (it needs to give me 50xp) and then do /getxp it says just 2 like i have 2 xp or something
Please help me out ;o
Re: Little XP System problem -
Konstantinos - 10.05.2014
- Everytime a player dies, their XP goes -5 and that can go to a negative value if you have less than 4 XP points.
- Everytime you type /xp command, it adds +50 to the current value.
For the command /getxp, you cannot use the array which stores an integer value as string and that would give error 035: argument type mismatch (argument 3). You need to
format a string first and send the formatted string in SendClientMessage message.
Re: Little XP System problem -
luckie12 - 10.05.2014
i can see, on gta wiki, but its not that clear for me the example, can you show something or tell me a little about it that makes it easy?
Re: Little XP System problem -
Konstantinos - 10.05.2014
pawn Код:
new msg[32]; // create an array with size of 32 (enough to store the text)
format(msg, sizeof (msg), "XP Points: %i", PlayerXP[playerid]); // we use placeholder "%i" for integers and the argument PlayerXP[playerid] is an integer (notice 1 placeholder for 1 argument)
SendClientMessage(playerid, -1, msg); // send the formatted text which is stored in variable "msg"
Re: Little XP System problem -
luckie12 - 10.05.2014
It looks so easy haha but for newbs, yep its difficult haha i will try!
Re: Little XP System problem -
luckie12 - 10.05.2014
As you can see theres in the chat a blank space between
Filterscript 'playerxp.amx' loaded.
and
You gained some experience points!
Theres where i did /getxp to check how much XP i had in beginning so it returned blank,
then i did /getxp it returned 2, then i did /xp and then /getxp it returned a D, and again /getxp and returned a D again, then /xp again and then /getxp and it returned a -- so i dont get it anymore haha ;$
And it doesnt say,
Код:
format(msg, sizeof (msg), "XP Points: %i", PlayerXP[playerid]); // we use placeholder "%i" for integers and the argu
XP Points: (ingame) only returns the value
Re: Little XP System problem -
luckie12 - 10.05.2014
Kay nvm it works, <3 thankyou! i can use it for more variables, if i will release my script, you are on the creds list, and ingame u are in the creds list, but can u tell me one more thing or Learn, how can i make it that if he has 4 xp and he dies and loses 5 xp he wont get -1 but just 0 XP
Re: Little XP System problem -
Konstantinos - 10.05.2014
pawn Код:
if ((PlayerXP[playerid] -= 5) < 0) PlayerXP[playerid] = 0;
Re: Little XP System problem -
luckie12 - 10.05.2014
Works like charm :3 I want to thank you alot, now im gonna try to learn too how to check how to give someone else XP
Re: Little XP System problem -
luckie12 - 10.05.2014
is there a way that you can make a lil admin script, based on users their name in the script like u define them in ENUMS?(the user names)