[Coox Script] Sickness system [11.01.2016]

Scripter or interested in scripting? This place just may fancy to your likings!

Moderators: Game Admins, FM, Lead Admins

Post Reply
User avatar
EldarCoox
Mafia
Mafia
Posts: 471
Joined: Sun Jul 21, 2013 9:44 pm
Ingame name: Ace

[Coox Script] Sickness system [11.01.2016]

Post by EldarCoox » Wed Jan 11, 2017 1:36 pm

Hello friends, I was bored so I decided to make a sickness system.
Notes: I was to lazy to do a GivePlayerHealth stock (which can be used for taking certain amount of hp from the player) so i went with SetPlayerHealth I advise you to make a GivePlayerHealth stock, or you will get bugs.



EDIT: Code has been edited with a fresh new update Coox & Sparke.
Last edited by EldarCoox on Wed Jan 11, 2017 6:57 pm, edited 2 times in total.

User avatar
Sparke
- Silver Member -
- Silver Member -
Posts: 219
Joined: Fri Jun 27, 2014 3:45 pm

Re: [Coox Script] Sickness system

Post by Sparke » Wed Jan 11, 2017 5:14 pm

There's some improvements that could be made. You should add where if they don't have $5,000 they can't purchase the cure, and you should also make it where they can buy the cure, and use it for later.

What's this for?

Code: Select all

#define SendClientMessage SendClientMessage // We are making a shortcut so instead of SendClientMessage we just do SendClientMessage
You should have used OnPlayerSpawn, and SetTimerEx look at the wikis for them. You're putting them OnGameModeInit which is doing nothing but starting a timer then. You need to assign it to the player. So you'll need to use OnPlayerSpawn or OnPlayerConnect, or you can make a loop in the timer that you've assigned OnGameModeInit but I don't think every single person in the server that's sick would throw up on que together (lol). I've re-coded your system, and put it here. I've described stuff using comments I hope you learn from it.


There's the script, the BB code for the pastebin stuff isn't working for me so I just included the link.

http://pastebin.com/iAuj6sC4

This is a working version of what you made. I strongly recommend you reading the comments I created inside of it. Good luck

If your to lazy to click the link here's the code tags for it;
Spoiler: show

Code: Select all

#include <a_samp>

main()
{
	print("Sick script loaded!");
}

new Sick[MAX_PLAYERS], // Creating the varbles for the script
	HasCure[MAX_PLAYERS];

#define SICK_TIMER 5000 // This is how long the timer will be. | 1000 = 1 second
#define SICK_HP 20 // This will be how much health is deducted from the user while their

forward Sickness(playerid); // Forwarding the timer

public OnPlayerConnect(playerid)
{
	Sick[playerid] = 0; // Sets their sickness to 0
	HasCure[playerid] = 0; // Sets their cure to 0
	return 1;
}

public OnPlayerSpawn(playerid) // This is called whenever a person spawns
{
	SetTimerEx("Sickness", SICK_TIMER, false, "i", playerid); // Setting the timer | Check the SetTimerEx wiki page for more information on the paramters
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/buycure", cmdtext, true, 10) == 0) // This will buy the cure and save it for later unless the player re-connects or d/c's
    {
        GivePlayerMoney(playerid, -5000);
        HasCure[playerid] = 1;
        return 1;
    }
    if(strcmp("/usecure", cmdtext, true, 10) == 0) // This will use the cure if the player has one
    {
    	if(HasCure[playerid] == 1)
    	{
    		SendClientMessage(playerid, -1, "You've used the cure!");
    		Sick[playerid] = 0;
    	} else {
    		SendClientMessage(playerid, -1, "You do not have the cure /buycure to get one.");
    	}
    	return 1;
    }
    if(strcmp("/makemesick", cmdtext, true, 10) == 0) // This command will make the player sick for testing purposes
    {
    	Sick[playerid] = 1;
    	SendClientMessage(playerid, -1, "You're now sick");
    	return 1;
    }
    return 0;
}


