AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can you help me to reduce this code? (https://forums.alliedmods.net/showthread.php?t=335377)

GlobalPlague 11-30-2021 03:17

Can you help me to reduce this code?
 
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(9078) : 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.

Natsheh 11-30-2021 03:50

Re: Can you help me to reduce this code?
 
Alright since you're setting team you don't need the teams values to be used as a bitsums values you rather need to have them as regular count numbers.

GlobalPlague 11-30-2021 04:13

Re: Can you help me to reduce this code?
 
Quote:

Originally Posted by Natsheh (Post 2764681)
Alright since you're setting team you don't need the teams values to be used as a bitsums values you rather need to have them as regular count numbers.

What does that mean? Does that mean what I want is impossible? If yes, then how is it done in ZP Shade?

If it can't be done, then would someone at least explain to me where exactly to add the new name of the boss and how many times I need to type the name?

Someone already explained it to me here: https://forums.alliedmods.net/showthread.php?t=335085

But I still don't understand it.

I can simply copy and paste the code the person provided me with, but if I want to add even more new game modes, I won't know where to add the new names of the teams. Would someone explain to me in detail how to deal with this code and why can't the name of a team be typed only once, but it must be typed multiple times on multiple lines? The fact the name must be typed multiple times on multiple lines is what makes me confused and unable to know where exactly to type the name and how many times to type the name.

Help me, please. :(

Thanks.

iceeedr 11-30-2021 13:06

Re: Can you help me to reduce this code?
 
Simple, use the API, I very much doubt that anyone will edit all this code just because you prefer to use everything in a main plugin and not use the API.

https://forums.alliedmods.net/showth...31119?t=131119

GlobalPlague 11-30-2021 20:19

Re: Can you help me to reduce this code?
 
Quote:

Originally Posted by iceeedr (Post 2764723)
Simple, use the API, I very much doubt that anyone will edit all this code just because you prefer to use everything in a main plugin and not use the API.

https://forums.alliedmods.net/showth...31119?t=131119

Alright. Thanks. It seems using API is easier than adding new game modes in the main source code.


All times are GMT -4. The time now is 23:16.

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