combining cvar strings
Moderator: Moderators
combining cvar strings
i was wondering if it's possible to combine 2 vars(both strings) to one var/string.
What i want:
as example "
local.newstring = local.str[1] + local.str[3]
or
local.newstring = local.str1 + local.str[3]
i always comes up with the error :
Script Error: binary '+' applied to incompatible types 'char' and 'char'
is there a command to make it a character? like int for integer ?
or maybe another good way to do it?
thanks in advance
What i want:
as example "
local.newstring = local.str[1] + local.str[3]
or
local.newstring = local.str1 + local.str[3]
i always comes up with the error :
Script Error: binary '+' applied to incompatible types 'char' and 'char'
is there a command to make it a character? like int for integer ?
or maybe another good way to do it?
thanks in advance
[VS-UK]Maj.OddBall[BnHQ]
I think strings are arrays of length 1 or something like that so maybe try
for(local.i = 1;local.i <= local.string1.size;local.i++)
{
local.newstring[local.i] = local.string1[local.i]
}
local.b = local.newstring.size+1
for(local.i = 1;local.i <= local.sting2.size;local.i++)
{
local.newstring[local.b] = local.string2[local.i]
local.b ++
}
for(local.i = 1;local.i <= local.string1.size;local.i++)
{
local.newstring[local.i] = local.string1[local.i]
}
local.b = local.newstring.size+1
for(local.i = 1;local.i <= local.sting2.size;local.i++)
{
local.newstring[local.b] = local.string2[local.i]
local.b ++
}
predefinded
To combine strings it would look like this, I think.
local.str1 = "Eat"
local.str2 = "at"
local.str3 = "Joe's"
local.newstring = ((local.str1) + " " + (local.str2) + " " + (local.str3) + "!")
iprintln (local.newstring) // Eat at Joe's!
There is probably a command for adding a space, but I only know the one for new line "\n"--must be in quotes. So, I added the spaces with " ".
local.str1 = "Eat"
local.str2 = "at"
local.str3 = "Joe's"
local.newstring = ((local.str1) + " " + (local.str2) + " " + (local.str3) + "!")
iprintln (local.newstring) // Eat at Joe's!
There is probably a command for adding a space, but I only know the one for new line "\n"--must be in quotes. So, I added the spaces with " ".
That's right Tom that should work perfectly, you can even do it without all the parens (makes it more readable):
local.newstring = local.str1 + " " + local.str2 + " " + local.str3
iprintln local.newstring
The thing what you tried Oddball doesn't work because you're only accessing one character of the string, so your adding two chars (which should still result in 1 char) instead of two strings...
local.newstring = local.str1 + " " + local.str2 + " " + local.str3
iprintln local.newstring
The thing what you tried Oddball doesn't work because you're only accessing one character of the string, so your adding two chars (which should still result in 1 char) instead of two strings...
I know howto combine the normal strings/cvars.
The proble in this case is, i want to split up the maplist in an array.
i want to split it up on every space so i was thinking to read every character in the maplist and put it in the new cvar array until a space is detected.
so obj/obj_team1 obj/obj_team2 obj/obj_team3 obj/obj_team4
would be:
local.maparray[0] >>> obj/obj_team1
local.maparray[1] >>> obj/obj_team2
local.maparray[2] >>> obj/obj_team3
local.maparray[3] >>> obj/obj_team4
maybe you have a more simple idea?
The proble in this case is, i want to split up the maplist in an array.
i want to split it up on every space so i was thinking to read every character in the maplist and put it in the new cvar array until a space is detected.
so obj/obj_team1 obj/obj_team2 obj/obj_team3 obj/obj_team4
would be:
local.maparray[0] >>> obj/obj_team1
local.maparray[1] >>> obj/obj_team2
local.maparray[2] >>> obj/obj_team3
local.maparray[3] >>> obj/obj_team4
maybe you have a more simple idea?
[VS-UK]Maj.OddBall[BnHQ]
Oooh you should have asked that instead 
Anyway try this:
Anyway try this:
Code: Select all
local.maplist = getcvar sv_maplist
local.j = 1
local.mapname[1] = ""
for(local.i = 0; local.i < local.maplist.size; local.i++)
{
local.char = local.maplist[local.i]
if(local.char == " ")
{
local.j++
local.mapname[local.j] = "" // create a string
}
else
local.mapname[local.j] += local.char
}
Script Files.txt
I found this in docs/Script Files.txt at the bottom of the page.
----------------------------------------------------------------
Accessing characters of a string
================================
Characters of a string are accessed by the [] array operator. Indexing starts at 0. For example, "abc"[2] evaluates to the string "c". There is no character type, so characters are just strings of length 1.
----------------------------------------------------------------
Also, thanks for the string printing commands, blue60007! Oddball - remember, they must be in quotes to use them.
----------------------------------------------------------------
Accessing characters of a string
================================
Characters of a string are accessed by the [] array operator. Indexing starts at 0. For example, "abc"[2] evaluates to the string "c". There is no character type, so characters are just strings of length 1.
----------------------------------------------------------------
Also, thanks for the string printing commands, blue60007! Oddball - remember, they must be in quotes to use them.
Last edited by tltrude on Fri Jun 04, 2004 9:01 pm, edited 1 time in total.
ok, here's the result for the code.
I made a script that warns you for custom maps.
feel free to use it on your servers when needed.
I made a script that warns you for custom maps.
feel free to use it on your servers when needed.
Code: Select all
// Custom map warning version 1.00
// This mod is created by [VS-UK]Lt.OddBall[BnHQ]
// The mod tells players what map comes next and warns them there's a custom map comming up.
// it also warns that if they don't have it, the server will kick them/
// the bot gives info where to get the maps
Start:
thread SendWarning
end
SendWarning:
wait 5
local.maplist = getcvar sv_maplist
local.j = 1
local.mapname[1] = ""
for(local.i = 0; local.i < local.maplist.size; local.i++)
{
local.char = local.maplist[local.i]
if(local.char == " ")
{
local.j++
local.mapname[local.j] = "" // create a string
}
else
local.mapname[local.j] += local.char
}
while(1)
{
level.currentmap = getcvar mapname
for(local.h = 1; local.h < local.j ; local.h++)
{
//println "mapname = " local.mapname[local.h]
if (level.currentmap == local.mapname[local.h])
{
level.CurrMapNumber = int(local.h)
//println "FOUND!!!!!"
//println "mapnumber + 1= " (level.CurrMapNumber + 1)
//println "nextmapname is " local.mapname[level.CurrMapNumber + 1]
if ((level.CurrMapNumber + 1) <= (local.j - 1))
{
if ((local.mapname[level.CurrMapNumber + 1] == "obj/obj_team1") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/obj_team2") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/obj_team3") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/obj_team4") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm1") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm2") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm3") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm4") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm5") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm6") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm7") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/MP_Druckkammern_TOW") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/MP_Flughafen_TOW") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/MP_Ardennes_TOW") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/MP_Berlin_TOW") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Bahnhof_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Bazaar_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Brest_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Holland_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Stadt_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Gewitter_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Unterseite_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Verschneit_DM"))
{
iprintln "The current map is " level.currentmap
iprintln "The next map is " local.mapname[level.CurrMapNumber + 1]
}
else
{
iprintln "Next map is " local.mapname[level.CurrMapNumber + 1]
iprintln "this is a custom map, if you don't have it, the server will kick you"
iprintln "you can download the map at http://www.vs-uk.net"
}
}
else
{
if ((local.mapname[1] == "obj/obj_team1") ||
(local.mapname[1] == "obj/obj_team2") ||
(local.mapname[1] == "obj/obj_team3") ||
(local.mapname[1] == "obj/obj_team4") ||
(local.mapname[1] == "dm/mohdm1") ||
(local.mapname[1] == "dm/mohdm2") ||
(local.mapname[1] == "dm/mohdm3") ||
(local.mapname[1] == "dm/mohdm4") ||
(local.mapname[1] == "dm/mohdm5") ||
(local.mapname[1] == "dm/mohdm6") ||
(local.mapname[1] == "dm/mohdm7") ||
(local.mapname[1] == "obj/MP_Druckkammern_TOW") ||
(local.mapname[1] == "obj/MP_Flughafen_TOW") ||
(local.mapname[1] == "obj/MP_Ardennes_TOW") ||
(local.mapname[1] == "obj/MP_Berlin_TOW") ||
(local.mapname[1] == "dm/MP_Bahnhof_DM") ||
(local.mapname[1] == "dm/MP_Bazaar_DM") ||
(local.mapname[1] == "dm/MP_Brest_DM") ||
(local.mapname[1] == "dm/MP_Holland_DM") ||
(local.mapname[1] == "dm/MP_Stadt_DM") ||
(local.mapname[1] == "dm/MP_Gewitter_DM") ||
(local.mapname[1] == "dm/MP_Unterseite_DM") ||
(local.mapname[1] == "dm/MP_Verschneit_DM"))
{
iprintln "The current map is " level.currentmap
iprintln "The next map is " local.mapname[1]
}
else
{
iprintln "Next map is " local.mapname[1]
iprintln "this is a custom map, if you don't have it, the server will kick you"
iprintln "you can download the map at http://www.vs-uk.net"
}
}
}
}
wait 60
}
end
[VS-UK]Maj.OddBall[BnHQ]