public Sickness(playerid) // This is called when the timer is done
{
	SetTimerEx("Sickness", 5000, false, "i", playerid); // Re-starts the timer

	if(Sick[playerid] == 1)
	{
		new Float:sickHP;

		GetPlayerHealth(playerid, sickHP); // getting the players health

		SetPlayerHealth(playerid, sickHP - SICK_HP); // Setting the players health down 20 due to them being sick

	    SendClientMessage(playerid, -1, "You're sick find somewhere to buy the cure!"); // Sends a message to the player telling them their sick
	   
	    ApplyAnimation(playerid, "FOOD", "EAT_Vomit_P", 4.1, 1, 1, 1, 1, 1, 1); // Applys the animation
	} else {
		SendClientMessage(playerid, -1, "You're not sick."); // This is here only for testing purposes to make sure the if statement is done properly
	}
	return 1;
}
Here's what I've added;
  • Storing the cure for later (/buycure then you can /usecure later)
  • Added a /makemesick for testing purposes
  • Added an if statement inside of when the timers called to make sure people who aren't sick are receiving sick effects
  • Added the timer to start OnPlayerSpawn instead of OnGameModeInit

F Sullivan
Mafia
Mafia
Posts: 573
Joined: Sun Mar 22, 2015 7:23 am

Re: [Coox Script] Sickness system

Post by F Sullivan » Wed Jan 11, 2017 5:46 pm

Code: Select all

#define SICK_TIMER 5000 // This is how long the timer will be. | 1000 = 1 second
#define SICK_HP 20 // This will be how much health is deducted from the user while their
You're creating a global directive for something that should be done with static const, in my opinion.

User avatar
EldarCoox
Mafia
Mafia
Posts: 471
Joined: Sun Jul 21, 2013 9:44 pm
Ingame name: Ace

Re: [Coox Script] Sickness system

Post by EldarCoox » Wed Jan 11, 2017 5:55 pm

Wow thanks dude and i was gonna do it rn it was just beta but thanks anyways i did it like that so people can adjust it they're own script thanks anyways

User avatar
Sparke
- Silver Member -
- Silver Member -
Posts: 219
Joined: Fri Jun 27, 2014 3:45 pm

Re: [Coox Script] Sickness system

Post by Sparke » Wed Jan 11, 2017 6:02 pm

F Sullivan wrote:

Code: Select all

#define SICK_TIMER 5000 // This is how long the timer will be. | 1000 = 1 second
#define SICK_HP 20 // This will be how much health is deducted from the user while their
You're creating a global directive for something that should be done with static const, in my opinion.
Preference

F Sullivan
Mafia
Mafia
Posts: 573
Joined: Sun Mar 22, 2015 7:23 am

Re: [Coox Script] Sickness system

Post by F Sullivan » Wed Jan 11, 2017 6:09 pm

Sparke wrote:
F Sullivan wrote:

Code: Select all

#define SICK_TIMER 5000 // This is how long the timer will be. | 1000 = 1 second
#define SICK_HP 20 // This will be how much health is deducted from the user while their
You're creating a global directive for something that should be done with static const, in my opinion.
Preference
Scope? Compiler awareness? Memory? It doesn't come down to purely preference.
Last edited by F Sullivan on Wed Jan 11, 2017 7:01 pm, edited 1 time in total.

User avatar
EldarCoox
Mafia
Mafia
Posts: 471
Joined: Sun Jul 21, 2013 9:44 pm
Ingame name: Ace

Re: [Coox Script] Sickness system [11.01.2016]

Post by EldarCoox » Wed Jan 11, 2017 6:58 pm

The thread has been updated seccesfully with new things added :D

User avatar
Sparke
- Silver Member -
- Silver Member -
Posts: 219
Joined: Fri Jun 27, 2014 3:45 pm

Re: [Coox Script] Sickness system

Post by Sparke » Wed Jan 11, 2017 7:27 pm

F Sullivan wrote:
Sparke wrote:
F Sullivan wrote:

Code: Select all

#define SICK_TIMER 5000 // This is how long the timer will be. | 1000 = 1 second
#define SICK_HP 20 // This will be how much health is deducted from the user while their
You're creating a global directive for something that should be done with static const, in my opinion.
Preference
Scope? Compiler awareness? Memory? It doesn't come down to purely preference.
You're right. I never said it didn't. I just didn't think it was worth it in the end. I know it's something to be in good habit of having "optimized" code, but personally it doesn't make that big of a difference (on this). I do understand why you would use, and I do also think I should get in the habit of it as well, thanks for the correction.

Post Reply

Return to “Scripting Section”

Who is online

Users browsing this forum: No registered users and 1 guest