Raised This Month: $ Target: $400
 0% 

Can you help me to reduce this code?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 11-30-2021 , 03:17   Can you help me to reduce this code?
Reply With Quote #1

Hello. There is a confusing code that makes me unable to add new game modes in the main source code of ZPA 1.6.1. I want this code to be simplified:

PHP Code:
// ZP Teams
const ZP_TEAM_NO_ONE 0
const ZP_TEAM_ANY 0
const ZP_TEAM_ZOMBIE = (1<<0)     // 1
const ZP_TEAM_HUMAN = (1<<1)     // 2
const ZP_TEAM_NEMESIS = (1<<2)    // 4
const ZP_TEAM_SURVIVOR = (1<<3// 8
const ZP_TEAM_SNIPER = (1<<4)     // 16
const ZP_TEAM_ASSASSIN = (1<<5// 32
new const ZP_TEAM_NAMES[][] =
{     
    
"ZOMBIE , HUMAN"
    
"ZOMBIE"
    
"HUMAN"
    
"ZOMBIE , HUMAN"
    
"NEMESIS",
    
"ZOMBIE , NEMESIS"
    
"HUMAN , NEMESIS"
    
"ZOMBIE , HUMAN , NEMESIS",
    
"SURVIVOR"
    
"ZOMBIE , SURVIVOR"
    
"HUMAN , SURVIVOR"
    
"ZOMBIE, HUMAN, SURVIVOR",
    
"NEMESIS , SURVIVOR",
    
"ZOMBIE , NEMESIS , SURVIVOR",
    
"HUMAN, NEMESIS, SURVIVOR",
    
"ZOMBIE , HUMAN , NEMESIS , SURVIVOR",
    
"SNIPER",
    
"ZOMBIE, SNIPER",
    
"HUMAN, SNIPER",
    
"ZOMBIE, HUMAN, SNIPER",
    
"NEMESIS , SNIPER",
    
"ZOMBIE , NEMESIS , SNIPER",
    
"HUMAN , NEMESIS , SNIPER",
    
"ZOMBIE , HUMAN , NEMESIS , SNIPER",
    
"SURVIVOR, SNIPER",
    
"ZOMBIE, SURVIVOR, SNIPER",
    
"HUMAN, SURVIVOR, SNIPER",
    
"ZOMBIE, HUMAN, SURVIVOR, SNIPER",
    
"NEMESIS, SURVIVOR, SNIPER",
    
"ZOMBIE, NEMESIS, SURVIVOR, SNIPER",
    
"HUMAN, NEMESIS, SURVIVOR, SNIPER",
    
"ZOMBIE, HUMAN, NEMESIS, SURVIVOR, SNIPER",
    
"ASSASSIN",
    
"ZOMBIE, ASSASSIN",
    
"HUMAN, ASSASSIN",
    
"ZOMBIE, HUMAN, ASSASSIN",
    
"NEMESIS, ASSASSIN",
    
"ZOMBIE, NEMESIS, ASSASSIN",
    
"HUMAN, NEMESIS, ASSASSIN",
    
"ZOMBIE, HUMAN, NEMESIS, ASSASSIN",
    
"SURVIVOR, ASSASSIN",
    
"ZOMBIE, SURVIVOR, ASSASSIN",
    
"HUMAN, SURVIVOR, ASSASSIN",
    
"ZOMBIE, HUMAN, SURVIVOR, ASSASSIN",
    
"NEMESIS, SURVIVOR, ASSASSIN",
    
"ZOMBIE, NEMESIS, SURVIVOR, ASSASSIN",
    
"HUMAN, NEMESIS, SURVIVOR, ASSASSIN",
    
"ZOMBIE, HUMAN, NEMESIS, SURVIVOR, ASSASSIN",
    
"SNIPER, ASSASSIN",
    
"ZOMBIE, SNIPER, ASSASSIN",
    
"HUMAN, SNIPER, ASSASSIN",
    
"ZOMBIE, HUMAN, SNIPER, ASSASSIN",
    
"NEMESIS, SNIPER, ASSASSIN",
    
"ZOMBIE, NEMESIS, SNIPER, ASSASSIN",
    
"HUMAN, NEMESIS, SNIPER, ASSASSIN",
    
"ZOMBIE, HUMAN, NEMESIS, SNIPER, ASSASSIN",
    
"SURVIVOR, SNIPER, ASSASSIN",
    
"ZOMBIE, SURVIVOR, SNIPER, ASSASSIN",
    
"HUMAN, SURVIVOR, SNIPER, ASSASSIN",
    
"ZOMBIE, HUMAN, SURVIVOR, SNIPER, ASSASSIN",
    
"NEMESIS, SURVIVOR, SNIPER, ASSASSIN",
    
"ZOMBIE, NEMESIS, SURVIVOR, SNIPER, ASSASSIN",
    
"HUMAN, NEMESIS, SURVIVOR, SNIPER, ASSASSIN",
    
"ZOMBIE, HUMAN, NEMESIS, SURVIVOR, SNIPER, ASSASSIN"

When I try to reduce the above code by deleting the extra team names, reducing it to this:

PHP Code:
new const ZP_TEAM_NAMES[][] = { "ZOMBIE""HUMAN""NEMESIS""SURVIVOR""SNIPER""ASSASSIN"
I get the following 3 errors:

// C:\mods\cstrike\addons\amxmodx\scripting\zomb ie_plague_advance_v1-6-1.sma(9076) : error 032: array index out of bounds (variable "ZP_TEAM_NAMES")
// C:\mods\cstrike\addons\amxmodx\scripting\zomb ie_plague_advance_v1-6-1.sma(907 : error 032: array index out of bounds (variable "ZP_TEAM_NAMES")
// C:\mods\cstrike\addons\amxmodx\scripting\zomb ie_plague_advance_v1-6-1.sma(9080) : error 032: array index out of bounds (variable "ZP_TEAM_NAMES")



Line 9076:
PHP Code:
else if (equal(keyZP_TEAM_NAMES[ZP_TEAM_SURVIVOR])) 
Line 9078:
PHP Code:
else if (equal(keyZP_TEAM_NAMES[ZP_TEAM_SNIPER])) 
Line 9080:
PHP Code:
else if (equal(keyZP_TEAM_NAMES[ZP_TEAM_ASSASSIN])) 
This is the whole code where the 3 error-causing lines are contained:

PHP Code:
// Trim spaces
                    
trim(key)
                    
trim(value)
                    
                    if (
equal(keyZP_TEAM_NAMES[ZP_TEAM_ZOMBIE]))
                        
teams |= ZP_TEAM_ZOMBIE
                    
else if (equal(keyZP_TEAM_NAMES[ZP_TEAM_HUMAN]))
                        
teams |= ZP_TEAM_HUMAN
                    
else if (equal(keyZP_TEAM_NAMES[ZP_TEAM_NEMESIS]))
                        
teams |= ZP_TEAM_NEMESIS
                    
else if (equal(keyZP_TEAM_NAMES[ZP_TEAM_SURVIVOR]))
                        
teams |= ZP_TEAM_SURVIVOR
                    
else if (equal(keyZP_TEAM_NAMES[ZP_TEAM_SNIPER]))
                        
teams |= ZP_TEAM_SNIPER
                    
else if (equal(keyZP_TEAM_NAMES[ZP_TEAM_ASSASSIN]))
                        
teams |= ZP_TEAM_ASSASSIN
                

So, I don’t know how to fix these 3 errors. Can someone help me?

When I try to add a new game mode, let’s say a boss that has ghost abilities, I don’t know where exactly to type the word “GHOST” nor I know how many times I need to type the word “GHOST”, regardless if the boss is a zombie (terrorist/T) or a human (counter-terrorist/CT). So, I simply prefer the code to be made in a way to not require the same team name to be typed many times, but only one time, like it is in Zombie Plague Shade.

This is the thread of Zombie Plague Shade, if you need it: https://forums.alliedmods.net/showthread.php?t=243147
Here you can see the ZPS's default code, without having to download anything: https://pastebin.com/kxx6v8Wm
Here you can see the ZPA's default code, without having to download anything: https://pastebin.com/j6efx4z8

So, ZPS is based on ZPA 1.6.1. Can someone compare the codes responsible for ZP TEAMS, and tell me how to reduce and simplify the ZPA’s “// ZP TEAMS” code and to make it like the same as the code in ZP Shade?

Thanks.

NOTE: I uploaded the big codes on another host, because AlliedModders shows server errors when I try to upload too large codes.

Last edited by GlobalPlague; 11-30-2021 at 03:19. Reason: mistake
GlobalPlague is offline
 



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 08:14.


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