find_vanilla_alternative
Check if your custom DayZ Enforce Script implementation has an existing vanilla function alternative to simplify your code.
Instructions
Check if custom code has vanilla DayZ function alternative
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| customCode | Yes | Your custom implementation |
Implementation Reference
- src/server/DayZMCP.ts:44-46 (schema)Zod schema for the find_vanilla_alternative tool input (requires 'customCode' string).
const FindVanillaAlternativeSchema = z.object({ customCode: z.string().describe('Custom code that might have vanilla alternative') }); - src/server/DayZMCP.ts:175-187 (registration)Registration of the 'find_vanilla_alternative' tool in the tools list (server capability).
name: 'find_vanilla_alternative', description: 'Check if custom code has vanilla DayZ function alternative', inputSchema: { type: 'object', properties: { customCode: { type: 'string', description: 'Your custom implementation' } }, required: ['customCode'] } }, - src/server/DayZMCP.ts:391-410 (handler)Handler for the 'find_vanilla_alternative' tool call. Parses arguments, delegates to CodeValidator.validate(), and returns vanilla alternatives.
case 'find_vanilla_alternative': { const args = FindVanillaAlternativeSchema.parse(request.params.arguments); const result = this.validator.validate(args.customCode); return { content: [ { type: 'text', text: JSON.stringify({ customCode: args.customCode, alternatives: result.vanillaAlternatives, suggestion: result.vanillaAlternatives.length > 0 ? 'Consider using vanilla functions instead of custom implementation' : 'No vanilla alternatives found - custom implementation may be necessary' }, null, 2) } ] }; } - Main validate() method in CodeValidator. Called by the handler, runs Iron Rules checks and calls checkVanillaPatterns() to populate vanillaAlternatives.
validate(code: string): ValidationResult { const errors: ValidationError[] = []; const suggestions: string[] = []; const vanillaAlternatives: { customCode: string; vanillaFunction: string; }[] = []; // Tokenize for context const tokens = lex(code); // Check Iron Rules for (const rule of CodeValidator.ironRules) { const error = rule.check(code, tokens); if (error) { errors.push(error); } } // Check for common patterns that could use vanilla functions const patterns = this.checkVanillaPatterns(code); vanillaAlternatives.push(...patterns); // Additional suggestions based on code analysis if (/for\s*\(\s*int\s+i\s*=\s*0/.test(code) && /GetInventory\(\)/.test(code)) { suggestions.push('Consider using GetInventory().EnumerateInventory() instead of manual iteration'); } if (/vector\.Distance/.test(code)) { suggestions.push('vector.Distance() is available for distance calculations'); } if (/GetGame\(\)\.CreateObject/.test(code) && /GetType\(\)/.test(code)) { suggestions.push('Consider using EntityAI.CastTo() for safe casting after spawning'); } return { valid: errors.length === 0, errors, suggestions, vanillaAlternatives }; } - Helper method checkVanillaPatterns() that uses regex heuristics to detect custom code patterns that could be replaced by vanilla DayZ functions.
private checkVanillaPatterns(code: string): Array<{ customCode: string; vanillaFunction: string; }> { const patterns: Array<{ customCode: string; vanillaFunction: string; }> = []; // Check for manual attachment copying if (/for.*Attachments|attachment.*Insert|GetAttachmentFromIndex/.test(code)) { patterns.push({ customCode: 'Manual attachment iteration and copying', vanillaFunction: 'EntityAI.CopyOldPropertiesToNew(EntityAI old_item)' }); } // Check for manual player list building if (/array<Man>.*players.*GetWorld\(\).*GetPlayerList/.test(code)) { patterns.push({ customCode: 'Manual player list building', vanillaFunction: 'GetGame().GetPlayers(array<Man> players)' }); } // Check for manual string manipulation if (/\.Split\(|\.IndexOf\(|\.Substring\(/.test(code)) { patterns.push({ customCode: 'String parsing/splitting', vanillaFunction: 'string.Split(), string.IndexOf(), string.Substring() are built-in' }); } // Check for manual inventory slot iteration if (/for.*GetInventory\(\).*GetCargo/.test(code)) { patterns.push({ customCode: 'Manual inventory slot iteration', vanillaFunction: 'GetInventory().EnumerateInventory() or GetInventory().GetCargo()' }); } // Check for manual health/blood operations if (/GetHealth\(""|SetHealth\(""|AddHealth/.test(code)) { patterns.push({ customCode: 'Health manipulation', vanillaFunction: 'GetHealth(), SetHealth(), AddHealth(), GetStatBlood()' }); } return patterns; }