Well, we are trying to get the mod working without anything else needed (regardless if that is a smart thing or not), we can upgrade or modify things later.
After some thinking and testing I came up with this code.
There might be room for improvement, feel free to comment.
So far I am pleased with the result, this will make many problems go away.
PHP Code:
//return type of variable
//performs a series of checks to determine the variable type ?
//type: 0-NIL, 1-string,2-entity,3-vector,4-int/float
//-1 could not detect type
//=========================================================================
returnVarType local.var:{
//=========================================================================
if(local.var == NIL){ end 0 }
local.stringified = string(local.var)
local.stringifiedSize = local.stringified.size
//var is of type entity or string
if(local.var.size == 0){
//it can be either a empty string or a entity
if(local.stringifiedSize == 0 ){ end 1 }
else{ end 2 }
}
//var is type of integer, entity or vector or singleletter string
else if(local.var.size == 1){
local.firstChar = string(local.stringified[0])
//assume it is a vector if it is in brackets
if( local.stringified[0] == "(" && local.stringified[local.stringifiedSize-1] == ")" ){
end 3
}
//note: cant detect entities with a targetname < 2 chars
if(local.stringifiedSize > 1){
//entity targetnames never start with a number or a colon not a number will be 0 when converted
if( int(local.firstChar) == 0 && int(local.stringified) == 0 && local.stringified != "0.000" && local.stringified[0] != "."){
end 2
}
if( waitthread isFloat == 1 || int(local.stringified) != 0){
end 4
}
}else{
if(int(local.stringified) != 0 || local.stringified == "0" || local.stringified != "0.000"){
end 4
}
}
//fallback to string
end 1
}
//must be a string
else{
end 1
}
}end -1
//check if it is a float, game makes sure float always has 3 digits after the dot
//=========================================================================
isFloat local.var:{
//=========================================================================
local.stringified = string(local.var)
if( local.stringified == "0.000" ){ end 1 }
if( float(local.stringified) == 0 ){ end 0 }
local.dotAt = -1
local.afterDot = 0
for(local.i=0;local.i<local.stringified.size;local.i++){
if(local.afterDot != -1){
local.afterDot++
}
if(local.stringified[local.i] == "."){
local.dotAt = local.i
local.afterDot = 0
}
}
if(local.afterDot == 3){ end 1 }
}end 0