Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 6 Guests
Online:

LATEST FORUM THREADS

»
warfare
CoD4 Map + Mod Releases
Voting menu on maps
CoD+UO General
Hauling 911
CoDBO3 General

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 4
Category: CoD4 Scripting
Scripting and coding with Call of Duty 4.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername, novemberdobby
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: convert int to string
uprize
General Member
Since: Jan 13, 2008
Posts: 24
Last: Oct 23, 2008
[view latest posts]
Level 1
Category: CoD4 Scripting
Posted: Tuesday, Sep. 30, 2008 01:05 pm
hi,

this is a stupid question but how do I convert a integer into a string?

This is my code so far

Code:

init()
{
	for (i = 0; i < getDvar("sv_maxclients"); i++)
	{
		setDvar("nameplayer[i]","");
	}
	wait 1;
	
}



It returns an error saying that it contains a mix of 'int' and 'string'.

I know its something simple but I havnt had much sleep so cant find the problem.

Cheers
Share |
novemberdobby
General Member
Since: Sep 17, 2006
Posts: 1965
Last: Oct 13, 2013
[view latest posts]
Level 8
Forum Moderator
Category: CoD4 Scripting
Posted: Tuesday, Sep. 30, 2008 04:23 pm
For getting a dvar that's a number, use getdvarint()/getdvarfloat() because getdvar() returns a string.

Code:

init()
{
	for (i = 0; i < getDvarint("sv_maxclients"); i++)
	{
		setDvar("nameplayer[i]","");
	}
	wait 1;
	
}


I'm not sure what you're trying to do here, is it giving all the players a blank name or something? The in nameplayer will be ignored because it's part of a string inside quotes.
Share |
uprize
General Member
Since: Jan 13, 2008
Posts: 24
Last: Oct 23, 2008
[view latest posts]
Level 1
Category: CoD4 Scripting
Posted: Tuesday, Sep. 30, 2008 11:12 pm
Hi Dobby

This is part of a gsc file which I want to set up blank Dvars at the start of each level. These Dvars will be later updated throughout the game using a loop, to update them to the current player names throughout the game.

I am using these Dvars to be displayed in the quickmenu commands. It all works from the menu side of things, as I can manually enter a value in the console to one of the Dvars and it will be displayed in the menus.

What I need to know for this to work, is a need the dvar to be a string which includes the loop number on the end.

example from init:
Dvar: nameplayer1 = ""
Dvar: nameplayer2 = ""
etc...

Then during game it will be updated to display the player names
Dvar: nameplayer1 = "Joe Bloggs"
Dvar: nameplayer2 = "NovemberDobby"
etc..

Basically all I need to know is how to get that loop index number into the dvar string, so it is saved as a string along with 'nameplayer'.
I know it is something so simple, I have tried getDvarInt and it didnt work...

If you can help me there will be lots of <3

cheers
Share |
novemberdobby
General Member
Since: Sep 17, 2006
Posts: 1965
Last: Oct 13, 2013
[view latest posts]
Level 8
Forum Moderator
Category: CoD4 Scripting
Posted: Wednesday, Oct. 1, 2008 12:24 pm
Ok. You'd do something like:

Code:

init()
{
	while(1)
	{
		players = getentarray("player", "classname");

		for (i = 0; i < getDvarint("sv_maxclients"); i++)
			if(isdefined(players[i]))
				setdvar("nameplayer" + i, players[i].name);
			else
				setdvar("nameplayer" + i, "");

		wait 1;
	}
}


That might work.
Share |
TFlames
General Member
Since: Feb 25, 2007
Posts: 3
Last: Oct 5, 2008
[view latest posts]
Level 0
Category: CoD4 Scripting
Posted: Sunday, Oct. 5, 2008 11:54 pm
NovemberDobby writes...
Quote:
Ok. You'd do something like:

Code:

init()
{
	while(1)
	{
		players = getentarray("player", "classname");

		for (i = 0; i < getDvarint("sv_maxclients"); i++)
			if(isdefined(players[i]))
				setdvar("nameplayer" + i, players[i].name);
			else
				setdvar("nameplayer" + i, "");

		wait 1;
	}
}


That might work.


Yeah that should work, unless nameplayer is an array and you're passing through one of it's entries that is a string, in which case you just take out the quotes

setdvar(nameplayer, "");



Share |
uprize
General Member
Since: Jan 13, 2008
Posts: 24
Last: Oct 23, 2008
[view latest posts]
Level 1
Category: CoD4 Scripting
Posted: Monday, Oct. 6, 2008 08:37 am
yeh thanks, novembers example worked like a charm. Just tweaked it a little bit to fit into what I wanna do.
I always seem to make everything more complicated than it needs to be

thnx for the replies
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty 4 : CoD4 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»