Raised This Month: $51 Target: $400
 12% 

Custom points system broken


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-05-2017 , 20:08   Custom points system broken
Reply With Quote #1

So I have a perk system setup in my Zombie Mod where players use points they've earned from killing zombies, but it seems to reward a larger amount of points then it should. It rewards points on hooked events like player death.

Code:
public Action At_Player_Death(Handle event, const String:name[], bool:dontBroadcast)
{
	new Client = GetClientOfUserId(GetEventInt(event, "userid"));
	new Attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
	if(bIsPlayerAlive[Attacker] && !bIsPlayerZombie[Attacker])
	{
		ZomPoints[Attacker] += 0.5;
Then points are taken away in a block such as this

Code:
public void OnClientDisconnect_Post(int Client)
{
	ZomPoints[Client] = 0;
Code:
public Action ArtillaryStrike(int Client, int args) //&& ZomPoints[Client] >= 10 && HasRoundStarted
{
	if(bIsPlayerAlive[Client] && !bIsPlayerZombie[Client] && ZomPoints[Client] >= 10 && !ArtillaryRestriction[Client])
	{
	     ZomPoints[Client] -= 10;
I'm not sure the issue perhaps a more experienced eye could spot an error.
Halt is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 09-06-2017 , 11:23   Re: Custom points system broken
Reply With Quote #2

wihtout the full code we can't help you
and stop posting in the wrong section
8guawong is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-06-2017 , 11:27   Re: Custom points system broken
Reply With Quote #3

If you want expected results don't mix floats and ints.
Mitchell is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-06-2017 , 12:01   Re: Custom points system broken
Reply With Quote #4

Can a moderator please move this thread?

Quote:
Originally Posted by Mitchell View Post
If you want expected results don't mix floats and ints.
Thanks for the tip, will fix. Can you explain why this is bad? (Just so I know for future reference)
Halt is offline
Maxximou5
AlliedModders Donor
Join Date: Feb 2013
Old 09-06-2017 , 12:16   Re: Custom points system broken
Reply With Quote #5

As Mitchell said, it's bad because you'll get unexpected results. If you need to give 0.5, set ZomPoints as a float and use it as such and convert it when necessary. Otherwise, increase your point system to where 0.5 becomes a value a 1 and use it as a int.
Also, you shouldn't mix old with new syntax either.
Maxximou5 is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-06-2017 , 12:29   Re: Custom points system broken
Reply With Quote #6

Quote:
Originally Posted by Maxximou5 View Post
Also, you shouldn't mix old with new syntax either.

Currently trying to switch over to the new syntax. My script is a bit sloppy.

Where in here is old syntax?

Last edited by Halt; 09-06-2017 at 12:30.
Halt is offline
Maxximou5
AlliedModders Donor
Join Date: Feb 2013
Old 09-06-2017 , 12:40   Re: Custom points system broken
Reply With Quote #7

Your first code block.
PHP Code:
public Action At_Player_Death(Handle event, const String:name[], bool:dontBroadcast)
{
    new 
Client GetClientOfUserId(GetEventInt(event"userid"));
    new 
Attacker GetClientOfUserId(GetEventInt(event"attacker"));
    if(
bIsPlayerAlive[Attacker] && !bIsPlayerZombie[Attacker])
    {
        
ZomPoints[Attacker] += 0.5
Should be:
PHP Code:
public Action At_Player_Death(Event event, const char[] namebool dontBroadcast)
{
    
int Client GetClientOfUserId(event.GetInt("userid"));
    
int Attacker GetClientOfUserId(event.GetInt("attacker"));
    if(
bIsPlayerAlive[Attacker] && !bIsPlayerZombie[Attacker])
    {
        
ZomPoints[Attacker] += 0.5
Maxximou5 is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-06-2017 , 12:42   Re: Custom points system broken
Reply With Quote #8

Spoiler


Thanks! And when setting my float to zero it's just 0, not 0.0 correct?
Halt is offline
Maxximou5
AlliedModders Donor
Join Date: Feb 2013
Old 09-06-2017 , 12:47   Re: Custom points system broken
Reply With Quote #9

I believe it to be good practice to always add a dot delimiter like .0 when dealing with floats.
If it's a float, treat it as such and your code should show it.
Maxximou5 is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 09-06-2017 , 12:49   Re: Custom points system broken
Reply With Quote #10

Quote:
Originally Posted by Halt View Post
Can a moderator please move this thread?
Posting that kind of stuff in public doesn't really help or bring any attention from the moderators/administrators:

Use the Report Post button near the thread, and put in a comment describing what issue you see, e.g. "Seems to be wrong section. I suggest moving the thread to Scripting", etc.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode